Schema Evolution
Problem
Event-sourced systems retain events forever (or for years). The event log outlives any single version of the service that wrote it. Consumers must be able to read old events; producers must be able to evolve event shape without breaking replay, downstream projections, or long-lived subscribers.
Same problem exists on message contracts and API contracts — but the event store makes it especially load-bearing: you cannot rewrite history.
Solution
Treat every schema as a versioned contract and evolve it under strict rules that keep old readers working.
Core rules — additive by default
- New fields — add as optional; default when missing.
- Renamed fields — introduce the new name, keep the old for a deprecation window, remove after all consumers have updated.
- Removed fields — deprecate first (log usage), remove only after telemetry shows zero readers.
- Type widening allowed (
int→long); narrowing not without a version bump. - Semantics change — always a new version, never in place.
Version identity
- Events + messages:
typeincludes major version (incident.created@v3). - APIs: URI-path versioned (
/v1/,/v2/) — ADR-0020. - Schemas published as CloudEvents + AsyncAPI (ADR-0005), OpenAPI for REST.
Upcaster / downcaster
For breaking changes in the event store, deploy an upcaster — a function that reads the old event shape and transforms it into the current shape on read. Consumers see a uniform schema; the raw log is preserved.
Contract testing
- Producer tests assert backward compatibility against a golden dataset of past events.
- Consumer tests assert forward compatibility for expected additive changes.
- CI blocks breaking changes without an approved version bump.
When to use
- Every event type in the event store — mandatory.
- Every message on Service Bus.
- Every REST API contract.
- Any long-lived config schema (feature flags, App Config).
Consequences
Positive
- Event log stays readable across service upgrades.
- Replays work against arbitrary historical points.
- Consumers and producers evolve independently within the compatibility window.
Negative
- Upcaster code accumulates — a maintenance surface.
- Deprecation windows can drag if consumers don’t update.
- Contract testing adds CI cost.
Failure modes
- Breaking change slipping in without a version bump — downstream projections corrupt.
- Untested upcaster — replay reads produce silently wrong data.
- Consumers pinning to old schemas indefinitely — blocks producer evolution and prolongs upcaster debt.
References
references/Design Pattern- Schema Evolution.mdreferences/Event Sourcing- Event Model.md- ADRs: 0005 — CloudEvents + AsyncAPI, 0006 — Event sourcing, 0020 — RESTful API guidelines
- Related: ECST, Idempotent Write
Applied in
- All event types across bounded contexts (incident, investigation, ticket, customer-collaboration)
- Watchtower incident event stream — versioned upcasters live in the projection pipeline
- Cogs workflow input/output contracts
- REST API versioning at the shared APIM