KatInterview

High-Throughput Counter System for Social Engagement

System DesignModel answer
MediumModel answerSystem Designdistributed-systemseventual-consistencyhigh-throughput

Last updated

Design a counting service that supports millions of concurrent engagement actions with eventual consistency and sub-50ms read latency.

Problem

Build a counter service for a social platform where users can engage with content items (posts, videos, profiles). The platform serves millions of active users, and popular content can receive thousands of engagements per second.

What You Need to Support

Your system must allow users to:

  • Record an engagement action on an item
  • Remove their engagement from an item
  • Query the total engagement count for any item

The count can be slightly stale (a few seconds behind) but individual user actions must reflect immediately in their own view.

Performance & Reliability Targets

  • Write volume: Handle 100,000+ engagement actions per second during peak traffic
  • Read latency: Serve count queries in under 50ms
  • Availability: Continue operating through partial infrastructure failures
  • Hot content: A single viral item may receive 5,000-10,000 actions per second

What to Design

  1. API contracts for engagement actions and count retrieval
  2. Storage schema for tracking both individual actions and aggregated totals
  3. Architecture that absorbs write spikes without overloading your primary datastore
  4. Strategy for handling duplicate requests and client retries

Example Operations

PUT    /items/{id}/engagement     → records user's engagement
DELETE /items/{id}/engagement     → removes user's engagement  
GET    /items/{id}/total          → returns current count

Assume user identity comes from authentication context.

Hints

Hint 1

Think about what happens when 10,000 users simultaneously try to increment the same counter in a database

Hint 2

Consider storing the relationship (user engaged with item) separately from the aggregate count

Hint 3

Buffering and batching writes can reduce database load by orders of magnitude