How does Instagram count 1,000,000 likes a second?
Free AI-generated illustrated lesson. Hand-drawn and narrated, step by step.
How does Instagram count 1,000,000 likes a second?
Imagine a viral video of a cat playing piano gets a million likes in a single second. If Instagram used a standard database, every single 'like' would have to wait in a long line to update one tiny number.
But here is the strange part: a physical hard drive can only lock and update that specific piece of data a few thousand times per second. Trying to do it a million times creates a massive traffic jam that would crash the entire app.
So how does the count keep climbing without the system exploding? To survive the stampede, Instagram has to stop counting perfectly and start doing something much more clever.
Imagine a single database trying to handle the 'hammering' of a million likes. Every time you tap that heart, the system has to lock the row, increment the count, and save it back to disk.
But here's the strange part: the physical disk can't keep up with the speed of the internet. This creates a massive traffic jam called a write-back bottleneck, where the database spends more time waiting for the hardware than actually counting.
To survive, we have to stop treating the database as the immediate source of truth. We need a way to buffer the chaos before it ever hits the disk.
If Instagram tried to show everyone the exact same count at the exact same millisecond, the whole app would freeze. Instead, they use a trick called Eventual Consistency, where different servers hold slightly different truths for a moment.
Imagine you and a friend are looking at the same post. You're connected to a server in London, while they're on a server in New York. When you hit like, London records it instantly, but New York hasn't heard the news yet.
Every few seconds, these servers 'gossip' to sync their totals. Only then does your friend's count jump up to match yours. It’s not perfectly accurate right now, but it will be eventually.
Watch this free lesson — play it in My Magic Pencil.