Event sourcing: handle event schema changing

Any ideas about how to handle this situation?

You design for it. You make backwards compatibility a first class concern when figuring out your event schema, and you get that right early, so that later changes are easy.

See Versioning in an Event Sourced System, by Greg Young.

The basic idea: you never mutate the semantics of a schema element. You can extend a schema by adding a new optional element, and you can deprecate optional elements.

When that doesn't suffice: you create a new schema with better design, and you migrate your data to the new schema.

What do you think about using schema.org?

I think the schema identifiers there are an excellent starting point, and they really open up the possibility of sharing with domain agnostic components some of the details of your messages. For instance, http://schema.org/telephone is a great way to communicate to a generic presentation engine that the enclosed data is suitable for dialing.

So by all means, design your schema with those types in mind, and stay aligned with them for as long as you can.

But when you do diverge, give your schema a new identifier.


This is been the topic of the research that I have been doing in the past 2 years. We found 5 techniques that you can use to handle schema evolution:

  1. Versioned events: never change existing events, always introduce new events.
  2. Weak schema: handle missing attributes or superfluous attributes gracefully.
  3. Upcasters: transform events at runtime, before the application has to process them.
  4. In-place transformation: just change what you need to change in your store.
  5. Copy-transform: copy your whole store into a new store.

This is all summarized in our paper "The Dark Side of Event Sourcing" (https://www.movereem.nl/files/2017SANER-eventsourcing.pdf)

We have also researched surrounding areas:

  • Pruning of your event store to keep the size maintainable.
  • How to keep your read models in sync.
  • How DDD can help you to prevent schema evolution.

The last part is not yet public. But you can find slides of a talk I gave yesterday at DDDEurope here: https://speakerdeck.com/overeemm/dddeurope-2018-event-sourcing-after-launch