Skip to main content
InterviewHubPRO
Section Overview
Q43

Question 43 of 50

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

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

Domain Events Lifecycle: Internal emission vs Outbox publishing.

senior LevelLifecycleSystem Design

In Simple Words: How events travel from aggregate mutations to external message brokers:

  1. Emitted Inside Aggregate: Calling order.cancel("Customer request") records an internal event in an uncommitted in-memory list: this.addDomainEvent(new OrderCancelled(...)).
  2. Repository Commit: When orderRepository.save(order) runs, it commits both the order state change and writes the domain event into the Transactional Outbox Table within the exact same local database transaction.
  3. Message Relay: A background CDC engine (Debezium) or worker process reads the Outbox table and publishes the event to Apache Kafka / RabbitMQ with guaranteed zero-loss delivery.