مشكلة الكتابة المزدوجة
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
explain why writing to a database and a broker separately can lose or invent events.
الموضوعات المخطط لها
- A dual write updates two systems (database, broker) with no shared transaction.
- Commit then publish: a crash between the two loses the event. The order exists, nobody hears about it.
- Publish then commit: a rollback or crash leaves an event for an order that does not exist.
- Publishing inside the DB transaction does not fix it: the broker call is not part of that transaction.
- Retrying makes it worse without idempotency: you may publish twice.
تفاصيل المخطط المبدئي
عرض عملي
@Transactional
void place(Order o) {
repo.save(o);
kafka.send("order-placed", o.id(), event); // not atomic with the commit
}اختبر فهمك
The service crashes after the commit but before send. What is lost?
أظهر الإجابة
The OrderPlaced event; the order stays in the database.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.