System Design

Caching and Read Replicas Interview Questions

How do you scale a read-heavy API: caching, CDNs, and database read replicas? — spoken sample answer for Indian interviews.

  • 5Questions with answers
  • 3Difficulty levels

Questions (5)

Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.

Question 1
Interview Intermediate
Question

How do you scale a read-heavy API: caching, CDNs, and database read replicas?

Answer:

I would measure first. If the same public response is hit over and over, I put a CDN in front. If the origin still repeats DB reads, I put Redis or Memcached with cache-aside: read cache, on miss read DB, then fill cache, TTL plus invalidation on write. Read replicas help queries that can live with a little lag. Writes still go to primary. I would add indexes and kill N-plus-1 queries before I buy more boxes. Stampede: when a hot key expires, I do not let 5,000 requests hit the DB together. I use a lock around rebuild or jitter the TTLs. I would not cache private user data on a shared CDN edge without thinking about it. I watch hit rate, replica lag, and p95, not just CPU.

Question 2
Interview Intermediate
Question

What is cache stampedes, and how do you stop one?

Answer:

When a hot key expires, many requests miss together and all hit the database. I would use a lock or singleflight so one request refills, slightly jitter TTLs, and keep a stale-while-revalidate value. I would not set the same TTL on a celebrity key for every app instance. Stampede is the follow-up after I say 'just put Redis in front'.

Question 3
Interview Intermediate
Question

When do read replicas go wrong?

Answer:

Replicas lag. If I write and immediately read from a replica I may not see my write. I would read-your-writes from the primary for that session, or use a version token. Replicas also do not help write-heavy workloads. I would not add five replicas and call the design done if the bottleneck is writes. I mention replica lag monitoring because silent lag is how users see 'missing data'.

Question 4
Interview Beginner
Question

Cache-aside versus write-through — which do you use for a user profile?

Answer:

I usually cache-aside: app reads cache, on miss loads DB and sets cache. On update I write DB then delete or update the key. Write-through is simpler for coherence but makes Redis a dependency on every write. User profiles can be slightly stale for a second if I delete the key on write and let the next read refill. I would not cache-aside a bank balance without a clear TTL and invalidation story.

Question 5
Interview Beginner
Question

Where does a CDN help, and where does it not?

Answer:

CDN helps static assets and cacheable GET APIs with a cache key. It does not help personalized feeds unless I am careful with cache keys, and it does not help writes. I would put images and JS on a CDN. I would not put 'GET /cart' on a shared CDN cache. I mention cache headers and purge. CDN is edge cache, Redis is app cache. I would not mix the two boxes in a diagram without saying why.

Practice with AI mock interviews

Run System Design mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.

Free to start · No credit card required