Interview › Databases & Caching
What is the difference between a write-through and write-behind cache regarding data loss?
Databases & Caching · Advanced level
Answer
Write-through updates cache and database synchronously, giving stronger consistency but higher write latency. Write-behind writes to cache first and flushes later, improving latency but risking data loss without durable buffering.
Technical explanation
Write-through favors consistency but couples success to both cache and database write paths.
Write-behind favors latency and burst absorption but can lose data before flush.
Write-behind needs durable queueing, idempotent workers, retries, DLQ, and reconciliation.
Hands-on example
Use write-through or direct DB transaction for inventory updates.
Use write-behind only for tolerable-loss events such as page-view counters.
If used: append to Kafka/SQS, update DB idempotently, monitor queue lag, and reconcile totals.
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 test a Redis or database failover without impacting users?
- What is the blast radius of a cache outage, and how do you make the app degrade gracefully?
- How do you handle cache warming after a restart or failover?
- How do you decide what to cache and what not to cache?
- How would you use Redis for distributed locking, and what are the caveats?
- How would you use Redis for rate limiting?
- 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?