Part 1

Complete Distributed Systems Quiz — 30 Questions

Distributed systems quiz — 30 questions across 4 sections covering concurrency, replication, CAP theorem, and consistency
30 questions covering all Class 8 distributed systems topics — target 24+ correct (80%+) to be interview-ready
0 / 30
Questions Revealed
Target: 24+ correct (80%) to be interview-ready
Q1 A race condition occurs when:
  • ATwo users read data at the same time
  • BThe outcome depends on the timing of unsynchronized concurrent operations
  • CThe database is too slow
  • DThe network has high latency
✓ CORRECT: B

A race condition = behavior depends on timing of unsynchronized concurrent operations. Two users reading simultaneously is only a race if their subsequent writes conflict without coordination.

Q2 The safest way to prevent two users from buying the last item is:
  • ACheck inventory in the application before writing
  • BUse UPDATE SET qty = qty - 1 WHERE qty > 0 (atomic database operation)
  • CUse a cache to check inventory
  • DSend an email to the user asking them to wait
✓ CORRECT: B

Atomic SQL: UPDATE SET qty = qty-1 WHERE qty > 0. If affected_rows = 0, item is out of stock. The database handles concurrency atomically. No application-level locks needed.

Q3 Redis SETNX (SET if Not eXists) is used for:
  • ACaching data with a TTL
  • BImplementing a distributed lock (only one process acquires the key)
  • CSorting a list of values
  • DPublishing messages to a queue
✓ CORRECT: B

SETNX = SET if Not eXists. Only one process can set the key. Others see it exists and know the lock is held. Use with TTL for auto-release on crash.

Q4 A distributed lock with a TTL is needed because:
  • ALocks must expire to prevent deadlock if the lock holder crashes
  • BTTL makes the lock faster
  • CRedis requires TTL on all keys
  • DTTL improves read performance
✓ CORRECT: A

Without TTL, if the lock holder crashes, the lock is held forever (deadlock). TTL auto-releases after a timeout, allowing another process to acquire.

Q5 Fencing tokens solve the problem of:
  • ASlow network connections
  • BA stale lock holder writing after its lock has expired and been acquired by another process
  • CCache invalidation
  • DDatabase sharding
✓ CORRECT: B

Fencing tokens: each lock acquisition gets a monotonically increasing token. Storage rejects writes with token < highest seen. Prevents a stale holder (whose lock expired during a GC pause) from overwriting.

Q6 Optimistic locking uses a version column and:
  • ALocks the row before reading
  • BChecks the version on write: UPDATE WHERE version = N; retries if version changed
  • CDeletes the row before updating
  • DUses Redis for locking
✓ CORRECT: B

Optimistic locking reads the version, then writes with WHERE version = N. If another process changed the version in between, the write affects 0 rows, and the application retries.

Q7 The Redlock algorithm acquires a lock on:
  • AA single Redis instance
  • BA majority (3 of 5) of independent Redis instances for fault tolerance
  • CAll database shards
  • DThe application server's local memory
✓ CORRECT: B

Redlock acquires on 5 independent Redis instances. If majority (3+) succeed within timeout, lock is held. Survives up to 2 Redis node failures.

Q8 SELECT ... FOR UPDATE in PostgreSQL:
  • ADeletes the selected rows
  • BPlaces an exclusive lock on the selected rows until the transaction commits
  • CUpdates the rows automatically
  • DCreates a new index
✓ CORRECT: B

SELECT FOR UPDATE places an exclusive row lock. Other transactions that try to read or write those rows must wait until the lock-holding transaction commits or rolls back.

Q9 In single-leader replication, writes go to:
  • AAny replica
  • BOnly the leader (primary), which replicates to followers
  • CAll replicas simultaneously
  • DA random node
✓ CORRECT: B

Single-leader: ALL writes go to the leader. It replicates to followers. Followers are read-only. Simplest topology, most common (PostgreSQL, MySQL, MongoDB).

Q10 Leaderless replication (Cassandra/DynamoDB) achieves consistency through:
  • AA single leader coordinating all writes
  • BQuorum: write to W nodes, read from R nodes, where W + R > N
  • CLocking all replicas before each write
  • DSynchronous replication to all nodes
✓ CORRECT: B

Leaderless uses quorum: W+R>N guarantees read-write overlap. With N=3, W=2, R=2: at least one of the 2 read nodes has the latest write (from the 2 write nodes).

Q11 With N=3 replicas, W=2, R=2 (quorum), the system can tolerate:
  • A0 node failures
  • B1 node failure (majority still available)
  • C2 node failures
  • DAll 3 nodes failing
✓ CORRECT: B

W=2, R=2, N=3. If 1 node fails: writes still succeed (2 of 2 remaining), reads still succeed (2 of 2 remaining). If 2 fail: W=2 but only 1 node available, writes fail.

