So what should you do if you find yourself in one of these situations and get let go? It gets really irritating having to explain what happened at the previous job in every interview.
That's part of the problem - and it's one of perception, not reality.
People are good in the right environment and with the right team. If the fit is bad, it could be a lose-lose.
I've seen great people (I personally knew) do worse in a subsequent job, and vice-versa - people who were subpar in a previous job do great at a new gig.
Atleast AFAIK in Bayarea, nobody cares as long as you have the skills. I have had the pleasure of working with some amazing engineers & team players who were let go in earlier jobs.
As an indie developer doing one sort of 'dream job' (distributing exceptional software for free and moving towards open source, supported entirely by voluntary small contributions like some DSP Bernie) it's pretty easy for me to see the catch.
You can do anything you want IF you 'have the skills' and are 'amazing'. If you're not sufficiently amazing, then you're fooling yourself and might as well suicide (that's the feeling) because you're doomed anyhow. There is no one specific level of 'the skills' or 'amazing', it's a sort of sliding scale in which you can begin to lose simply because everyone around you took a level in 'amazing'. And everyone around you is incredibly driven and desperate…
You can call this motivational and not be so far wrong, but there's a really dark side when society is set up to have harsh punishments for losing. Ain't no welfare T-Bone steaks for homeless people pooping in the streets of San Francisco. I can't help but feel that in the Bay Area, there's no clear floor you can drop to. You can be amazing… or you can be NOT amazing, and there might be a level of 'untouchable caste' to the NOT amazing.
My own psychological method of fighting this (in my field there's definitely an element of 'abandon the losers before they saddle you with being associated with their fail') is to be defiant, claiming that I'm very poor but on an upward trajectory because I've seen the light of Open Source etc, that I am audaciously redefining what it means to be a dev/creator, and might decide to be always poor as dirt just to be defiant about it. It does keep me from suicide: finally committing to that POV made a noticeable difference. I think this attitude is echoed among other open-sourcers.