Very few firms want to hire juniors, while nearly all firms desire senior-level talent. This manifests inflated job vacancies because so many firms have an evergreen job posting for "Senior Full Stack". Because talent is scarce these roles rarely get filled (hiring managers expect million-dollar candidates to accept $100-200k compensation). Also, because lots of software requires specific expertise, there are vacanci…
Worse, many firms are put off by juniors for entirely preventable reasons. In their minds, juniors are undesirable because the moment they are trained up, they tend to jump ship for senior positions elsewhere. Why train your competition, right? The reason they jump ship is because the firm refuses to re-evaluate them for what they are worth, and keeps them on work meant to free up the company's existing senior staff…
I really disagree. These junior engineers you're talking about are mostly in their early 20's (even if they're older and switching from a different career track, they're by definition new to the industry and still have a lot to learn). In my experience, they definitely do want to move around. And even if there is a great track for internal promotions and the compensation is going to be the same whether they stay or leave, it honestly is usually in their best interest to move around every couple of years anyway early in their career. They'll meet more new people to grow their professional network faster, work on new problems, see different ways of how teams operate and what works better/worse, and gain more experience faster.
I do think that for the very top performers, most companies should probably be much more aggressive than they are. If someone is really crushing it, like in say the top 1-5% of performers, be ridiculously proactive and promote them from junior engineer to Staff Engineer within 18 months or something. I've seen a couple of people over my career that actually were performing at that level, and no external company is going to give them that big of a boost, so it's a good chance to use your inside information to be more competitive. Otherwise, for the majority of folks that are learning/advancing at a more normal pace, I don't think there's really much a company can do to keep them longer. (Not that you shouldn't even try, it's still a continuum and if you do a really bad job at career growth internally you'll lose even more people faster. But you shouldn't expect to be able to keep most people beyond 2-3 years).