a Schematic illustration of the microfluidic device used to encapsulate engineered E. coli and pyranine into cell-sized compartments. Water-in-oil droplets were generated at a flow-focusing T-junction of a PDMS-based device. b Schematic illustration of a surfactant-stabilized water-in-oil droplet containing engineered E. coli. c Brightfield image of monodisperse water-in-oil droplets with a radius of 27 ± 5 μm (mean ± s.d., n = 53) containing engineered E. coli (OD600 = 20). Scale bar: 50 μm. d Overlay of confocal fluorescence and brightfield images of pyranine (c= 50 μM, λex = 488 nm) inside droplet-based compartments at pH 5.8 and pH 8.0. Scale bar: 50 μm. e Normalized fluorescence intensity ratio I488/I405 of E. coli and pyranine-containing droplets over time. The fluorescence intensity ratio (mean ± s.d., n = 11 droplets) of pyranine (and hence the pH) increases reversibly during periods of illumination with white light (30 W halogen bulb, highlighted in yellow). Note that the number of recorded frames was reduced because the illumination light had to be turned off each time an image was acquired, which will bias the proton pumping activity. Source data is available for Fig. 2e.