Bacteria have immune systems that they control by talking with each other. Their immune systems work differently than humans'. Bacteria take snippets of a virus's DNA and store the snippets to help them recognize and destroy the virus in the future.
The whole system is a huge balancing act. If the bacteria create too much immune activity, they can get a kind of autoimmune‑like disease that destroys them. If they don't create enough activity, that could let a virus wipe out a whole bacterial community.
Scientists now know that bacteria communicate with each other by releasing chemicals in a process called, "quorum sensing." That's how they figure out their population density--that is, how many cells are in their communities--which lets them gauge the right amount of immunity to create. If they figure out their community is a big one, they boost their immunity.
This happens because the advantages of stronger immunity outweigh the potential danger in a bigger community.
