Katkat

Design a Scalable Like Counter

RobloxSoftware Engineer · Onsite

Last updated

This question tests the ability to design a high-throughput, eventually consistent counting system that handles massive concurrent write volumes while maintaining low-latency read access.

Problem Statement

Design a global 'Like' counter service for a platform with millions of concurrent users. Each piece of content (e.g., a game or profile) can receive thousands of likes per second.

Functional Requirements

  • Users must be able to 'like' an item and 'unlike' an item.
  • Users must be able to retrieve the total like count for any item.
  • The count should be accurate with at most a few seconds of lag.

Non-Functional Requirements

  • The system must handle high-write throughput.
  • The system must provide low-latency reads (sub-50ms).
  • The system must be highly available and resilient to partial outages.

Scope

  • Define the API endpoints for liking and reading counts.
  • Propose a data schema for storing counters.
  • Describe the architecture to handle bursts of traffic without overwhelming the primary database.
  • Explain how you would handle potential duplicates or re-tries from clients.

Example Interaction

  • POST /v1/items/{itemId}/like: Increments the counter.
  • GET /v1/items/{itemId}/count: Returns the current integer value of likes.

Hints

Hint 1

Consider using an in-memory data structure to buffer or aggregate updates before persisting them to the database.

Hint 2

Think about the trade-offs between synchronous updates to a relational database versus an asynchronous event-driven approach.

Hint 3

How would you ensure that a single user cannot spam 'like' requests to artificially inflate the count?

Follow-up questions

  • How would you change your design if the business required real-time accuracy for a specific 'trending' subset of items?
  • What strategies would you implement to shard the counter data to prevent hot partitions on popular items?
  • How would you verify the integrity of the counter if the cache and database values drift significantly over time?