This short primer on the Virology Blog, hosted by Columbia's Prof. Vincent Racaniello, provides an excellent introduction to the way vaccines actually work. Here is the gist:
Immune memory is maintained by dedicated T and B lymphocytes that remain after an infection has been resolved, and most activated immune cells have died. These memory cells can respond rapidly to a subsequent infection (Figure). Ideally, an effective and durable vaccine is one that induces and maintains significant numbers of memory cells. If the host is infected again with this same pathogen, the memory B and T cells initiate a response that rapidly controls the pathogen before disease develops. This paradigm is true for most human viruses for which vaccines exist, including measles, mumps, and varicella-zoster viruses and poliovirus. In some cases, antigenic variation, such as occurs with influenza virus, precludes complete protection by a memory immune response, necessitating re-vaccination.
Protection from Infection or Protection from Disease?
The memory response elicited by most human viral vaccines does not protect against reinfection, but rather against the development of disease. An individual may be exposed repeatedly to viruses and never be aware of it, because the memory response eliminates the virus before signs and symptoms develop. After vaccination with inactivated poliovirus vaccine, virus replication may take place in the intestine, but effectively blocks the development of poliomyelitis. On the other hand, the human papillomavirus vaccine is over 90% effective at blocking infection. Consequently the HPV vaccine induces sterilizing immunity.
Whether or not COVID-19 vaccines will block infection is unknown because it has not been adequately measured.
You can read the entire post here.