Event-Driven Invalidation

Using domain events, change feeds, and webhook-style signals to invalidate caches when real source changes happen.

Event-driven invalidation uses source changes as the trigger for cache trust changes. Instead of waiting for time to pass, the system listens for domain events, change data capture streams, webhooks, or explicit invalidation messages and uses them to invalidate or refresh affected cache entries.

This can be much more precise than pure TTL because invalidation responds to actual changes. The trade-off is operational complexity. Event order, delivery guarantees, replay behavior, and dependency fan-out now matter directly to cache correctness.

    sequenceDiagram
	    participant Source
	    participant EventBus
	    participant CacheLayer
	
	    Source->>EventBus: product.updated
	    EventBus->>CacheLayer: product.updated
	    CacheLayer->>CacheLayer: invalidate or refresh affected entries

Why It Matters

This pattern matters because it aligns freshness with actual change instead of with coarse time windows. For volatile or business-critical data, that can deliver better freshness without driving TTLs down to the point where the cache loses value. But the system is now only as reliable as its event path and dependency model.

Where Event-Driven Invalidation Fits

This approach is strongest when:

  • the source emits meaningful change signals
  • the cache dependency graph is at least partly understood
  • freshness matters enough that TTL-only invalidation is too crude
  • the team can operate asynchronous pipelines confidently

It is weaker when event delivery is unreliable, change meaning is ambiguous, or the cache dependencies are too poorly understood for precise targeting.

Example

This event-driven invalidation contract makes the trigger and action explicit.

1event_invalidation:
2  trigger: product.updated
3  actions:
4    - delete_key: product:{product_id}
5    - purge_tag: product-{product_id}
6    - refresh_projection: category-membership

What to notice:

  • one event can drive several invalidation actions across layers
  • precision depends on the event semantics and dependency map
  • event-driven invalidation often still coexists with TTL as a safety net

Operational Risks

Event-driven invalidation introduces several failure modes:

  • delayed events
  • duplicate events
  • missing events
  • out-of-order delivery
  • subscribers that fall behind or fail silently

A correct design has to decide what the cache should do when event delivery is late or uncertain.

Common Mistakes

  • assuming event-driven invalidation is automatically precise
  • forgetting replay or recovery when subscribers miss historical changes
  • treating domain events as if they already encode every affected cached artifact
  • using event-driven invalidation without a backup freshness boundary such as TTL

Design Review Question

Why is event-driven invalidation often paired with TTL even when event delivery exists?

The stronger answer is that events improve precision but do not remove operational failure risk. TTL provides a backup bound on staleness if an event is delayed, missed, or processed incorrectly.

Quiz Time

Loading quiz…
Revised on Thursday, April 23, 2026