Q12 The main trade-off of partitioning (sharding) is:
  • ABetter read performance at no cost
  • BWrite scalability gained, but cross-shard joins and transactions become difficult
  • CReduced storage requirements
  • DSimpler operational management
✓ CORRECT: B

Partitioning gives write scalability (N shards = N× writes) but makes cross-shard joins slow (scatter-gather) and cross-shard transactions require 2PC (fragile).

Q13 Sharding by user_id is preferred for user-centric systems because:
  • AIt guarantees perfectly even distribution
  • BAll of a user's data is co-located on one shard, enabling local transactions
  • CIt prevents all race conditions
  • DIt eliminates the need for indexes
✓ CORRECT: B

user_id key co-locates all user data on one shard. User's orders, payments, profile = same shard = local ACID transactions. The primary access pattern is user-centric.

Q14 Multi-leader replication is used when:
  • AYou need the simplest possible architecture
  • BUsers in multiple geographic regions need low-latency writes to a local leader
  • CYou want to avoid all consistency issues
  • DYou have a single data center
✓ CORRECT: B

Multi-leader: each geographic region has a local leader accepting writes. Users get low-latency writes to their nearest leader. Cross-region sync is async.

Q15 The biggest challenge with multi-leader replication is:
  • AHigher read latency
  • BWrite conflicts: two leaders may accept conflicting writes that must be resolved
  • CLack of support in any database
  • DReduced storage capacity
✓ CORRECT: B

Multi-leader = multiple writers = write conflicts. Two leaders may accept conflicting updates to the same row. Must resolve via LWW, CRDTs, or application logic.

Q16 A network partition means:
  • AA server's hard drive is full
  • BThe network splits the cluster into groups that cannot communicate with each other
  • CAll nodes crash simultaneously
  • DThe database runs out of connections
✓ CORRECT: B

Network partition = network splits the cluster into groups that cannot communicate. Nodes in each group are alive but isolated from each other.

Q17 The CAP theorem states that during a network partition, a distributed system must choose between:
  • ASpeed and storage
  • BConsistency (reject writes) and Availability (accept writes, risk conflicts)
  • CCaching and indexing
  • DSQL and NoSQL
✓ CORRECT: B

CAP: during a partition, choose Consistency (reject writes from minority, no stale data) or Availability (accept writes on both sides, risk conflicting data).

Q18 A CP system during a partition:
  • AAccepts all writes on both sides of the partition
  • BRejects writes from the minority partition to maintain consistency
  • CShuts down entirely
  • DSwitches to a different database
✓ CORRECT: B

CP system rejects writes from the minority partition (fewer than N/2+1 nodes). Only the majority side accepts writes. This prevents conflicting writes.

Q19 Split brain occurs when:
  • AA database table is too large
  • BA network partition causes two parts of a cluster to each elect their own leader
  • CA cache key expires
  • DCPU usage exceeds 90%
✓ CORRECT: B

Split brain: network partition → each side elects its own leader → two leaders accepting writes → conflicting data. Prevented by majority quorum.

Q20 Split brain is prevented by requiring:
  • AFaster network connections
  • BA majority quorum (N/2 + 1 votes) for leader election
  • CMore RAM on each server
  • DDisabling replication
✓ CORRECT: B

Majority quorum (N/2+1 votes) for leader election. With 5 nodes, need 3 votes. A partition of 2 nodes cannot elect a leader (only has 2 votes).

Q21 A cascading failure occurs when:
  • AOne failure triggers a chain of failures across dependent services
  • BA single server crashes and is replaced
  • CA scheduled maintenance window is too short
  • DThe database is upgraded to a new version
✓ CORRECT: A

Cascading failure: DB slow → app timeouts → thread pool exhausted → retries → DB overwhelmed → crash. One failure triggers a chain of failures.

Q22 Circuit breakers prevent cascading failures by:
  • AIncreasing the timeout for slow services
  • BImmediately returning an error instead of calling a failing service (stopping the cascade)
  • CAdding more servers
  • DCaching all responses
✓ CORRECT: B

Circuit breaker: after N failures, immediately return error without calling the failing service. This stops the cascade — no retries hitting the already-struggling service.

Q23 Distributed systems should use odd cluster sizes (3, 5, 7) because:
  • AOdd numbers are faster
  • BEven sizes waste a node: 4 nodes tolerates 1 failure (same as 3 nodes)
  • CDatabases only support odd numbers
  • DOdd numbers use less memory
✓ CORRECT: B

4 nodes needs 3 for majority, tolerates 1 failure. 3 nodes needs 2, also tolerates 1. The 4th node adds cost without improving fault tolerance.

Q24 Raft consensus commits a write when:
  • AThe leader alone writes it to disk
  • BA majority (N/2 + 1) of nodes have the log entry
  • CAll nodes have the log entry
  • DThe client sends a confirmation
