📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you make cache invalidation survive a crash between the database commit and the cache delete?

Mid-Level Theory Intermediate

🎯 Key points

  • DB commit and cache delete are a dual write with no shared transaction
  • TTL is the fallback staleness bound in every design
  • Transactional outbox pattern: invalidation row in the same transaction; a relay publishes and retries
  • Idempotent deletes make at-least-once delivery safe and order-independent
  • Event-driven alternative: subscribers to domain or integration events invalidate their own caches
  • CDC on SQL Server can drive invalidation without changing the write path
  • Versioned keys avoid deletes: bump the version, old keys expire by TTL

⏱ 30-second answer

The commit and the delete are a dual write with no shared transaction, so a crash between them leaves stale data. Keep a TTL as the upper bound on staleness, then make invalidation durable with the transactional outbox pattern: write an invalidation message to an outbox table in the same transaction as the data change, and have a relay (a BackgroundService or Azure Functions) publish it, retrying until subscribers have deleted the keys. Deletes are idempotent, so at-least-once delivery is fine. Alternatives: change data capture on SQL Server driving deletes, domain events in an event-driven design, or versioned keys, where the change bumps a version so new reads use a new key and old entries simply age out under their TTL.

🔍 What the interviewer is checking

Checks they know the dual-write problem and the outbox or CDC fix

↩ Usually asked after

More in Caching

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me