In buildings. It's really not that hard: https://www.vox.com/a/new-economy-future/urban-sprawl-housin... or http://www.slate.com/blogs/moneybox/2013/05/03/silicon_valle... . It's just illegal, right now, to build the buildings that people want to occupy. Make it legal and lots more people will live in SF and environs.
But, as with any city - the income disparity and the cost of living is high - but all cities need affordable labor as well as economic opportunity.
What has led you to believe this is a difficult problem? The impediments to density in San Francisco are regulatory. At Brooklyn's density the city would have 1.6 million people. At Paris's density? 2.5 million.
I deliberately chose those places because they're not dominated by skyscrapers.
People talk about the "housing crisis" using the language of natural disasters. But this is just people deciding not to build more housing. No more or less.
Streets and parking are a huge waste of space, so higher concentration will be better livability (less noise, pedestrians can own the surface, and let's face it, streets full of cars are ugly)
The upside of this is decentralization, not more concentration.