call(back)

Design Recent Like Counts and Trending Posts

Design the backend for three features of a social platform, all defined over the last 60 seconds:

  • given a post, return how many likes it received;
  • return the most-liked posts globally;
  • return the most-liked posts in each region.

Peak write load is around one million likes per second, with an average of 100,000 to 300,000. Before designing, settle with the interviewer whether the window slides or tumbles, how exact each number must be, how a like is assigned to a region, and whether an unlike subtracts.

Hints

Hint 1

The three reads have different needs. A count shown next to a post should be close to exact; a trending list is a ranking surface and can be approximate and a few seconds old.

Hint 2

For the point query, keep a small ring of per-second counters per post and add up the last sixty at read time.

Hint 3

For the lists, do not compute at read time. A stream job maintains the windowed counts and publishes snapshots that readers fetch.

Asked at

Similar Problems6