Continue where you left off ×
Instagram, the case study
Everything · Open board
The whole machine on one canvas. The Python program at the top is drawn once, because there was only ever one of it.
Before you start. You need to know that a website is a program running on rented computers, and that it keeps its information in a database, a filing cabinet a program writes to and searches. This is the story of a photo app that reached three billion users without ever rewriting the program at the top.
The idea in 30 seconds
Instagram never rewrote the Python program at the top. Every fix for fifteen years went in underneath it.
A shard is one of two thousand numbered pieces of the database, picked by the remainder when the user’s number is divided by two thousand, and a photo’s id contains the number of the shard it lives in.
Fanout is copying a new post’s id into every follower’s list, done by a background job, and skipped entirely for accounts with tens of millions of followers.
Denormalising is storing an answer you could have recalculated, which is why a like count is one number to read instead of millions of rows to count.
Copy-on-write lets dozens of worker processes share one copy of the program’s memory, until something writes to a page, and Python’s memory tidier was writing to every page it looked at.
A quorum waits for a majority of copies to confirm a write, which is cheap inside a region and ruinous across an ocean, so every record was given a home continent.
Read the story
Lesson 94 of 115 in System Design
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson October 2010: two founders, and 25,000 strangers on the first day 2011: one database ran out of room, so they cut it into shards Nobody waits for a million followers: fanout Three shapes of data, three places to keep them August 2016: Stories, and a hundred posts out of billions January 2017: workers copying memory nobody had written to November 2018: Europe is seventy milliseconds away Terms it explains: shard, fanout, denormalising, copy-on-write, quorum, 69.7 years, 8,192, 2.05 billion a second, 16.7 bytes an entry, 6x, 3x, 8.3x, 10%, 12% less CPU, 30% less memory, 27.9 ms, 55.7 ms, 14 to 70 times.
Review System Design
Mark as read Saved in this browser, and to your account when you sign in.