There's a whole subset of folks looking at 'tech' as 'startup', and the goal of those companies is often to get acquired, so, the company won't necessarily be around in 8 years, let alone 20.
I've resigned myself to the notion that I'll never get a '20 year anniversary' at a company at this stage of my life. I don't mind, but it was one of those things when you're younger that does seem achievable. Most of the companies I've worked at in the past 25+ years aren't even in business any longer, except for 1, which was already 15+ years old when I started, and that was 15 years ago - had I stayed, that might have been the one chance to hit a '20 year' mark someplace (and I have one colleague who started with me and stayed there, so he might make it).
I won't either. But I was at one company about 13 years, another about 8, and just over 10 at my current one.
Based on their experiences I think the best advice is to stay current in your skills, find ways to apply those skills at work so you can get those lines on your resume, and choose to be a generalist rather than specializing. Don’t be loyal to your language or framework, demand for skills in software is more a function of whats fashionable than anything else. Look at where Perl is, many Perl coders were loyal to Perl instead of learning Python.
Most importantly, take a look at the ages of your coworkers. Is it really smart to be loyal to a company where there’s few people over 40 working your job? My Dad stayed at a company for 10 years and only got a raise once. Be smart, at some places you’re just a line item.