عرض عملي: إبطال موجّه بالأحداث من ProductUpdated
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
evict cached products when the catalog service publishes ProductUpdated. Prepares MID-039-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- 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.
اختبر فهمك
Why publish only after commit?
أظهر الإجابة
Otherwise readers can reload the old data and re-fill the cache.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.