Vaccines work by mimicking an infection, prompting the immune system to generate memory B cells without causing the disease. This prepares the immune system to respond quickly and effectively if the actual pathogen is encountered in the future. Different types of vaccines, such as live-attenuated, inactivated, and mRNA vaccines, aim to stimulate the production of memory B cells.