How three engineers became three data centers
2012: keep it boring, keep it stateless
Fourteen million people, three engineers, one Amazon region. The stack is plain on purpose: Django on stateless web servers behind load balancers, PostgreSQL for the data, Redis and Memcached in front of it, a task queue for work that can wait, and photos on S3 behind a CDN. When traffic grows, they add web servers. Nothing on those servers needs to be moved.
The database is the first thing that cannot just be copied
Web servers you can clone. Rows you cannot. So they split users and their media across thousands of logical shards, each one a PostgreSQL schema, mapped onto a dozen physical servers. A logical shard can move to a new server later without rewriting its data. And every ID is minted on its own shard, with the time, the shard number and a counter packed into 64 bits, so no central ID service can become the bottleneck.
Do the expensive part later
Posting a photo stores the file, writes one row, and answers. Putting that photo into every follower's feed is queued, and about 200 workers do it in the background. Reading a feed is then cheap: the list is already built.
2013 to 2015: one data center becomes a single point of failure
Instagram moves from AWS into Facebook's data centers, then spreads across three. Because the web and async tiers hold no state, each data center gets its own. PostgreSQL keeps a primary per shard and read replicas in every region, so reads stay local and writes travel. Cassandra holds data that must exist everywhere. Caches stay local, and invalidations ride the database's replication stream so each region clears its own. Facebook later shuts down a whole data center at peak as a test, and users do not notice.
2018: the long tail
At this size the average is fine and the slowest reads are the problem. Garbage collection pauses in Cassandra show up as tail latency. Instagram replaces Cassandra's storage engine with RocksDB and publishes it as Rocksandra: on one cluster, P99 reads drop from 60 ms to 20 ms.