Skip to main content
InterviewHubPRO
Section Overview
Q32

Question 32 of 50

Part 3: Advanced Architecture & Production Patterns (Senior / Lead)

64%
Domain-Driven Design (50 Qs)•Part 3: Advanced Architecture & Production Patterns (Senior / Lead)

How do you implement Idempotency in Domain Event Consumers?

senior LevelSystem Design

In Simple Words: Message brokers (Kafka, RabbitMQ) provide at-least-once delivery, meaning event handlers will occasionally receive the exact same event multiple times:

  • Idempotent Consumer Pattern:
    1. Consumer inspects incoming eventId (UUID).
    2. Queries a local processed_events database table.
    3. If eventId exists -> Acknowledge and discard immediately!
    4. If not -> Process business logic, insert eventId into processed_events, and commit in a single atomic transaction.