Demo: event-driven invalidation from ProductUpdated
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
evict cached products when the catalog service publishes ProductUpdated. Prepares MID-039-LAB1.
Draft outline details
Step by step
- The catalog service saves the product and publishes
ProductUpdated{productId, version}after the transaction commits (use the outbox pattern from the messaging phase). - The cache service consumes the event and calls
cache.evict("products", productId). - Update a price and show the new price returned within one second.
- Planned mistake: the handler evicts the cache before the database commit; a concurrent read re-caches the old row. Fix: publish after commit and evict after the commit.
- Make the consumer idempotent (evicting twice is harmless) and add a 10-minute TTL as a safety net.
Check your understanding
Why publish only after commit?
Show answer
Otherwise readers can reload the old data and re-fill the cache.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.