Design a Live Likes
Design the like button of a large social app. Anyone can like or unlike a post, the post shows how many likes it has everywhere it appears, and each user sees whether they have liked it. People looking at a post right now see the number climb live, without refreshing, and anyone can open the list of who liked it.
The app records about 2 billion likes a day, peaking at 100,000 likes a second during big events, and the counts are read about 2 million times a second as feeds load. The hard part is skew: when a celebrity posts or a goal is scored, one post can take 30,000 likes a second while 2 million people watch its number. A single counter row, a single database partition or a message per like per viewer would each melt long before the rest of the system notices.
Good questions to ask first
Decide what you would assume for each before you look at ours.
- 1Can a user like a post more than once?
- 2How exact must the count be?
- 3How fast must viewers see it change?
- 4How many likes and reads?
- 5How many people watch counts live?
- 6Do we need the list of who liked?
- 7Other reactions, such as hearts and laughs?
- 8Can likes be removed later?
How to spend the 45 minutes
- 5minPart 1: Requirements: one like per user, freshness
- 5minPart 2: Estimates and the hot-post skew
- 5minPart 3: API: idempotent like, batch reads, live socket
- 15minPart 4: Architecture, from count column to stream
- 15minPart 5: Deep dives: hot counter, dedupe, live fan-out