Event sourcing
Event sourcing captures every state change as an immutable event. Current state is derived by replaying a stream, never stored in place. ION applies it to the Incident, Investigation, and Ticket aggregates, where history, auditability, and replay are first-class concerns.
Building blocks
The model separates four concepts. A command can be rejected; a committed event is an immutable fact.
| Block | Meaning |
|---|---|
| Trigger | A user, external system, or automated process that asks for work — exposed as a REST endpoint. |
| Command | An intent to change state, enriched with the parameters needed to decide (domain class UpdateIncidentStatusCommand; wire type ion.command.securityincident.updatestatus.v1). |
| Event | A business fact that already happened and was persisted (domain class IncidentStatusUpdatedEvent; wire type ion.event.securityincident.statusupdated.v1). Named in past tense, in domain language. |
| View | A query-shaped projection of events for a specific UI, report, or automated reader. |
Patterns
| Pattern | Chain | Use |
|---|---|---|
| Command | Trigger → Command → Event(s) | A state change from request to committed fact. |
| View | Event(s) → View | Build a read model from existing facts. |
| Automation | Event(s) → View → Trigger → Command → Event(s) | A robot reacts to facts and issues the next command (automated closure, enrichment). |
| Translation | Event(s) in system A → View → Trigger → Command → Event(s) in system B | Synchronize across a boundary — Sentinel and ServiceNow synchronization follow this. |
Event Sourcing Design
End-to-end flow
- A trigger reaches the Command API or a BFF; the API validates the payload, authenticates and authorizes it at APIM, and returns 202 Accepted.
- The command is enqueued. Ordering and per-aggregate processing use queue or session semantics; the command id supports deduplication.
- The command subscriber opens a Cosmos transactional batch on the aggregate’s logical partition, reads the full stream, and reconstructs current state.
- It validates domain invariants. On success it appends one or more new events and commits; on failure it records a command-failed or command-denied fact.
- Change Feed acts as the outbox — committed events flow to local projectors and to the integration publisher without a co-committed broker write.
- The publisher translates internal events into versioned integration events on the shared Service Bus. Consumers (projections, workflows, external adapters) are idempotent and tolerate redelivery.
The append is the source transaction. A producer never co-commits a domain event and a broker message; Change Feed closes that dual-write gap.
Consistency boundaries
- The aggregate stream is the unit of atomic append and optimistic concurrency.
- Events in one stream carry a strictly increasing sequence.
- There is no global order across aggregates or stores.
- Projections and cross-context reactions are eventually consistent.
- Correlation and causation express a business chain; platform arrival order does not.
- A domain accepts external input only through its own commands and invariants. No consumer writes another domain’s private store.
Domain facts versus integration events
A stored domain event records an accepted fact inside the owning context. A publisher may expose it as an integration event when another context needs it. The integration contract can omit private fields or use a separately versioned payload, but it must preserve event identity, tenant scope, correlation, causation, and the link to the source aggregate. A Service Bus message is not authoritative merely because it carries an event — authority stays with the committed stream.
Design rules
- Model events as business facts, not mutable records or database change capture.
- Keep invariants that need atomicity inside one aggregate stream.
- Make fold functions deterministic — no clock, no I/O, no randomness.
- Make command handling and all consumers idempotent.
- Version event contracts and keep readers for all retained history.
- Use projections for cross-stream and analytical queries.
- Record external synchronization outcomes as facts rather than hiding divergence.
- Rebuild derived state from history instead of repairing it in place.