Layoff can happen to anyone, but highly experienced developers and architects are less likely to have problem finding jobs, even if they are over 40 or 50. The industry is constantly in need of those people. This was the case even during past downturns.
If your job can be done by younger and cheaper labor, you will be replaced. Of course, there are plenty of examples of idiot leadership deciding to replace unreplaceables too.