If you want to be recession-proof, get a job at a non-software company (or in academia, state/city government, etc). In theory, "programmer" is the same job whether you work for a startup or the Minnesota Dept. of Transportation, but in practice they feel like completely different industries. In one, you can make fantastic money but the interviews are famously difficult, the culture can be borderline abusive, and lay…
These generalizations are untrue for a lot of companies, and for a lot of teams. Software companies, even FAANGs, can be very relaxed and comfortable places to work. It all really depends on the team -- and you can end up with an abusive boss in any industry.
Job security depends on the nature of the recession. In 2008 a lot of government employees in California (and probably other states) got furloughed without pay for a while because the state government basically ran out of money.
Also, the pay difference for software engineers at tech and non-tech companies is not small. It's at least 4X, often more. If you work at an established tech company for several years and you aren't totally irresponsible, you will be able to save enough money to live for a long time without an income -- even while paying a Silicon Valley mortgage.