LearnFrenzy
Sign in Take a free test

System Design interview · Set 4 of 6

Distributed Systems Concepts for Interviews

  • 6 follow-up questions
  • 4 key points
  • Code examples
Test yourself

The theory behind the boxes

Know which consistency your design offers, how it behaves during partitions and failures, and the practical tools — replication, quorums, consensus services, idempotency — that make it reliable.

  • Trade-offsCAP, PACELC and consistency models.
  • DataReplication, quorums and partitioning.
  • CoordinationConsensus, idempotency and clocks.

Senior system design interviews probe the theory behind the boxes: what consistency your design gives, what happens during a network partition, how nodes agree on a leader. You do not need academic depth — just accurate concepts and their practical consequences.

1. Explain the CAP theorem and PACELC.

CAP: during a network Partition, a distributed store must choose between Consistency (every read sees the latest write, or errors) and Availability (every request gets a response, possibly stale). PACELC adds: Else, when there is no partition, you trade Latency against Consistency — strong consistency needs coordination, which costs time.


2. What consistency models should you know?

  • Strong (linearisable): reads always see the latest committed write — like a single machine.
  • Read-your-writes: a user always sees their own updates.
  • Monotonic reads: a user never sees data go backwards.
  • Eventual: replicas converge if writes stop — fine for likes and view counts, not for balances.

3. How does replication work, and what is replication lag?

In leader–follower replication, writes go to the leader and are copied to followers, which serve reads. With asynchronous replication, followers can lag, so a user may not see a write they just made — fix with reading your own writes from the leader or sticky sessions. Synchronous replication avoids lag but slows writes. Multi-leader and leaderless (quorum) designs trade more complexity for availability.


4. What are quorums?

In leaderless systems with N replicas, a write waits for W acknowledgements and a read queries R replicas. If W + R > N, every read overlaps at least one replica with the latest write. For N = 3, W = 2 and R = 2 is a common balance of consistency and availability.


5. How do nodes agree on a leader or a value?

With a consensus algorithm such as Raft or Paxos: nodes elect a leader by majority vote, the leader replicates a log, and an entry is committed once a majority has stored it. A cluster of 2f + 1 nodes tolerates f failures. You rarely implement it — you use systems built on it (etcd, ZooKeeper, Consul) for configuration, locks and leader election.


6. How do you partition (shard) data well?

Choose a key that spreads load evenly and keeps related data together. Hash partitioning spreads evenly but makes range queries hard; range partitioning supports ranges but risks hot spots (all new timestamps on one shard). Consistent hashing minimises data movement when nodes join or leave. Watch for hot keys such as a celebrity account.


7. Why is idempotency essential in distributed systems?

Networks fail ambiguously — a request may have succeeded even if you never got the response — so clients retry and messages are delivered at least once. Make operations idempotent: use idempotency keys for payments and orders, upserts instead of blind inserts, and de-duplicate processed message ids.

POST /payments
Idempotency-Key: 7f3c-2026-order-1042

server:
  if key seen → return the stored response (no second charge)
  else        → charge, store (key → response), return response

8. Why can't you trust clocks across machines?

Physical clocks drift and are adjusted by NTP, so timestamps from different machines can be out of order — “last write wins” can silently drop data. Use logical clocks (Lamport timestamps, version vectors) to order events causally, or generate ordering from a single source such as a database sequence or the consensus leader.


Remember

Key points

  • Partitions force a choice

    Consistency or availability.

  • W + R > N

    Quorum reads see the latest write.

  • 2f + 1 nodes tolerate f failures

    For majority-based consensus.

  • Retries need idempotency

    Idempotency keys and de-duplication.

Interview drill

Follow-up questions

What the interviewer asks after your first answer. Turn on practice mode, answer each one aloud, then reveal.

  1. 1 Is a single relational database CP or AP? Intermediate

    CAP is about distributed systems with partitions; a single node simply becomes unavailable if unreachable. Replicated setups behave CP or AP depending on how failover and replication are configured.

  2. 2 What is split-brain? Intermediate

    Two nodes both believe they are the leader after a partition and accept conflicting writes. Majority quorums and fencing tokens prevent it.

  3. 3 What is a distributed lock and its risks? Advanced

    A lock shared across machines (via Redis, etcd or ZooKeeper). Risks: the holder pauses (GC, network) past the lock's expiry while another node takes it — use fencing tokens checked by the resource.

  4. 4 At-most-once, at-least-once and exactly-once delivery? Intermediate

    At-most-once may lose messages; at-least-once may duplicate them; “exactly-once” in practice means at-least-once delivery plus idempotent processing.

  5. 5 What is a vector clock? Advanced

    A per-node counter array attached to data that shows whether two versions are causally related or concurrent, so conflicts can be detected and resolved.

  6. 6 What is backpressure? Basic

    A way for an overloaded consumer to slow producers — bounded queues, rejecting with 429 or pausing reads — instead of collapsing under load.

Preparing with friends?

Share this page with your study group or placement batch.

Search LearnFrenzy

Esc

Quick links