Answer:
Quorum Sensing
This is how bacteria "communicate" with one another.
A tiny quorum molecule will be secreted by each individual bacteria in a set quantity. They can each determine how many other bacteria of the same sort are nearby based on the quantity of this chemical around them.
When the quorum molecule reaches a certain mass and a specific threshold, it triggers some type of shift in gene transcription that leads the bacteria to behave differently (they all do it because they are all exposed to a high enough concentration of the quorum molecule).