Skip to content
System Designer

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.

  1. 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.

  2. 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