✓ CORRECT: B

Raft commits when a majority (N/2+1) of nodes have the log entry. This ensures even if the leader crashes, the committed entry exists on a majority and survives.

Q25 You should implement Raft/Paxos yourself in production:
  • AAlways, for maximum control
  • BNever — use battle-tested implementations like etcd, ZooKeeper, or Consul
  • COnly for small systems
  • DOnly in Java
✓ CORRECT: B

Never implement consensus yourself. Use etcd, ZooKeeper, or Consul. These are battle-tested for edge cases you will never think of. Consensus algorithms are notoriously hard to get right.

Q26 Linearizable consistency means:
  • AAll replicas are updated at the exact same nanosecond
  • BEvery read returns the most recent write, as if there were only one copy of the data
  • CData is stored in a linear data structure
  • DWrites happen one at a time, never concurrently
✓ CORRECT: B

Linearizable = every read returns the most recent write, as if there is only one copy of the data. The strongest consistency guarantee. Requires quorum reads/writes.

Q27 Eventual consistency means:
  • AData is never consistent
  • BIf no new writes occur, all replicas will eventually converge to the same value
  • CData is always immediately consistent
  • DOnly eventual reads are supported
✓ CORRECT: B

Eventual consistency = if no new writes occur, all replicas will eventually converge to the same value. They may temporarily disagree, but they eventually agree.

Q28 In a system design interview, the best approach to consistency is:
  • AChoose strong consistency for the entire system
  • BChoose eventual consistency for the entire system
  • CChoose per-operation: strong for financial writes, eventual for reads, read-your-writes for user-facing state
  • DIgnore consistency entirely
✓ CORRECT: C

Per-operation: strong for financial writes (payments, inventory), read-your-writes for user-facing state (profile), eventual for most reads (feed, catalog). This hybrid is what production systems use.

Q29 Read-your-writes consistency ensures:
  • AEvery user sees every other user's latest writes
  • BA user always sees their own recent writes (routed to leader after write)
  • CAll reads are from the leader
  • DWrites are faster than reads
✓ CORRECT: B

RYW ensures a user sees their own recent writes. After updating their name to 'Alice', their next read returns 'Alice' (routed to leader). Other users may still see the old name briefly.

Q30 Last-write-wins (LWW) conflict resolution:
  • APerfectly preserves all data from all conflicting writes
  • BUses timestamps to keep the latest write and silently discard others (may lose data)
  • CRequires user intervention to resolve every conflict
  • DOnly works with SQL databases
✓ CORRECT: B

LWW: compare timestamps, keep the value with the highest timestamp. The other value is silently discarded. Simple but lossy. OK for metrics, not for financial data.

Part 2

Strong vs Eventual Consistency Trade-offs

CONCEPT 1

The Core Trade-off in Every System Design

Every distributed system must choose, for every operation, how consistent the data needs to be. Strong consistency guarantees that every read returns the latest write, but it is slower and less available. Eventual consistency allows reads from any replica (fast, available) but the data might be stale. The art of system design is choosing the right level for each operation — not applying one level to the entire system.

Strong consistency vs eventual consistency — every read equals latest write (higher latency, less available) vs replicas converge over time (lower latency, more available)
Figure 1: Strong consistency (every read = latest write, higher latency, less available) vs Eventual consistency (replicas converge over time, lower latency, more available)
CONCEPT 2

The Consistency-Latency Spectrum

Four consistency levels: linearizable (strictest ~10ms), read-your-writes, monotonic reads, eventual (weakest ~1ms)
Figure 2: Four levels from linearizable (strictest, ~10ms) to eventual (weakest, ~1ms), with read-your-writes and monotonic reads in between

The spectrum is not binary (strong vs eventual). There are intermediate levels that provide useful guarantees at lower cost than full linearizability. Read-your-writes ensures a user always sees their own recent changes (route their reads to the leader for a few seconds after writing). Monotonic reads ensure a user never sees data go backwards (sticky session to one replica). These intermediate levels cover 90% of use cases without the latency cost of full linearizability.

CONCEPT 3

Per-Operation Consistency: The Right Choice for Each

Six operations mapped: payments, inventory, leader election need STRONG; feeds, likes, catalogs use EVENTUAL
Figure 3: Six operations mapped — payments/inventory/leader election need STRONG; feeds/likes/catalogs use EVENTUAL

The most common interview mistake is choosing one consistency level for the entire system. The correct approach is per-operation: list every read and write operation, then classify each as requiring strong, read-your-writes, or eventual consistency. This hybrid approach gives you correctness where it matters (payments) and performance everywhere else (feeds, catalogs, counts).

Interview Anti-Pattern

Never say "I'll use strong consistency everywhere" or "I'll use eventual consistency everywhere." The first kills performance. The second risks data loss on critical operations. Always say: "For X operation I need strong because..., for Y I can use eventual because..."

