Modern microbiology relies on growing cells in homogeneous liquid cultures and agar plates. While these have taught us a tremendous amount about microbial life, in nature bacteria experience complex chemical and hydrodynamic landscapes that are not found in homogeneous laboratory conditions. This talk will present two projects that use microfluidic experiments and mathematical models that show how bacteria exploit heterogeneity in their natural environments. The first project investigates how hydrodynamics mediates bacterial competition in porous environments like soil. In porous environments bacterial biofilms face a fundamental challenge: dividing too rapidly can redirect flow, and the dissolved nutrients that it carries, to competing biofilms. We combine experiments, physical models, and game theory to show how this interaction favours genotypes with a specific “evolutionary stable” growth rate. Our results suggest that growing slower can actually give cells a competitive advantage in porous environments, which is where >97% of bacteria on Earth live. The second half of the talk will present how bacteria within biofilms use grappling hook like appendages called pili to navigate chemical gradients. Using massively parallel cell tracking, we resolve both the molecular and behavioural basis of pili-based chemotaxis. Our experiments show that cells can navigate chemical gradients with submicron precision, suggesting that they directly sense changes in concentration over the length of their bodies. Taken together, these two studies offer new insights into the microscale processes that shape the composition of bacterial communities and offer new tools to manipulate them to our advantage.