Okay, the user wants a document that clearly distinguishes between command, domain, and integration events in event modeling. They’re asking for a primer, so it should be educational but concise, not overly technical.
I should start by explaining why event modeling matters—context is key. Then define each event type with clear examples to avoid confusion. The distinction between command and domain events is especially important because people often mix them up. Integration events need to highlight their role in system communication.
A comparison table would help summarize, but I should place it after explaining each type to ensure the reader already understands the terms. The conclusion should tie it all together, emphasizing how they work together in a system.
Avoid jargon unless defined, and keep the tone approachable but professional. The user likely needs this for a team or documentation, so clarity and correctness are top priorities.
Event Modeling Primer: Distinguishing Command, Domain, and Integration Events
1. Introduction: Why the Distinction Matters
In event-driven architectures, precision in terminology is critical for clear communication, correct system design, and effective debugging. Mislabeling events leads to flawed contracts, unexpected behaviors, and integration failures. This primer clarifies the three fundamental event types in a typical domain-centric, event-sourced or messaging-based system.
2. Core Definitions & Intent
A. Command Event
Intent: A request or intention to perform an action. It is imperative ("do this") and directive.
Nature: Represents a user's or external system's desire for a state change. It has not yet been validated or executed.
Naming Convention: Usually in the imperative mood, present or future tense (e.g., CreateOrder, CancelReservation, RegisterUser, ConfirmPayment).
Key Characteristic:It can be rejected. A command may fail due to validation rules, business constraints, or system state (e.g., "Order cannot be cancelled because it has already shipped").
Typical Flow:Command → (Validation & Business Logic) → Domain Event (if successful) or Error/Rejection.
Analogy: A form you submit (e.g., a purchase order form). It's a request that may be accepted or denied.
B. Domain Event
Intent: A statement of fact about something that has already happened in the business domain. It is declarative.
Nature: Represents a significant, indisputable change in the state of an aggregate or the domain. It is the output of successful command handling.
Naming Convention: In the past tense (e.g., OrderCreated, ReservationCancelled, UserRegistered, PaymentConfirmed).
Key Characteristic:It is irrevocable and immutable. Once published, it represents truth. It should not be "rejected" or "undone" (though compensating actions may trigger new events).
Typical Flow:Command → [Handler/Process Manager] → Domain Event → (Triggers) other Domain Events, Integration Events, or UI updates.
Analogy: The recorded entry in the official ledger (e.g., "Order #123 was created at 10:05 AM"). It's a fact.
C. Integration Event (or System Event)
Intent: A wrapper or projection of a domain event (or other state) intended for communication across system boundaries (bounded contexts, microservices, external systems).
Nature: Focuses on data contract and interoperability. It may flatten domain models, add context (like correlationId, causationId), or contain only the data external consumers need.
Naming Convention: Often mirrors the underlying domain event but may be more technical or context-specific (e.g., OrderCreatedV1, UserRegisteredForMarketing). Sometimes includes the source context (e.g., Billing.OrderCreated).
Key Characteristic:It is about transport and decoupling. Its payload is optimized for consumers, not necessarily for the domain model's integrity. It may be published on a different channel (e.g., Kafka topic, RabbitMQ exchange) than internal domain events.
Analogy: A press release issued to the public (other systems) based on the internal ledger entry. It contains the essential facts, formatted for external distribution.
3. Comparative Summary
Aspect
Command Event
Domain Event
Integration Event
Primary Goal
Request an action
Record a fact
Notify another system
T Direction
Inbound to an aggregate/process manager
Internal within a bounded context
Outbound across a boundary
Temporal Nature
Future-oriented ("I want to...")
Past-oriented ("This happened...")
Past-oriented (reflects a domain fact)
Can it fail?
Yes. Rejected by business rules.
No. It is the result of success.
Technically, but conceptually it's a fact already recorded in its source.
Mutability
Temporary, operational.
Immutable, eternal.
Immutable in transit, but payload may be a projection.
Typical Name
CreateOrder
OrderCreated
OrderCreated (on orders topic)
Payload Focus
Inputs needed to attempt action.
Full state change & metadata (who, when, why).
Consumer-specific data, often denormalized.
Analogy
Job Application
Official Meeting Minutes
Company Newsletter Summary
4. Visual Flow in a Typical System
code
[External Client / User]
|
v
`CreateOrderCommand` <-- [Imperative Request]
|
v
[Order Aggregate / Command Handler]
| (Validates: Is stock available? Is customer valid?)
|
+--(Invalid)--> `OrderCreationRejected` (or error response)
|
v (Success)
`OrderCreated` (Domain Event) <-- [Declarative Fact]
| \
| \ (Internal Subscribers)
| v
| [Update Order Read Model]
| [Send Confirmation Email]
|
v (External Publication)
`OrderCreated` (Integration Event) <-- [System-to-System Contract]
|
v
[Other Bounded Contexts: Inventory, Shipping, Analytics, etc.]
5. Common Pitfalls & Best Practices
Pitfall 1: Using Commands as Integration Events.
Wrong: Publishing CreateOrder to a shared Kafka topic. Consumers don't know if it succeeded.
Right: Publish OrderCreated (the domain fact) as an integration event. Consumers react to the certainty of the fact.
Pitfall 2: Encoding Logic in Integration Event Names.
Wrong:CreateOrderIfStockAvailable. This is a command, not a fact.
Right:OrderCreated. The "if stock available" logic belongs in the command handler for CreateOrderCommand.
Wrong: Publishing a full, complex Order aggregate with lazy-loaded collections as an integration event. This couples consumers to your internal model and causes performance issues.
Right: Create a specific OrderCreated integration event DTO with just orderId, customerId, totalAmount, createdAt. Denormalize data if needed.
Best Practice 1: Commands are Transient. They exist only in the request/processing phase. Do not store them in an event store for business logic. Domain events are what you store and replay.
Best Practice 2: Names Must Reflect Reality. A PaymentSucceeded domain event must only be published after the payment gateway has confirmed success. The timing of the fact is everything.
Best Practice 3: Integration Events are a Public API. Treat their schema as a versioned contract. Use schema registries and backward-compatible changes.
6. Conclusion
Think of the flow as a pipeline of certainty:
A Command is a proposal.
A Domain Event is the accepted, recorded truth within your context.
An Integration Event is the officially certified copy of that truth, shared with the outside world.
By maintaining this clear separation, you ensure:
Unambiguous Communication between developers, domain experts, and stakeholders.
Robust System Design where each event type has a single, clear responsibility.
Loose Coupling between services, as integration events represent stable facts, not volatile intents.
Accurate Auditing & Debugging, as the event stream tells a clear story of what was intended, what actually happened, and what others were told.
Use this model as a checklist:
Before publishing an event, ask: "Is this a request (Command), a recorded fact (Domain Event), or a notification for another system (Integration Event)?" The answer defines its structure, its channel, and its consumers.