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.

Preparing for an interview?

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

← All Databases & Caching questions