Bacteria often live in a type of communities call biofilms, where they can cooperate and also compete with each other for resources. For example, cells at biofilm periphery protect interior cells from external attack, but also starve them through nutrient consumption. It remains unclear how these opposing interactions are resolved at the population level. To investigate this question, I developed a new microfluidic technique to culture Bacillus subtilis biofilms. Using this technique, I discovered that the conflict between protection and starvation is resolved through the emergence of long-range metabolic co-dependence between biofilm periphery and interior. As a result, biofilm growth halts periodically, increasing nutrient availability for the sheltered interior cells, benefiting the community in the event of chemical attack. I will further demonstrate a function for ion channels in this process. Specifically, ion channels conduct long-range electrical signals within biofilms through spatially propagating waves of potassium, which facilitates the coordination of metabolic states among cells. These findings indicate that bacterial communities can coordinate their dynamics to resolve competing demands in space and time, suggesting new strategies for biofilm control.