Diagrammatic

Count Facebook Likes, Especially for High-Profile Users — System Design Interview Practice

Design a system to efficiently count and display likes for posts, especially for viral content. Work through the requirements, architecture trade-offs, and an interactive design review.

Concepts and architecture decisions to consider

  • social mediaConcept to explore
  • countingConcept to explore
  • real timeConcept to explore
  • scalabilityConcept to explore
  • aggregationConcept to explore

Interview prompt

Design a like-counting system that keeps the actor-to-post relationship correct while serving accurate-enough counters and live updates for viral posts with millions of likes.

  • Store one authoritative relationship per actor and post, then derive sharded counters and recent-liker views asynchronously.
  • Avoid a single hot post key by striped counters, partitioned event consumers, coalesced broadcasts, and bounded fanout.
  • Return the committed toggle immediately with a version and expose a count that may briefly lag under viral load.
  • Explain duplicate taps, unlike races, recount repair, privacy, moderation, abuse, and reconnect behavior.

Requirements and scale assumptions

  • Like or unlike a post idempotently and return the actor's current state, count estimate, and monotonic version.
  • Display an accurate-enough count, recent eligible likers, and live deltas to connected viewers.
  • Support post deletion, blocked users, privacy rules, recounts, abuse limits, and durable audit events.
  • Target p95 toggle acknowledgement below 150 ms and live counter propagation below 2 seconds for healthy rooms.
  • Handle viral posts with tens of millions of likes without synchronously incrementing one database row.
  • The relationship write must be durable and unique; counters and broadcasts may be eventually consistent.
  • Degrade to periodic refresh when live delivery or counter aggregation is behind, without losing toggles.
  • Handle high-profile users with millions of likes
  • Partition by the primary tenant, user, item, or geographic key and isolate hot partitions.
  • Keep serving state bounded; retain raw events or durable records for replay and auditing.
  • Peak scale: Handle high-profile users with millions of likes — Capacity assumption that drives partitioning and backpressure.
  • Latency target: Real-time updates for like counts — User-facing budget for the primary request or read path.
  • Durable boundary: Committed before async — The source of truth is Count likes for posts in real-time; Handle high-profile users with millions of likes.
  • Async boundary: At-least-once workers — Keep Separate counter and list storage, Eventual consistency for aggregated counts, Sharding by post ID off the synchronous path.

Key entities

  • InteractioninteractionId, actorId, objectId, type, version, occurredAt

    Canonical count facebook likes especially interaction with an idempotency key and ordering version.

  • ConnectionSessionsessionId, userId, deviceId, roomKey, lastHeartbeat, status

    Ephemeral but observable count facebook likes especially connection registration used for routing and presence.

  • FanoutCursorstreamKey, shard, offset, consumerGroup, updatedAt

    Durable progress marker for count facebook likes especially fan-out and replay.

  • DeliveryReceiptinteractionId, recipientId, channel, attempt, status, deliveredAt

    Deduplicated count facebook likes especially delivery state for reconnects, retries, or acknowledgements.

Data flow

  1. 1. Accept and commit the interactionThe count facebook likes especially gateway authenticates the actor, validates room or object membership, applies rate limits, and conditionally commits the interaction.
  2. 2. Publish an ordered eventAn outbox emits the committed count facebook likes especially transition with an event ID, partition key, sequence, and replay retention.
  3. 3. Fan out by partitionConsumers route count facebook likes especially events to connected recipients, durable inboxes, or notification channels without making the origin write wait for every recipient.
  4. 4. Resume and reconcile connectionsClients reconnect with a cursor; the count facebook likes especially service replays missed events, deduplicates delivery, and exposes stale or degraded state.
  5. 5. Measure latency and recoverOperations tracks count facebook likes especially publish-to-deliver latency, hot partitions, reconnect storms, dropped events, and consumer lag for replay or repair.

Deep dives and trade-offs

  • Ordering, idempotency, and hot keysChoose a count facebook likes especially partition key that preserves required order while distributing high-volume rooms, users, or objects. Use event IDs, inboxes, consumer offsets, and conditional state transitions for at-least-once delivery. Split or isolate hot partitions without changing the client-visible sequence contract.
  • Reconnect and replay semanticsIssue resumable count facebook likes especially cursors with an expiry and a clear snapshot-plus-delta fallback. Bound replay windows and rebuild from durable state when a cursor is too old. Expose version and freshness so a client can distinguish current, catching up, and degraded state.
  • Backpressure and presenceKeep connection heartbeats and ephemeral presence separate from durable count facebook likes especially interactions. Coalesce safe updates, shed low-value work, and protect critical events during reconnect storms. Measure end-to-end delivery, not only broker publish latency.
  • Direct fan-out versus pull-based readsUse push for latency-sensitive count facebook likes especially deltas and pull or replay for reconnect, history, and recovery. A push-only design loses state when clients disconnect and a pull-only design wastes latency and bandwidth.
  • Per-recipient queues versus shared streamsUse shared partitioned streams with per-recipient cursors where fan-out is large, and isolate exceptional high-fanout objects. A queue per recipient becomes expensive and hard to inspect at large scale.
  • Strong ordering versus availabilityGuarantee ordering only within the scope the product needs, such as a room, object, or conversation. Global ordering introduces a bottleneck and still does not solve duplicate delivery or reconnect recovery.
Diagrammatic — system design practice and architecture review.