Skip to content
Ameen Abozaid
Planned lessonMID-039-L05

Demo: event-driven invalidation from ProductUpdated

  • Lesson 5 of 5
  • Mid-level
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

  1. The catalog service saves the product and publishes ProductUpdated{productId, version} after the transaction commits (use the outbox pattern from the messaging phase).
  2. The cache service consumes the event and calls cache.evict("products", productId).
  3. Update a price and show the new price returned within one second.
  4. 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.
  5. 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.