Bird
0
0

How can you combine the Saga pattern with Kafka to handle a scenario where a service crashes after publishing a success event but before completing its local transaction?

hard📝 Application Q9 of 15
Kafka - Event-Driven Architecture
How can you combine the Saga pattern with Kafka to handle a scenario where a service crashes after publishing a success event but before completing its local transaction?
ARely on Kafka to retry publishing the event automatically until success.
BImplement an outbox pattern to atomically write local transaction and event to a database, then publish event asynchronously.
CUse synchronous Kafka producers to block until the local transaction completes.
DSkip publishing the event and rely on manual reconciliation.
Step-by-Step Solution
Solution:
  1. Step 1: Problem of partial failure

    Service crash after event publish but before local commit causes inconsistency.
  2. Step 2: Outbox pattern solution

    Outbox writes event and local transaction atomically to DB, then publishes event asynchronously to Kafka, ensuring consistency.
  3. Final Answer:

    Implement an outbox pattern to atomically write local transaction and event to a database, then publish event asynchronously. -> Option B
  4. Quick Check:

    Crash after event publish = use outbox pattern [OK]
Quick Trick: Outbox pattern ensures atomic event and transaction writes [OK]
Common Mistakes:
MISTAKES
  • Assuming Kafka retries fix partial commits
  • Using synchronous producers blocks processing
  • Ignoring event publishing leads to manual fixes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kafka Quizzes