Here is how it works for the MMR vaccine (measles, mumps, and rubella):
Children should get two doses of MMR vaccine, starting with the first dose at 12 to 15 months of age, and the second dose at 4 through 6 years of age.
Or here are the WHO recommendations for various vaccines (from the larger source here) for children. The times in the Booster Dose column span months or years. This doesn’t quite answer the question of how soon you need to be, but does provide an intuition for the orders of magnitude which are typically involved, at least for children. Though besides age, I suppose part of the epidemiological reasoning here must involve not just the reaction of the immune system, but also the prevalence of the disease.
Reasoning by analogy, via some googling:
Here is how it works for the MMR vaccine (measles, mumps, and rubella):
Or here are the WHO recommendations for various vaccines (from the larger source here) for children. The times in the Booster Dose column span months or years. This doesn’t quite answer the question of how soon you need to be, but does provide an intuition for the orders of magnitude which are typically involved, at least for children. Though besides age, I suppose part of the epidemiological reasoning here must involve not just the reaction of the immune system, but also the prevalence of the disease.