CONCEPT 4

Read-Your-Writes: The Practical Middle Ground

Read-your-writes: problem — user writes to leader, reads stale replica; solution — route user reads to leader after write
Figure 4: Problem — user writes to leader, reads stale replica. Solution — route user's reads to leader after write.

Read-your-writes (RYW) is the most important intermediate consistency level. It guarantees that a user always sees the effect of their own recent writes, while other users may see eventual consistency. This covers the most critical UX requirement: when a user updates their name, they see the new name immediately. Other users seeing the old name for 30 seconds is acceptable.

Three Implementation Strategies

1. Route to leader after write: After a user writes, set a flag (Redis key user:{id}:wrote_at = timestamp). For the next 10 seconds, route that user's reads to the leader. After 10 seconds, replication has caught up, so reads go back to replicas. Simple and effective.

2. Session-sticky replica: Assign each user to a specific replica via consistent hashing (hash(user_id) % num_replicas). All reads for that user go to the same replica. Once that replica receives the write via replication, the user sees it. Slightly slower than routing to leader but avoids leader overload.

3. Client-side timestamp: The client includes its last write timestamp in every read request. The server checks if the serving replica's data is at least as fresh as that timestamp. If not, it either waits for replication or routes to the leader. This is the most precise approach, used by DynamoDB's session consistency.

CONCEPT 5

Monotonic Reads: Never Go Backwards

Without monotonic reads, user sees 10 comments then 7 (stale replica). With sticky sessions, count only grows.
Figure 5: Without monotonic reads, user sees 10 comments then 7 (stale replica). With sticky sessions, count only grows.

Monotonic reads guarantee that once a user has seen a value, they never see an older value in subsequent reads. Without this, a user might see 10 comments on a post, refresh, and see only 7 (they hit a staler replica). This "time travel" effect is confusing and frustrating. The solution is simple: use sticky sessions (hash user_id to a consistent replica) so all reads go to the same replica, which only moves forward in time.

CONCEPT 6

Real-World Application: E-Commerce Consistency Map

Complete e-commerce system with per-component consistency: product catalog (eventual), cart (session), payment (strong), inventory (strong)
Figure 6: Complete e-commerce system with per-component consistency: product catalog (eventual), cart (session), payment (strong), inventory (strong)

An e-commerce system demonstrates the hybrid approach perfectly. Above the dashed line: Product Catalog, Search Results, Shopping Cart, and User Profile all use eventual or session consistency — they are read-heavy, tolerate brief staleness, and benefit from caching and replicas for low latency. Below the dashed line: Order Placement, Payment, and Inventory all require strong consistency — they involve money, finite resources, and operations where errors cause real-world harm.

CONCEPT 7

Common Anti-Patterns

Five consistency anti-patterns that lose points in interviews — and their fixes
Figure 7: Five consistency anti-patterns that lose points in interviews — and their fixes

The most common anti-pattern is applying one consistency level to the entire system. Saying "I use strong consistency everywhere" kills performance and availability for no benefit (most reads don't need it). Saying "I use eventual consistency for payments" is dangerous (double charges). The second most common mistake is not mentioning consistency at all, which signals you do not understand distributed systems trade-offs. Always proactively state consistency levels per component.

CONCEPT 8

Implementation Reference

Three implementation patterns with specific technologies, latencies, and throughput characteristics
Figure 8: Three implementation patterns with specific technologies, latencies, and throughput characteristics
PatternTechnologiesLatencyUse When
Strong (Linearizable)PostgreSQL leader, etcd, ZooKeeper~10msPayments, inventory, leader election
Read-Your-WritesRedis flag + route to leader; sticky replica~2–5msProfile updates, settings, user-visible state
EventualDynamoDB, Cassandra, CDN cache~1msFeeds, catalogs, counters, search results
CONCEPT 9

Design Checklist

12-step checklist for making consistency decisions in any system design
Figure 9: 12-step checklist for making consistency decisions in any system design
Interview Template: How to Talk About Consistency

For every component in your design, explicitly state: "For [operation], I'll use [strong/eventual/read-your-writes] consistency because [reason]. This means [technology choice and trade-off]."

Example: "For inventory deduction, I'll use strong consistency with UPDATE WHERE qty > 0 because overselling causes real-world harm. For the product catalog, I'll use eventual consistency via CDN caching because a 60-second stale price is acceptable and reduces database load by 95%."

Want to Land at Google, Microsoft or Apple?

Watch Pranjal Jain's free 30-min training — the exact GROW Strategy that helped 1,572+ engineers go from TCS/Infosys to top product companies with a 3–5X salary hike.

DSA + System Design roadmap 1:1 mentorship from ex-Microsoft 1,572+ placed · 4.9★ rated
Watch Free Training →