The best thing to do is to be prepare to switch your career at some point. The tech industry is notoriously ageist so don't expect to retire working in the same type of job you have now.
I am 51. I got my first job in BigTech at 46. When I got Amazoned in 2023, within the first two weeks I had three offers.
I was out looking again in 2024, I responded to a recruiter and had a job offer within two weeks.
I am still an IC and half my job as a staff consultant is pushing out code onto AWS, the other half is leading projects, supporting sales, talking to customers.
You are the exception not the rule. Go to any tech shop and you the will see that the majority are in their 20's and 30's and mid 40's. Sure there are a few that are older but they are the minority by far.
There's a survivor bias, you see the older techs that are employed and people think "oh, there's no problem." But people don't take into account all the other techs that could not continue their career because they could not get a job as they got older.
There's also a large number of folks moving to management as they age. Yes, the tech industry tends to skew young for engineering, but management doesn't. There's also a relatively decent chunk of people retiring in their early 50s (I plan to). There's also a decent number of them leaving to create their own companies, or to join friends at their early stage startups.
I don't think it makes sense to say they're the exception. I'm also mid-40s and have no issues finding employment. Most of my friends are mid 40s/50s and also have no issues. The vast majority of them have switched into management, though. Myself and the other older engineers I know are staff+, though, which helps a lot. I can't imagine being this age as a senior engineer trying to fight an army of equally qualified people in their 20s (who are also having issues finding employment right now).
The HN bubble is real. Most developers are boring old enterprise developers who toil away at writing LOB apps spending their entire career in corp dev if they don’t move onto management.
They live in second tier cities and retire at the same time everyone else retires.
If you are 40 years old and still competing with 20 something’s based on your ability to reverse a b tree on the whiteboard, you have made some poor life choices.
I was out looking again in 2024, I responded to a recruiter and had a job offer within two weeks.
I am still an IC and half my job as a staff consultant is pushing out code onto AWS, the other half is leading projects, supporting sales, talking to customers.