← Questions

Design a distributed counter for many users

0
NvidiaSystem designLast asked Sep 2025

A system design interview question asked in Nvidia's technical phone screen, last asked Sep 2025. It tests counters, concurrency and distributed systems.

Design a counter service that many users increment and decrement concurrently. It must support atomic updates and read-after-write consistency, scale horizontally, and stay correct when clients retry and servers fail.

Requirements

  • Functional: increment(counter_id, delta, request_id), decrement, get(counter_id); many counters, some very hot.
  • Non-functional: no lost or double-applied updates; a client reads its own writes; horizontal scale; tolerance of node failures and network partitions; observability of contention.

Clarifying questions

  • How many counters, how many updates per second, and how skewed (one viral counter)?
  • Must every reader see the exact current value, or only the writer itself?
  • Can counters go negative, or must decrements stop at zero (like inventory)?
  • Are retries common, and do clients send a request id?
  • Is eventual consistency acceptable for some counters (view counts) but not others (balances)?

What a strong answer covers

  • A single-process baseline with a lock or atomic, then the distributed design: data model, APIs, partitioning by counter id.
  • Concurrency control options with trade-offs: optimistic compare-and-set with versions, a single writer per shard (leader per partition), distributed locks and their failure modes.
  • Idempotency with request ids stored per counter for a window, so at-least-once delivery gives exactly-once effect.
  • Leader election and replication (Raft or a consensus-backed store), behaviour under partitions, and why wall clocks must not order updates (clock skew).
  • Hot counters: sharded sub-counters summed on read, batching and write combining, and their effect on read-after-write.
  • Monitoring of contention, retries and latency, and rollback of a bad change.

Follow-ups

  • One counter takes 1M increments per second: walk through your design.
  • A decrement must never take the counter below zero.
  • The leader of a shard dies mid-write: what does the client see, and what is the final value?

Where it's asked

What it tests

counters · concurrency · distributed systems

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing