There are a lot of factors that determine the duration of efficacy of a vaccine. Broadly speaking, you can lump these effects into 1) decaying immune response and 2) mutating disease vectors.

For number 1), what you have to know is that the human immune system is a goofy non-linear Rube Goldberg machine. It's not something that an engineer would come up with. Some vaccines work by promoting an ongoing immune response to certain proteins. You can think of the antibodies as like "wanted" posters, and when a real virus with matching features is detected, it sets off your immune system. But if those proteins are passively introduced, they will decay in your bloodstream over time. Some proteins will hang around longer, others do not, perhaps because it just happens to be structurally similar to some protein that is metabolized by naturally present enzymes. There are also crazy feedback loops that can keep your immune system primed by synthesizing the antibodies from a sort of "memory". Look at the B-cells, they basically pick up any random proteins they think are junk, learn how to synthesize new proteins that stick to it, and then it wears all those proteins around like a hat. And when it's hat sticks to stuff, it tells some other cell to start making lots of party hats for all the other white blood cells to wear so they can sweep up the foreign substances. But these feedback loops are not always stable and can also fade with time. Some antibodies are more stable than others, and some just need a much lower blood concentration to be effective. It's really hard to predict, especially with new diseases.

The best vaccines work by having an actual live virus that lives and replicates inside your body, sometimes for decades. These are your "one-and-done" vaccines, and they're actually really hard to make! You basically have to engineer a virus that lives inside of you, forever, but doesn't hurt you. Instead, it just looks sufficiently similar to a different virus that could hurt you, and it keeps your immune system primed with antibodies to keep the virus in check if you are exposed to it.

Number 2) is the reason we have to get a new flu shot every year. The virus mutates very rapidly and different strains can mix-n-match easily. The Covid virus is already mutating into several variants of concern, and because people are not getting the vaccine which is effective for the strains that are out there now, this will likely become a reason why we have to get regular covid shots.

The upshot of all of this: we had an emergency and needed a vaccine fast. We've come up with two solutions so far: non-replicating adenovirus vaccines (such as AstraZenica, sputnik, etc), and the mRNA ones (Pfizer and Moderna). Both of these work by basically introducing a dead protein into your system, which teaches your immune system how to identify Covid and start attacking it before it can take hold and do damage. But as you can see, it's hard to say how long this can be effective before it needs to be renewed.

Anyone who doesn't like the idea of getting follow-up shots should get to work on making a one-and-done, live, replicating Adenovirus vaccine! But they had better hurry up because if situation 2) takes hold, you're going to need a new shot every year anyways.