Senior · Design · Invalidate cached reads after a successful commit

Design cache freshness and recovery for a database-backed representation across commits, invalidation failure and multiple process owners.

Think through your answer before opening the explanation.

Production engineering

Reveal answer and reasoning

Design cache invalidation from the application's allowed staleness and source ownership. Preserve an explicit commit boundary, deliberate key identity and observability for failed invalidation or refills. Test rollback, successful update and post-commit failure independently, and state whether coordination is local or distributed. The portable snapshot explains the desired publication rule, while actual SQLite and HybridCache checks establish this fixture's implementation.

A production system with multiple replicas or another storage tier needs corresponding integration evidence. Correct ordering is a valuable component, but it should not be expanded into an unsupported guarantee of instantaneous consistency across all readers.

For a replicated service, choose which source version readers can recognize and how cache keys, expiry or invalidation reach every relevant owner. A process-local remove does not erase another instance's entry by assertion. Define recovery from committed-but-not-invalidated state and decide whether retrying a mutation is safe. Keep metrics and diagnostics bounded, and validate behavior with an actual second owner only when that coordination exists.

Tests should compare source truth, returned view and invalidation outcome separately rather than labeling every failure before a response as an uncommitted operation.

What a strong answer covers

  • The companion prints rune,rune,glyph and reads2 without executing SQL or HybridCache.
  • Actual pre-commit rollback preserves source/version1 and the valid cached entry.
  • Commit then removal remains two fallible boundaries; cross-instance coordination is not configured.

Common pitfall

Calling database commit plus a later cache removal one atomic distributed transaction.

Follow-up questions

  1. What should happen if the write committed but cache removal failed?
  2. How would another process discover or expire its stale entry?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions