Here's a military analogy, the hunt for Osama bin Ladin. For years, we kind of knew his general vicinity, but couldn't identify precisely where. So, we had two options. Carpet-bomb the entire region and deal with all the collateral fall-out, or carefully gather intelligence, select and train an elite team of operatives and launch a precision strike that results in bin Ladin having a bullet go through his skull, but spares almost everyone else in the immediate area.
Carpet-bombing is essentially the inital immune response to a virus your body has never encountered before. This isn't a bad defense against bacteria, which behave more like a large, densely packed swarming army, but for smaller, more elusive targets like viruses, it isn't very effective and can cause severe damage to the body. Most of the symptoms and consequences of an infection aren't directly related to tissue injury caused by the infecting organism (some is, though), but by the out-of-control immune response trying to keep the virus or bacteria at bay. Only after the immune system has successfully selected for a population of T and B cells that can specifically identify and target that particular pathogen does the initial carpet-bombing become more focused and directed. It generally happens quicker in younger people because they have a larger population of stem cells to recruit.
Vaccines essentially recruit and train that elite strike force without going through the carpet bombing. But, even the best elite teams eventually start to age and lose their edge. Team anti-measles seems to be one of the strongest and most enduring, but others, like team anti-pertussis, anti-tetanus (which actually tragets a bacterial toxin, not the bacteria itself) and anti-mumps tend to suffer more attrition over time. Hence, the need for boosters with some diseases.
COVID and its vaccines are still too new to really know how long the immunity endures.