Well, vaccines are substances that stimulate the production of antibodies. They contain live and dead pathogens as well as antigens.
When pathogens invade our bodies, the immune system triggers a series of responses to fight against these pathogens and try to identify them. A vaccine prevents the invasion of these pathogens when it is injected into the body. As I said, vaccines have a small amount of the same pathogen which a person is being vaccinated from.
White blood cells in our body work to kill the pathogens. One type is called a phagocyte and another type is lymphocytes which produce antibodies that attack the pathogen. In this process, memory cells are produced. Their job is to remember the pathogen so that if your body was exposed to it then your immune system will know how to fight it off.
Wow that's so cool!
Most vaccines last a lifetime, but not all. For example, the vaccine for Rubella lasts for 15-20 years and the vaccine for Pneumococcal lasts 4-5 years.