San Francisco is the most extreme case, but you can see the same phenomenon in New York City, LA, Minneapolis,... and even tiny Ithaca, NY.
The children of Chinese billionaires, attending Cornell University, will sometimes simply buy single-family houses for use while attending college. All the "development restrictions" in the world won't stop them. The obscenely rich students can afford to simply buy out the "single-family" districts if they want to, and so they have been moving in on them.
Somewhat less rich people who want to retire here buy up "homes for people of modest means" and build their dream mansions. If it's a historic district, where they can't demolish the building (which it frequently is), they just build their expensive-rich-person house inside the existing house.
Meanwhile, other not-super-rich-but-still-rich students "slum it" in shoddy, decrepit apartments close to campus for which they pay higher rents than the Cornell staff can afford. It's been driving the lower-paid Cornell staff to live 30 or 60 minutes away in neighboring cities.
The only way to blunt the effects of this and make it possible for the staff to live in Ithaca, which they mostly want to do, is to build more apartment buildings. (Of course, that will empty out the housing demand in the neighboring cities; there's always an effect. I've suggested connecting the neighboring cities by passenger rail to make them more desirable relative to Ithaca, but it's so outside the thinking of current politicians it's got no traction so far.)
The underlying cause is a 1950s era zoning code which came very close to prohibiting new housing construction. As a result, there was basically nothing built in the City of Ithaca for 50 years. For part of that time, the Town of Ithaca sprawled ranch houses onto greenfields, but then they stopped too. During the entire period, the number of jobs and students has grown, and the housing simply hasn't kept up, because it was illegal for it to keep up.