Data & persistence · No. 15
Event-schema versioning: never silently reshape an event

An integration event is a wire contract the moment it crosses a service boundary. Reshape it in place and you break consumers that are already deployed. Here is the policy that prevents it.
You shipped this event a year ago, and three services consume it:
public sealed record UserRegistered(int UserId, string FullName) : BaseIntegrationEvent;
Today a product requirement says you need first and last name separately. The obvious edit:
// Looks harmless. It is not.
public sealed record UserRegistered(int UserId, string FirstName, string LastName)
: BaseIntegrationEvent;
You deploy the producer. The event serializes with the new shape. Every consumer that still expects
FullName deserializes it, finds no FullName, and either gets a null where it never expected one or
throws on a missing required member. Nothing on the wire told them the shape changed. They were already
deployed and running, and you reshaped the contract under them.
This is not a hypothetical. With database-per-service and async integration over the outbox, consumers
resolve an event by its identity, never by its shape: the outbox serializes the event to JSON keyed by
an EventType that holds the event's declared [EventName] identity when it has one (and its
assembly-qualified type name otherwise), and the broker path publishes on a topic named for the event's
wire name, the kebab-cased [EventName] identity (or the full type name when none is declared), carried
in an mmca-event-name header. Neither key says anything about which fields the payload carries. There is no schema registry in the middle
saying "this is a different shape than you expect." A producer that reshapes a payload silently breaks
every consumer, and it does it in production, asynchronously, where it is hardest to trace.
Why it matters
In a monolith, an event handler and the code that raises the event compile together. Reshape the event and the consumer fails to compile; you fix it in the same commit. The type system is your schema check.
The moment a module is extracted into its own service, that safety net is gone. Producer and consumer are independently deployed. They are different processes, possibly different repos, definitely different deploy cadences. There is now a window where the producer speaks the new shape and the consumer still expects the old one, and no compiler spans that window. The events that were "just an internal contract" inside the monolith are now a wire contract, and wire contracts have exactly one rule: you do not break them out from under a deployed reader.
An event that carries only MessageId (idempotency) and DateOccurred (when the business action
happened) has no version signal at all, and a consumer meeting an unfamiliar payload has nothing to
branch on: it cannot tell a producer that has moved ahead of it from a shape it should refuse, and it
certainly cannot upcast. ADR-010 is the answer, and the scorecard's section 6 row cites its SchemaVersion
gate and the ADR-090 upcaster pipeline as CQRS and event-driven evidence.
The MMCA answer: a version on every event, and a rule for changing it
The decision has two halves: a signal that is enforced, and a discipline for breaking changes.
Half one: every integration event carries an explicit SchemaVersion. The base record exposes it
as a virtual default:
// MMCA.Common.Domain - BaseIntegrationEvent
public virtual int SchemaVersion => 1;
// A concrete event overrides only when it bumps:
public sealed record UserRegisteredV2(int UserId, string FirstName, string LastName)
: BaseIntegrationEvent
{
public override int SchemaVersion => 2;
}
It is serialized with the payload (System.Text.Json on both the outbox path and the broker path, with
the same options), so a consumer always sees the producer's declared version and has an explicit value to branch or
upcast on. And it is not just a convention you have to remember: a fitness function,
EventVersioningConventionTests, asserts that every concrete integration event declares an int SchemaVersion, so a new event cannot ship without one. The same invariant-over-discipline approach as
the layer rules and the dependency fact that fails the build on any MassTransit* package pin: a thing
that matters is a check, not a comment.
Half two: the rule for changing a shape.
- Additive, optional changes keep the same version. Adding a nullable or optional field, or one with a safe default, is backward-compatible. Consumers ignore unknown fields (System.Text.Json's default), and old payloads deserialize with the default. No version bump.
- Breaking changes require a NEW type plus an upcaster, never a silent reshape. Renaming, removing,
or retyping a field is breaking. The producer introduces a new event type (
UserRegisteredV2,SchemaVersion => 2) and publishes it. Consumers register an upcaster that maps the old type/version to the new shape before their handler runs. The old type is retired only after every consumer has drained it.
That last point is forced by the transport, not chosen for taste. The broker routes by the event's
declared contract name, and a new type carries a new [EventName] identity and so a new topic, so a
rename is a parallel-publish-and-drain migration with a real compatibility window, not an in-place edit.
An in-place reshape has no compatibility window: the instant the producer deploys, the old shape is
gone, and any consumer mid-deploy or slow to upgrade is reading a contract that no longer exists.
New-type-for-breaking-change is the only safe option when the transport routes by contract identity and
consumers deploy independently.
The framework ships the wiring for that migration, not only the rule (ADR-090, accepted 2026-08-21). An
upcaster is one typed class, IEventUpcaster<TSource, TTarget>, registered by the module that owns the
contract:
// Module DI: one line per retired contract (hypothetical V2 shown).
services.AddEventUpcaster<ProductVariantChanged, ProductVariantChangedV2, ProductVariantChangedUpcaster>();
// Broker hosts also subscribe their one queue to the retired contract's topic,
// inside AddBrokerMessaging's consumer callback:
x.RegisterIntegrationEventConsumer<ProductVariantChangedV2>(); // the current contract
x.RegisterUpcastedIntegrationEventConsumer<ProductVariantChanged>(); // the old one, draining
The registry chains registrations to the terminal contract (register V1 to V2 and V2 to V3, and a V1
message reaches the V3 handler), and after every hop it stamps MessageId and DateOccurred from the
pre-hop instance, so inbox deduplication keys survive the transform and an upcaster author maps payload
fields only. Both delivery paths honor it, the in-process dispatcher and the broker consumer, so
handlers are written once against the newest contract. A duplicate source contract, a type mapped onto
itself, or a cycle fails host startup with the offenders named, rather than the first message. Retiring
the old type is deleting these lines.
SchemaVersion is non-breaking by construction. A virtual get-only default (=> 1) means no existing
event has to change and no outbox row has to be migrated: System.Text.Json tolerates the missing field
on old payloads and the type supplies the default; new rows simply gain "SchemaVersion":1 (the outbox
serializer sets no naming policy, so the payload keeps the .NET property name). It lives in
the framework, and a framework change reaches every consumer in one pass: the lockstep policy (ADR-016)
bumps every MMCA.Common.* pin in every consumer together, with no phased rollout, so no consumer sits
on a base record its producers have moved past.
How it complements the outbox
This sits directly on top of the transactional outbox (ADR-003). The outbox guarantees an event is delivered at least once: persisted atomically with the state change, then drained to consumers with retries. Schema versioning guarantees that when the event arrives, the consumer can understand it.
The two failure modes are different and both have to be covered. The outbox addresses "the event was lost." Versioning addresses "the event arrived but means something different than the reader thinks." At-least-once delivery already requires consumers to be idempotent (a duplicate can arrive); add to that contract that a consumer should also be tolerant of versions it knows and explicit about versions it does not. The version field is what lets a consumer make that decision instead of guessing from a shape that silently changed.
One lifecycle event per entity: fewer contracts to version
Versioning is cheaper when there are fewer contracts to version, and ADR-083 settles the shape of a
CRUD lifecycle event before ADR-010 governs how it evolves. Instead of a {Entity}Created /
{Entity}Changed / {Entity}Deleted triple, an entity raises one event carrying a
DomainEntityState discriminator, and handlers filter on State. The framework base is two members
wide:
// MMCA.Common.Domain - EntityChangedEvent (XML docs omitted)
public abstract record EntityChangedEvent<TIdentifierType>(
DomainEntityState State,
TIdentifierType EntityId) : BaseDomainEvent
where TIdentifierType : notnull;
Seventeen concrete records derive it across the four repos: nine in ADC's Conference module, seven in Store and one in Helpdesk. Common ships only the base.
For versioning, the collapse means one record, one serialized payload shape and one snapshot entry
per entity instead of three, and a new transition is an enum member rather than a new type. When a
lifecycle event crosses a service boundary, the discriminator rides the wire and is frozen with
everything else. Store's ProductVariantChanged integration event puts State first, typed as
Catalog's own ProductChangeState, which repeats the framework enum's member names and ordinals but
lives in the Shared layer, because the payload-purity rule rejects any type from a *.Domain
assembly on an integration event's wire shape. The committed contract snapshot records
State:ProductChangeState as a member of that event, so the discriminator obeys the same rule as
every other field: per ADR-083, adding an enum member is additive, while renumbering or removing one
is a breaking change that, under ADR-010, takes a new event type and an upcaster. The taxonomy itself is a review
convention: no fitness rule names EntityChangedEvent or checks that a discriminator exists.
Trade-offs, honestly
ADR-010 is candid that the field is a signal, not a complete mechanism.
SchemaVersionby itself does not stop a consumer breaking on a real reshape. It is a value on the wire, and the load-bearing half is the discipline: new type plus upcaster. Two mechanisms back that discipline. A frozen wire-contract snapshot,IntegrationEventContractTestsBase, rebuilds every integration event's member set and compares it with a committed copy, so a missing, extra or retyped member, or a new event, fails the build until someone versions the event and updates the snapshot in the same commit; ADC, Store and Helpdesk each subclass it, while Common does not freeze its own event. And the reshape itself has framework support in the registration extension point (ADR-090): a typedIEventUpcaster<TSource, TTarget>,AddEventUpcaster<...>(), a chaining registry that preserves the envelope, a draining broker consumer for the retired contract's topic, and two fitness functions that reject two upcasters claiming one source contract or a target that does not raiseSchemaVersion. Two gaps stay open and are worth naming: the framework itself still ships no V2 event of its own (its one concrete integration event stays at version 1, so the first real consumer migration will be the pipeline's first production use), and outbox type-name aliasing for a type deleted ahead of policy is deliberately out of scope, because the policy keeps the old type alive until every consumer has drained it. That second gap is narrower than it sounds: the outbox stores and resolves an event's declared[EventName]identity, so an event that declares one stays resolvable through a rename or a namespace or assembly move, and only a type with no declared identity that is deleted early leaves its rows unresolvable. The shared convention base also makes that identity mandatory: a fact onEventConventionTestsBasefails the build for any integration event without an[EventName], in Common and in every consumer tree.- The convention test covers a real event in MMCA.Common, but the framework's own coverage is one
event wide. Common ships exactly one concrete integration event, the sealed record
OutputCacheEvictionRequested, andCommonArchitectureMapregisters the Domain assembly it lives in, soEventVersioningConventionTestsruns against a real event in Common's own build. Enforcement runs at four points: the framework itself plus three consumer trees (ADC, Store and Helpdesk), each subclassing the same base, running its rules against its own event assemblies, and resolving the current release, so all of them run the identical rules. One caveat rides along: Common's map declares no modules, so the Shared-layer half of the namespace rule is relaxed for the framework's own event, while every module-bearing consumer is still held to it. The framework supplies the rule; the consumers still supply the bulk of the events that exercise it. SchemaVersionis informational on the wire (it round-trips out, not back in). A get-only virtual property means you read the version off the concrete type or the JSON, you do not mutate it per instance. That is intentional (a version is a property of the type, not of an individual message), but it means the upcaster reads the declared type, not a settable field. That is literally how the shipped registry works: it indexes upcasters and walks chains by the declared .NET type, and both transports resolve a message back to that type before dispatch (the outbox from its stored identity, the broker from its wire name).
None of these are reasons to skip the field. They are the reasons the field is necessary but not sufficient, and the discipline is the rest of the answer.
Apply this even without MMCA
The policy ports to any event-driven system with independently deployed consumers:
- Put an explicit version on every event, and make it un-skippable. A test that fails the build when a new event omits a version is worth more than a wiki page that says to add one.
- Treat additive-and-optional as the only in-place change you are allowed to make. New nullable field with a default: fine. Anything else is breaking.
- For breaking changes, publish a new type and upcast, then drain and retire the old one. Never edit a shape that a deployed reader still expects. Give the new type its own identity on the wire (its own name, and so its own topic or routing key); use that to get a compatibility window instead of a cliff.
- Pair it with at-least-once delivery and idempotent consumers. Versioning answers "can I understand this?"; the outbox and idempotency answer "did I get it, exactly once in effect?" You need both.
The rule of thumb: the instant an event crosses a service boundary it is a published contract. You can add to it, you can supersede it, but you can never quietly change it.
What we covered: why silently reshaping an integration event breaks already-deployed consumers
(especially after extraction, when the compiler no longer spans producer and consumer), how
MMCA.Common puts an enforced SchemaVersion on every event and answers a breaking change with a new
type plus a registered upcaster that the framework chains and applies on both delivery paths, and how
that complements the outbox's at-least-once delivery.
Next in the series: cross-service auth without a shared secret, JWKS discovery and RS256 so an extracted service validates tokens with no shared key.
MMCA.Common is Apache-2.0 licensed and open source. Star the repo, read the 2-minute ADR-010 behind this
policy, or dotnet add package MMCA.Common.API and try it.
- Repo: https://github.com/ivanball/MMCA.Common
- ADR-010 (event-schema versioning and upcaster policy): ADR-010: Integration-Event Schema Versioning & Upcaster Policy in the docs site.
- ADR-090 (the upcaster registration extension point): ADR-090: Event Upcaster Registration Extension Point in the docs site.
Tags: .NET, C Sharp, Software Architecture, Event-Driven Architecture, Microservices