Interview › Databases & Caching
How would you design caching for a read-heavy microservice?
Databases & Caching · Advanced level
Answer
For a read-heavy microservice, I cache hot, expensive, safe-to-stale data using clear key naming, TTL plus jitter, explicit invalidation, request coalescing, warming, and fallback protection for the database.
Technical explanation
Start from metrics: hot endpoints, expensive queries, result size, and allowed staleness.
Use Redis/Valkey shared cache for common data and local cache for tiny ultra-hot config.
Protect the database from miss storms with coalescing, warmup, and fallback rate limits.
Hands-on example
Read-heavy product cache:
product:v3:{id} TTL 15m+jitter
product-price:v1:{id} TTL 60s plus explicit invalidation
Redis timeout 50ms.
On miss, coalesce requests and rate-limit DB fallback.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Databases & Caching interview questions
- How do you decide what to cache and what not to cache?
- How do you handle cache warming after a restart or failover?
- What is the blast radius of a cache outage, and how do you make the app degrade gracefully?
- How would you use Redis for distributed locking, and what are the caveats?
- How would you use Redis for rate limiting?
- How do you test a Redis or database failover without impacting users?
- What is the difference between Redis as a cache and Redis as a primary datastore?
- Why are some Redis commands (KEYS, FLUSHALL) dangerous in production?