How did Mark Zuckerberg decide to scale Facebook's database architecture?

Mark Zuckerberg says the key decision was to split the databases by school, because most activity happened within a user's own school network. That made the friend-connection computation manageable by shrinking the problem from the whole network to a much smaller local database. It also let Facebook grow without exponential hardware growth.

“So what we decided was that everyone on the site does most of their activity at the school that they're kind of based at. So if you're at Harvard, then most of the people who you're going to be seeing and transacting with on the site are going to be at Harvard. It's actually probably like 90% of the stuff that you do on the site. >> So we decided to split up the databases and create one instance of MySQL database for each school in the network. And in doing that, if you notice the paths that we compute are only within the school. So instead of say, like now we're at six million users, and instead of having to do n cubed over some portion of six million, it's just n cubed over 10,000, which is a much more manageable type of computation.”
— Mark Zuckerberg, Harvard CS50 lecture, 2005 · at 5:59
Mark Zuckerberg: Mark Zuckerberg on Scaling Social Networks: Harvard CS50 Lecture

Key takeaways

  • Partition data around natural user clusters
  • Reduce expensive computations by narrowing the scope
  • Scale linearly when possible, not exponentially

Context

In a Harvard CS50 lecture, Zuckerberg was explaining the early technical choices that let Facebook expand beyond Harvard. The quote above is taken word for word from the recording's transcript.

In the transcript

…six degrees out, or like seven degrees out. >> And that's something that when you're doing like n seventh, that just is really very hard and it took down their site for a while. So one of things that we kind of had in mind when we were figuring out how to do this was how do you distribute the database in such a way that this computation becomes manageable.

So what we decided was that everyone on the site does most of their activity at the school that they're kind of based at. So if you're at Harvard, then most of the people who you're going to be seeing and transacting with on the site are going to be at Harvard. It's actually probably like 90% of the stuff that you do on the site. >> So we decided to split up the databases and create one instance of MySQL database for each school in the network. And in doing that, if you notice the paths that we compute are only within the school. So instead of say, like now we're at six million users, and instead of having to do n cubed over some portion of six million, it's just n cubed over 10,000, which is a much more manageable type of computation.

>> So that was sort of the first big architectural decision that we had to make that contributed to us not dying a few months later. And it was probably a pretty important one. >> So when we first set up the site we had just one computer that we were running. It wasn't in our dorm room. We were renting it. I kind of learned my lesson for trying…

Read the full transcript of Harvard CS50 lecture, 2005

Topics

What others said about product development

More questions about Mark Zuckerberg

All Mark Zuckerberg answers · All Mark Zuckerberg recordings

How this answer was made: the quote is checked word for word against the transcript of the recording and confirmed as the speaker's own words; the summary above it was drafted with AI from that transcript and quality-checked. Methodology and corrections.

Search every transcript
Open the full search page →