virat.kohli
1,204,337 likes
virat.kohli 2 hours ago
likesone per personcount1,204,337
virat.kohli
1,204,337 likes
virat.kohli 2 hours ago
likesone per personcount1,204,337virat.kohli
1,204,337 likes
virat.kohli 2 hours ago
Instagram with every fact in PostgreSQL, or in Cassandra: a double-tapped like, a story seen a hundred million times, then a question nobody planned. Illustrative numbers.
SQL when facts relate and must stay right: follows, likes, comments, payments. One table answers any question, and a rule or a transaction keeps it right. NoSQL when small writes come by the hundred million and are read back by key: views, trays, messages. It spreads across machines by design, one table per question. Instagram keeps both.
| Difference | SQL | NoSQL |
|---|---|---|
| Shape | Tables with fixed columns; each fact once, linked by ids | Rows by key, laid out per question; facts copied |
| Several changes at once | One transaction: all or nothing | One row at a time |
| A rule (one like per person) | The table enforces it | The app enforces it |
| Writes beyond one machine | Split by hand; transactions stop at the pieces | Spread by key; add a machine to grow |
| A new question | One more query, tonight | A new table, filled from the old |
| Pick it for | Follows, likes, comments, payments | Views, trays, messages, logs |
Three moments on Instagram: Rajat double-taps Virat’s post, a hundred million fans watch his story, and Virat asks where his followers are from.
On the left, a SQL database like PostgreSQL: tables on one machine, every fact stored once. On the right, a NoSQL database like Cassandra: rows by key, spread across many machines.
First, the like. One transaction writes the like row and the post’s count together: both land, or neither does.
Rajat’s thumb slips and taps again. The table has a rule, one like per person per post, so the second row is refused and the count stays put.
With NoSQL, the row and the counter are two separate writes on two machines; nothing holds them together.
The second tap writes the same row again, but the counter still goes up: one person, counted twice. That rule now lives in the app.
Next, a hundred million fans watch Virat’s story in an hour: a row per view, twenty-eight thousand writes a second, all to one machine.
Say it manages twenty thousand: the rest queue up, and after an hour it’s thirty million rows behind.
With NoSQL, each row goes to the machine that owns its key, so a hundred machines share the flood, under three hundred a second each.
Need more? Add a machine, and it takes its share of the keys.
Finally, Virat opens Insights: where are my followers from? Nobody planned that question, but one query joins followers with users and counts by city.
It takes minutes over 273 million rows, but it answers tonight, with no new table.
With NoSQL, the followers table holds only ids, and there is no join to reach each user’s city.
So the team builds a new table, followers by city, fills it overnight, and every new follow writes there too. Each new question needs a new table.
SQL when facts relate and must stay right: follows, likes, comments, payments. NoSQL when small writes come by the hundred million and are read back by key: views, trays, messages. Instagram keeps both.