Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Asynchronous and Event-Driven Systems
Lesson 18 of 20

Schema evolution for events

Change event formats without breaking consumers you do not deploy or history you must replay.

15 min read

Events outlive the code that wrote them

An API response is read once, immediately. An event is read by consumers owned by other teams that deploy on their own schedule, and it may sit in a log for months to be replayed later. That means a producer can never assume all consumers have upgraded, and a consumer must read events written by code that no longer exists. A careless rename can break five services, and you will only find out when they fail.

Compatibility rules

Compatibility is about which side can read the other's data.

  • Backward compatible: new consumers can read old events. Needed for replay
  • Forward compatible: old consumers can read new events. Needed because producers usually deploy first
  • Safe changes: add an optional field with a default; ignore unknown fields when reading
  • Breaking changes: rename or remove a required field, change a field's type or meaning

Formats and a schema registry

Binary formats such as Avro and Protobuf are compact and come with explicit evolution rules: Protobuf identifies fields by number, so you add new numbers and never reuse old ones. A schema registry stores every version of each topic's schema and rejects a producer's new schema if it violates the configured compatibility mode, catching breaking changes at deploy time instead of in production. JSON with JSON Schema works too, but the discipline is then up to you and your CI checks.

When you must break

Sometimes the meaning really changes. Publish a new event type or a versioned topic (orders.v2), dual-publish both versions while consumers migrate, and retire the old one when its last consumer has moved. In event-sourced systems, upcasters translate old event versions into the current shape as they are read. Give every event a standard envelope: event ID, type, schema version, occurred-at timestamp and producer name.

Key takeaways

  • Events are a public, long-lived contract: assume old and new versions coexist
  • Add optional fields with defaults; never rename, retype or reuse fields
  • A schema registry enforces compatibility before a breaking change ships
  • For real breaks, publish a new version alongside the old and migrate consumers

Sign in to track lessons and earn badges.

Stream processing: windows and watermarksWorkflows: orchestration vs choreography

Coming up

Course: 0/20 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 10/10Design a Durable Workflow EngineRun long-lived workflows with durable history, timers, retries, compensation and exactly-once step effects.MAJORHardPRO
All 10 challenges →