SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 50
Design live like count updates
When you look at a post, its like count ticks up while you watch, without refreshing. As you scroll, different posts come into view and should start updating, and posts you scrolled past should stop. The like counts themselves already exist in a separate counting service.
Requirements
- While a post is on screen, its displayed like count updates live.
- Updates start when a post scrolls into view and stop when it leaves view or the app goes to the background.
- A viewer's own like shows instantly and is never undone by a slightly stale update.
- The count on screen never jumps backwards because updates arrived out of order.
Constraints and assumptions
- 50 million clients connected at peak, each with about 5 posts on screen; scrolling changes about one subscription per client every 5 seconds.
- The counting service emits about 100,000 count changes per second in total; one viral post can change 50,000 times per second.
- A change should be visible on watching screens within 2 seconds.
- Clients have limited battery and bandwidth: no more than one update per post per second is useful.
Out of scope for the first sketch
How likes are recorded and counted durably · Comments and other live features · Notifications to the post author
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design live like count updates
Finish your first sketch before answering these. Cross out freely.
- A viral post gets 50,000 likes per second. How many messages does each watching client receive?
- A user scrolls quickly past 30 posts in 10 seconds. What subscription traffic does that create, and where is it absorbed?
- An update saying 1,000 arrives after one saying 1,005. What does the client show, and how does it know?
- A connection server holding 200,000 clients restarts. What do those clients see, and what load hits the rest of the system?
- Would you push updates at all for a post with three viewers, or just let clients poll? Where is the crossover?
Compare afterwards: worked approaches and reading at sketchbook /questions/live-like-updates/review