Instagram: from 3 engineers on Postgres to a billion users
In 2011 Instagram had 14 million users and 3 engineers; in September 2025 Meta said it had 3 billion monthly users. In between, its core stayed surprisingly plain: Django, PostgreSQL split into thousands of logical shards, Redis and memcached, and a 64-bit ID made inside Postgres. This is the giant whose early stack looks most like your team's, so it is the one to study most closely.
By the end you can
- Explain logical shards on Postgres schemas, and how they move to new servers without changing app code
- Read an Instagram-style 64-bit ID bit by bit, and write the PL/pgSQL function that makes it
- Choose between fan-out on write and fan-out on read for a feed, and handle big accounts
- Trace a photo from upload to CDN, and say where Cassandra fitted in
- Build the ID generator, move a logical shard with logical replication, and run a fan-out worker
The everyday picture
A new grocery chain opens with 4 stores and one warehouse, but the manager plans for 400. Instead of 4 big shelves, he labels 400 small crates, one for each future store's stock, and stacks 100 crates in each of the 4 rooms. A clipboard at the door says which room holds which crate. When room 2 gets full, he does not repack anything. He carries 50 whole crates to a new room and changes 50 lines on the clipboard.
Every item also gets a sticker when it arrives: the date and time, the crate number, and a running number. From the sticker alone, anyone knows when it arrived and which crate it belongs to, without asking the office. Instagram's database is those crates (logical shards), that clipboard (a shard map), and that sticker (the 64-bit ID).
What the product must do
Functional: upload a photo or video with a caption; follow people; see a feed of posts from people you follow, newest or best first; like and comment; see who liked what.
Non-functional:
- Posting feels instant, for someone with 10 followers and someone with 10 million. The 2011 post says fan-out ran in a task queue "so posting is as responsive for a new user as it is for a user with many followers".
- The feed loads fast, which means it cannot be computed from scratch on every open.
- Media is big, metadata is small. Photos go to object storage and a CDN; the database holds only ids, captions and keys (Files and CDNs).
- Growth without rewrites. A tiny team must be able to add database servers without changing app code or taking long downtime.