System Design course menu
Intermediate System Design Interview Questions
Intermediate system design interview questions with answers: CAP theorem, cache strategies, replication lag, sharding keys, consistent hashing, idempotency and delivery guarantees.
On this page
- 1. Explain the CAP theorem.
- 2. What is eventual consistency? When is it acceptable?
- 3. Explain cache-aside, write-through and write-back.
- 4. What is a cache stampede? How do you prevent it?
- 5. How do you keep a cache consistent with the database?
- 6. What is replication lag? How do you handle it?
- 7. How do you choose a shard key?
- 8. What is consistent hashing?
- 9. Horizontal scaling of reads and of writes: how do they differ?
- 10. What does idempotent mean? Why does it matter?
- 11. Compare at-most-once, at-least-once and exactly-once delivery.
- 12. Kafka or RabbitMQ?
- 13. How do you design a rate limiter?
- 14. Offset or cursor pagination?
- 15. WebSockets, server-sent events, or polling?
- 16. How do you prevent double booking?
- 17. Explain the circuit breaker pattern.
- 18. What are SLI, SLO and SLA?
- 19. Why use percentiles rather than averages?
- 20. Fan-out on write or on read?
These questions check that you can reason about trade-offs.
1. Explain the CAP theorem.#
Show solution
When the network between nodes fails, a distributed store must choose between consistency (refusing some requests) and availability (answering, possibly with stale data). Partitions cannot be avoided, so that is the real choice.
2. What is eventual consistency? When is it acceptable?#
Show solution
Copies may differ for a while, but they eventually agree. It suits likes, feeds and view counts, but not bank balances.
3. Explain cache-aside, write-through and write-back.#
Show solution
In cache-aside, the app fills the cache on a miss. In write-through, writes go to the cache and database together. In write-back, writes go to the cache first, and later to the database, which is fast but risks data loss.
4. What is a cache stampede? How do you prevent it?#
Show solution
A popular entry expires, and many requests hit the database at once. Use a lock so that one request refills it, serve stale data while refreshing, and add randomness to TTLs.
5. How do you keep a cache consistent with the database?#
Show solution
Delete the entry on write, and use a TTL as a safety net. For stronger guarantees, use change data capture to invalidate entries.
6. What is replication lag? How do you handle it?#
Show solution
Replicas fall behind the primary. To handle it, read a user's own recent writes from the primary, and use sticky reads, so that time never goes backwards for a user.
7. How do you choose a shard key?#
Show solution
It should have many values, spread load evenly, and match your main queries, so that most queries touch one shard. Avoid time-based keys, which send all new writes to one shard.
8. What is consistent hashing?#
Show solution
Servers and keys are placed on a ring, and a key belongs to the next server clockwise. Adding a server moves only a small share of keys. Virtual nodes even out the load.
9. Horizontal scaling of reads and of writes: how do they differ?#
Show solution
Reads scale with caches and replicas. Writes scale with sharding, queues and batching, since every replica must apply every write.
10. What does idempotent mean? Why does it matter?#
Show solution
Repeating an operation has the same effect as doing it once. Networks cause retries, so payments and other writes need idempotency keys, to avoid duplicates.
11. Compare at-most-once, at-least-once and exactly-once delivery.#
Show solution
At-most-once may lose messages, at-least-once may repeat them, and exactly-once is hard. Most systems use at-least-once, with idempotent consumers.
12. Kafka or RabbitMQ?#
Show solution
Kafka is a replayable log for high-volume event streams. RabbitMQ is a broker, good for task queues and flexible routing.
13. How do you design a rate limiter?#
Show solution
Use a token bucket or sliding window, stored in Redis with atomic operations, enforced at the gateway, keyed by user or API key, and returning 429 with Retry-After.
14. Offset or cursor pagination?#
Show solution
Offset allows jumping to a page, but it slows on deep pages and can repeat items. Cursors stay fast and stable, so they suit feeds.
15. WebSockets, server-sent events, or polling?#
Show solution
WebSockets suit two-way, real-time apps such as chat. Server-sent events suit one-way updates. Polling is simplest, and suits infrequent changes.
16. How do you prevent double booking?#
Show solution
Make the check and update atomic, with row locks or a conditional UPDATE, and add a unique constraint. Use temporary holds during payment.
17. Explain the circuit breaker pattern.#
Show solution
After repeated failures, calls to a service stop for a while, and fail fast. Trial requests then test recovery. This stops one failing service from dragging down others.
18. What are SLI, SLO and SLA?#
Show solution
An SLI is what you measure, an SLO is your target, and an SLA is a promise to customers, often with penalties.
19. Why use percentiles rather than averages?#
Show solution
Averages hide slow requests. p95 and p99 show what your unluckiest users experience.
20. Fan-out on write or on read?#
Show solution
Fan-out on write prepares feeds in advance, so reads are fast, but posting is costly. Fan-out on read is the opposite. Many systems use a hybrid for accounts with many followers.
Next: Advanced Questions.
Finished this lesson?
Related lessons
Recommended System Design resources
- System Design Interview by Alex Xu
Step-by-step walkthroughs of common design questions, for interview preparation.
Some links are affiliate links. If you buy through them, Laviyx Learn may earn a commission at no extra cost to you. As an Amazon Associate, we earn from qualifying purchases.