Easy · Social and messaging
Comments and likes
Under every post sits a like counter and a comment list. Millions tap the heart on the same famous post at the same moment. Showing the exact number is not essential, but showing the person their own like is. Practise this easy system design problem for free with a Google or GitHub account.
The brief
Under every post sits a like counter and a comment list. Millions tap the heart on the same famous post at the same moment. Showing the exact number is not essential, but showing the person their own like is.
Think of the like counter under a post.
Users, scale and requirements
- Who uses it
- 10 million people a month
- Audience in plain numbers
- 10,000,000 people per month
- Normal peak
- ≈ 30,000 requests per second
- Request mix
- Read: 80%; Write: 18%; Analytics event: 2%
- Speed for 99 of 100 requests
- Read: ≈ 450 ms; Write: ≈ 500 ms
- Successful requests
- 99.9%
- Data safety
- At most 1 minute of writes may be lost.
- Monthly budget
- ≈ $94,000
- Data at rest
- ≈ 3 TB
- Where users are
- North America: 50%; Europe: 30%; Asia Pacific: 20%
- Home region
- North America
- Waiting deadlines
- Read: 900 seconds; Write: 3,600 seconds; Analytics event: 3,600 seconds
- Fresh reads
- People must see their own changes. At most 0.1% of reads may be stale in the model.
- Personal reads
- 25% of reads are private; a shared public copy cannot answer them.
≈ marks an approximation, just as in the game. Waiting deadlines measure the age of queued work and are separate from interactive response time.
- A like is only a few bytes. The count is what people keep asking for.
Questions that shape the design
Must the like count be exact?
No. A count that is a few seconds behind or off by a few is fine. It rounds to "1.2M" anyway.
Must I see my own like straight away?
Yes. If you tap the heart and it does not light up, you will tap again.
Can a comment be lost?
Comments should be kept. After a failure, at most the last 60 seconds of writes may need replay.
Do all posts get the same traffic?
No. One post may get 10 percent of all likes for an hour while a million others get none.
The traffic day
Consumer traffic, busiest in the evening. The clock covers 00:00 to 24:00 in the home region. Events add pressure on top of that normal traffic.
20:00 · Viral spike
A post blows up. Traffic climbs to several times normal within minutes.
Traffic reaches 5 times the scheduled load; rises over 600 seconds, holds for 3,600 seconds and eases over 3,600 seconds.
13:00 · Hot key
One item gets a huge share of traffic: a celebrity profile, one product, one merchant.
Affected share: 10%. Duration: ≈ 3,600 seconds.
What a strong design has to handle
- What if one row in your database got 10,000 writes per second?
- A five-second cache keeps counts cheap but means a count can be five seconds old. Rounding to "1.2M" hides it.
- Batching likes in workers saves the database but means a crash can lose the last few seconds of taps. That is the "lose up to a minute" trade the requirement allows.
Make a prediction, run a full traffic day, then compare the result. The in-game editorial opens after a finished day and includes measured reference designs.
Concepts to practise
Related problems
- Hard
Social feed
Every person opens the app and sees a feed of posts from the people they follow. Most people have a few hundred followers, but a few have millions, and when they post, millions of feeds must change. The feed must be fast and your own post must show up at once.
- Medium
Short-video feed
People swipe through an endless feed of clips of 10 to 30 seconds. The next clip must already be on the phone before the swipe. One clip can suddenly get millions of views, and every view is a signal that picks what to show next.
- Easy
Leaderboards
Players send their score at the end of every match and open the top-100 table all day. Everyone looks at the same top 100, which makes that one answer extremely popular. A tournament final will make it much worse.
- Hard
Black Friday marketplace
Once a year a marketplace puts thousands of deals live at the same minute. Millions browse and search, a few doorbuster items get hammered, and a smaller crowd checks out. A payment must never be taken twice, and the day must survive the card processor having a bad hour.