As someone who has hired many engineers and PMs, and runs a hiring budget today, there are some reasons to feel at least fairly secure if you're an engineer at a growing company:
- Building a high-quality product is a longterm investment and most technology companies know that. As a result, in my experience companies who expect growth would always prefer to keep engineers and PMs as investments.
- Companies generally find it hard to hire Engineers and PMs that meet their standards, especially in competitive markets like the SFBA, NYC, Boulder/Denver, Seattle, Austin etc. (You can argue whether that's caused by overly stringent hiring standards - that's a much more complex question). As a result, companies are somewhat more likely to "hoard" engineers if they expect that they'll need them to grow.
- Because engineers in these markets are expensive, it makes economic sense to spend to improve their productivity. If I have 100 engineers on my team and I can make them all just 1% more productive by hiring an additional engineer who focuses solely on internal tools or open source libraries that improve developer QoL, that's arguably money well spent.
- Many products at scale are more complex than one might expect from the outside, which demands a lot of ongoing product/engineering effort to maintain. If you're working on something that has a credible path to revenue or clearly makes/saves money now, your job is probably fairly safe.
This all assumes that 1) the company wants to keep you, and 2) the company is growing, even modestly. Once the financials go downhill companies will cut directly to the bone in order to survive, and at that point nobody in any industry is safe.
(edited for formatting, thanks @mkl)