Bacteria Have Immune Systems, Too
Human immunity, specifically the adaptive immune response, is based on recognizing and remembering molecules which pose a threat. After fighting off the initial assault, the body "remembers" the pernicious molecule via the long-lived memory T- and B-cells. The next time your body is exposed to the molecule, an overwhelming army of immune cells are poised for attack. This immunological memory is the scientific basis for vaccination.
The human immune system is incredibly complicated, and it involves several organs (e.g., thymus, lymph nodes, spleen) as well as multiple cell types (e.g., T-cells, B-cells, macrophages, etc.). Bacteria aren't nearly as complex as humans, yet they too, have an adaptive immune system. How does it work?
Remarkably, the bacterial adaptive immune system, known as CRISPR (don't worry about what it stands for) is based on a similar principle: Recognizing and remembering foreign invaders. (See diagram.)
In the upper-left corner, the thing that looks like a lunar lander is a bacteriophage -- a virus which infects only bacteria. It injects its DNA into the bacterial cell. If everything goes well (for the virus), it will commandeer the bacteria's machinery. Instead of making bacterial DNA and proteins, the bacterium will start making viral DNA and proteins. After the virus has had its way with the bacterium, it causes the bacterium to explode, immediately killing it and ejecting thousands of new virus particles into the environment -- searching out their next victim.
Occasionally, things don't go well for the virus. (See diagram.) Sometimes, an immunological protein system called CAS recognizes the viral DNA as foreign. When it does, the bacterium will snip out a piece of the viral DNA and then incorporate it into its own genome! This DNA sequence then serves as something of a bar code, allowing the bacterium to "remember" this DNA as dangerous and to pass on this information to its offspring.
As shown in the diagram, the viral DNA bar code is referred to as a "spacer." The bacterium has a unique location (called a "locus") in its genome where it accumulates many different bar codes from the many different viruses it has encountered. The DNA is then transcribed to produce non-coding (which means it doesn't encode protein) RNA which contains the same bar code information as the DNA.
Then, other proteins in the CAS system pick up this RNA and use it to identify foreign, invading DNA. The next time a bacterium (or one of its offspring) encounters the exact same foreign DNA, it will match the RNA bar code, and the bacterium will know that this DNA is dangerous and must be destroyed immediately. The virus is toast before it even has a chance to inflict any damage on the bacterium!
The CRISPR system is a relatively new discovery in microbiology, but its potential applications are already known. Friendly bacteria are used in the food industry, and knowledge of bacterial immunity could allow the creation of bacteria which are resistant to viruses. Also, it is possible such knowledge could be useful for genetic engineering of higher organisms.
Source: Manuela Villion and Sylvain Moineau. "The double-edged sword of CRISPR-Cas systems." Cell Research advance online publication 4 September 2012; doi: 10.1038/cr.2012.124
(Diagram: James atmos/Wikimedia Commons)