Development of microbial communities is a complex multiscale phenomenon with wide-ranging biomedical and ecological implications. How biological and physical processes determine emergent spatial structures in microbial communities remains poorly understood due to a lack of simultaneous measurements of gene expression and cellular behaviour in space and time. Here we combined live-cell microscopy with a robotic arm for spatiotemporal sampling, which enabled us to simultaneously acquire phenotypic imaging data and spatiotemporal transcriptomes during Bacillus subtilis swarm development. Quantitative characterization of the spatiotemporal gene expression patterns revealed correlations with cellular and collective properties, and phenotypic subpopulations. By integrating these data with spatiotemporal metabolome measurements, we discovered a spatiotemporal cross-feeding mechanism fuelling swarm development: during their migration, earlier generations deposit metabolites which are consumed by later generations that swarm across the same location. These results highlight the importance of spatiotemporal effects during the emergence of phenotypic subpopulations and their interactions in bacterial communities.