The interview problem
Design per-post reaction counts across three regions. Handle 300,000 reaction-state requests per second at peak and one million displayed-count reads per second. A user contributes at most one active like to a post, can undo it, and may use multiple devices. Requests and messages can be retried. Display totals may lag, but committed user state must not double count.
Original system-design practice, not a reported company interview. Workload and examples are hypothetical. Primary CRDT research consulted September 27, 2026.
1. Count active relationships, not button presses
The business object is a relationship keyed by post and authenticated user. Its state is liked or not liked, with a version. The displayed count is a projection of active relationships. Counting every incoming increment instead would count retries and repeated likes as separate users.
Use an explicit desired-state operation such as setLiked(post, true, expectedVersion, requestId). A toggle is harder to retry safely because repeating it changes the result again. Bind the request ID to its payload and principal; reject reuse with a different payload.
Choose serialized writes per relationship at a home shard, with replicated durability and fenced ownership. During a partition, reads can remain available while writes that cannot reach the authority are pending or rejected. Do not acknowledge a locally queued request as committed. An alternative that accepts conflicting writes everywhere needs an explicit conflict policy; a counter alone does not define which user intent wins.
2. Separate the state transition from its count projection
client → edge → authoritative relationship shard
↓ atomic transaction
state + request result + outbox record
↓
durable change log
↓
ordered, fenced projection workers
↓
per-post bucket totals → regional display cacheCommit the relationship change, idempotency result and outbox entry together. Only an actual false-to-true transition emits +1; true-to-false emits −1. A request for the existing state may return success without a count event, subject to its version precondition.
Route all writes for a relationship through the same current authority. Use a fencing generation when transferring shard ownership so the old owner cannot keep committing after failover. The authoritative record, not a regional display count, answers whether this user currently likes this post.
3. Walk through retries and concurrent undo
| Request | Result | Count delta |
|---|---|---|
| Initial state false, version 0 | No active relationship | 0 |
| R: set true, expected 0 | Commit true, version 1 | +1 |
| Retry R with identical payload | Return saved result | 0 |
| New request: set true, expected 1 | Already true; no transition | 0 |
| U: set false, expected 1 | Commit false, version 2 | −1 |
| Concurrent V: set false, expected 1 | Version conflict; refresh state | 0 |
| Delayed new like based on version 0 | Version conflict | 0 |
| Intentional new like, expected 2 | Commit true, version 3 | +1 |
The final relationship contributes one, regardless of transport retries. The server checks an existing idempotency record before treating an identical retry as a fresh versioned command. The client can distinguish the original successful result from the current state, which may since have changed.
Request-result retention and version retention are separate choices. After a request result expires, an old expected version still prevents accidental replay. Do not delete an inactive relationship and recreate it at version zero while old commands remain valid. Retain a tombstone, use a generation that cannot be reused, or enforce a bounded request-lifetime protocol that makes old commands invalid.
4. Make projection retries harmless
Process each authoritative stream partition in order. Atomically persist both the processed offset and the affected bucket totals. If the worker crashes before commit, replay repeats uncommitted work. If it crashes after commit, the saved offset prevents double application. A delivery acknowledgment alone is not a durable application checkpoint.
Offsets deduplicate redelivery of the same log position, not two different positions containing the same outbox event. The publisher must preserve one logical append through an idempotent publication protocol, or the projector must additionally deduplicate stable transition IDs. Persist transition-ID deduplication in the same transaction as the total and checkpoint. Its retention must cover possible republication and replay; an expired deduplication entry cannot safely protect against an arbitrarily old event. An outbox does not by itself guarantee a single log record.
Fence competing projection workers. Keep partition identity and generation in checkpoints, and coordinate repartitioning rather than resetting offsets. Detect outbox gaps and reconcile counts against authoritative membership. Updating a total and then separately saving an offset leaves a crash window that can overcount or undercount.
5. Understand what replica merging does and does not solve
State-based counters can maintain one monotonic component per writer and merge each component by maximum. Increment/decrement variants keep separate positive and negative components. The primary CRDT report describes these constructions and their identity assumptions. They converge under the required update and delivery conditions; they do not automatically deduplicate business requests.
For an illustrative increment-only state, replica A knows (7,2,0) and replica B knows (5,4,1). Their merged components are (7,4,1), totaling 12. Taking the maximum of their scalar totals gives max(9,10) = 10 and loses information. Adding totals gives 19 and counts shared history twice.
Merging the same state twice is harmless, but admitting the same client increment twice changes a writer's component twice. A positive vector (7,4,1) and negative vector (2,1,0) produce 12−3 = 9; neither vector alone represents distinct active users. Component ownership, durable identity and restart behavior are necessary assumptions. Resetting a reused component can lose new increments behind an older maximum.
For this product, use authoritative relationship transitions and a rebuildable projection. A CRDT may be appropriate for other event-counting contracts, but it does not replace the one-like-per-user state machine or define concurrent undo semantics.
6. Partition hot posts and budget the read path
With 100 equally loaded workers, 300,000 requests per second averages 3,000 per worker. Real traffic is skewed. Partitioning only by post ID sends every reaction to a viral post through one partition. Hash the relationship key and maintain per-post partial totals across buckets, while keeping each relationship's authority unambiguous.
Suppose a hot post uses 100 buckets. With one million count reads per second and a 90% display-cache hit rate, 100,000 misses per second would require ten million bucket reads per second if those misses all target posts configured with 100 buckets and every miss independently fetches every bucket. Coalesce refreshes, batch reads and maintain cached aggregates with explicit freshness metadata. More write buckets trade write contention for read and reconciliation work.
illustrative compact event size = 64 bytes 300,000 events/second × 64 = 19.2 MB/second 19.2 MB/second × 86,400 = 1.65888 TB/day three replicas = 4.97664 TB/day before overhead
This is a sustained-peak sizing scenario that assumes every request generates a transition event. Retries and no-op requests still consume request-processing capacity but need not produce count events. Measure average traffic separately; peak sustained for a full day is not an average forecast. Include log framing, indexes, replication and retention overhead in a real storage budget.
7. Distinguish exact arithmetic from a current snapshot
The projection uses exact integer arithmetic for admitted transitions. It can still be stale. Eventual delivery and complete processing can make a quiescent projection exact without making every live read current. No finite freshness guarantee survives an unbounded partition unless service stops or the contract changes.
Expose processing lag or watermarks internally and define a display-age objective. Summing independently fetched latest buckets need not represent one instant across the whole system. An exact point-in-time query requires an aligned snapshot or another coordinated read contract, at additional cost.
The client may show an optimistic personal reaction while the global count catches up. Keep those states distinct. Blindly adding one to a count that already incorporates the transition double counts in the UI. A version-aware response or a deliberately separate pending indicator avoids that ambiguity.
8. Rebuild without counting history twice
Take a membership snapshot with a defined corresponding log cut, build bucket totals from that snapshot, then replay only transitions after the cut. If the snapshot already includes an event that is replayed again, the rebuilt count is wrong even when every subsequent message is delivered once.
For partitioned snapshots, preserve a valid per-partition cut and the ownership mapping used to interpret it. Publish the new aggregate generation only after all required buckets are ready and its catch-up condition is met. Include empty buckets rather than confusing absence with a completed zero.
Compare old and rebuilt projections on controlled cuts, inspect discrepancies and retain rollback capability. A periodic reset to a count obtained from an inconsistent scan can hide a pipeline defect while introducing a new one.
9. Do not use the display total as a hard-limit guard
If two regions each see one remaining slot and independently admit a request, both may succeed. A convergent total records the outcome afterward; it does not prevent over-admission. Clamping a negative displayed balance to zero does not undo an accepted operation.
A hard cap requires coordination at the admission boundary or a protocol that allocates and conserves exclusive admission rights. That is a different requirement from displaying social reactions. Choose consistency around the invariant being protected rather than promising every counter is both always available and globally current.
10. Failure tests, follow-ups and self-review
Exercise identical request retries, conflicting undo, expired request records, stale generation replay, duplicate outbox publication, crash between projection writes and checkpointing, worker split brain, region partitions, viral-post skew and a rebuild crossing an ownership migration. Monitor committed transitions versus processed transitions, deduplication hits, conflicts, per-partition lag and reconciled divergence.
Follow-ups: What conflict rule would permit offline writes? How long must inactive relationship versions remain? Can a post deletion race with likes? What guarantees does a cached total expose? How would moderation remove a user's contributions? How does the design change for anonymous view events rather than unique user reactions?
- Define active-user semantics before choosing a counter type.
- Separate request idempotency, log redelivery and replica-merge idempotency.
- Trace concurrent undo with version checks.
- Fence writers and commit projection checkpoints atomically.
- Budget hot-key writes and read fanout.
- State freshness and snapshot limits precisely.
- Rebuild from a compatible snapshot and log cut.
- Keep hard admission invariants separate from display counts.
Sources and attribution
- Shapiro et al.: A comprehensive study of Convergent and Commutative Replicated Data Types — INRIA RR-7506, January 2011, version 1 dated January 13; counter sections 3.1.2–3.1.4 consulted in the primary report hosted by Berkeley.
Retrieved September 27, 2026. No interview date applies. The reaction protocol, timelines, workload and sizing calculations are original practice material.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.