How-To Guide

How to Evolve Message Schemas Without Breaking Consumers

Change published event and queue schemas so old and new consumers keep working during a rolling deploy.

On this page

  1. Introduction
  2. Messages Are Interfaces
  3. Compatible and Breaking Changes
  4. Adding a Field Safely
  5. Renaming and Deprecating
  6. Versioning and Registries
  7. Deprecating Without a Flag Day
  8. Conclusion

Introduction

When a producer publishes messages and multiple consumers read them, the schema of those messages is an interface, and changing it breaks everyone who reads it. During a rolling deploy both old and new versions of consumers run at once, so a schema change must be compatible with both. This is stricter than changing a database table, because you cannot migrate the readers in a coordinated step; you can only publish a new shape and wait for the old readers to drain. This article covers the compatibility rules that keep a schema change safe, the patterns that make a change reversible, and how to deprecate a field without a flag day.

Messages Are Interfaces

A message schema is the contract between a producer and its consumers, but unlike an HTTP API it is mediated by a durable queue or log, so messages published before an upgrade may be read after it. That means a consumer must be able to read messages produced by either the old or the new producer, and a producer must not assume every consumer has upgraded. Compatibility is a property of the pair, evaluated across the upgrade window.

The consequence is that schema changes are governed by what consumers tolerate, not by what is convenient for the producer. A field added is easy; a field removed or a type changed is a breaking change that requires a staged rollout of its own. Knowing the compatibility categories lets you plan the change instead of discovering the break in production.

Compatible and Breaking Changes

Additive changes are backward compatible: adding a new optional field means old consumers ignore it and new consumers can use it. Removing a field is backward incompatible: old consumers that read it will fail or see a missing value. Changing a field’s type, narrowing its allowed values, or making an optional field required is also incompatible for one direction or the other. Changing the meaning of a field without changing its name is the most insidious, because nothing technical flags it and only a reader’s assumptions break.

Full compatibility is forward and backward at once: a new producer’s messages are readable by old consumers, and a new consumer can read old messages. Most safe changes are forward compatible in one direction at a time, which is why the standard rollouts add the new field, migrate readers, then remove the old field in a later release. Each step is compatible; the sequence safely changes the shape.

Adding a Field Safely

Adding a field is the easy case, provided it is optional and has a sensible default. Optional means consumers that do not know it do not fail; a default means consumers that do know it can handle messages produced before it existed. Publish the field, let consumers start using it, and only then consider making it required in a much later release, once you are sure no producer omits it.

// Version 1
{
  "type": "order.created",
  "orderId": "o-123",
  "amountCents": 2500
}

// Version 2: add an optional field. Old consumers ignore it; new consumers
// can rely on it once every producer emits it (during the overlap, new
// consumers must handle its absence and treat it as "unknown").
{
  "type": "order.created",
  "orderId": "o-123",
  "amountCents": 2500,
  "currency": "USD"
}

Renaming and Deprecating

Renaming a field breaks readers of the old name, so do it in three releases: add the new field alongside the old and have the producer write both; migrate consumers to read the new field, falling back to the old; then stop writing the old field once no consumer reads it. This is the expand, migrate, contract pattern, and it works for renames, type changes and removals alike.

A type change follows the same shape: add a new field of the new type, populate it in parallel with the old, migrate readers, then remove the old. Never change a field in place, because in-flight messages and un-upgraded consumers will read the old type and fail. The extra field is temporary scaffolding, and its removal is the final step once the migration is verified.

// Expand: write both the old and the new field during the transition
{
  "orderId": "o-123",
  "amountCents": 2500,          // deprecated: removed in v3
  "amount": { "value": 25.00, "currency": "USD" }   // new shape
}

// Consumer reads the new shape, falling back while both are present:
//   const amount = msg.amount ?? fromCents(msg.amountCents);

// Contract: after all consumers read the new shape, drop amountCents.

Versioning and Registries

A schema registry enforces compatibility automatically: producers register a schema, the registry rejects a change that violates the configured compatibility rule, and consumers fetch the schema to decode. This turns a policy into a gate, so an incompatible change fails at publish time rather than in a consumer at read time. Configure the rule to match your rollout: backward compatible for the common case, full compatibility if consumers and producers roll out independently.

Even with a registry, version the message envelope so a consumer can detect a shape it does not understand and handle it explicitly. A consumer that receives an unknown field should ignore it; one that receives a missing expected field must fall back rather than crash. Tolerate unknown fields in forward-compatible consumers, and never ignore a validation failure silently.

Deprecating Without a Flag Day

A flag day, where everyone upgrades at once, is a sign that the change was not made compatible. Avoid it by measuring who reads a field before removing it: instrument consumers to report which fields they access, or check the registry for which schema versions are still in use. Remove a field only when the usage is zero, and keep the deprecated field for at least one full deploy cycle so stragglers are caught.

Document the lifecycle of each field: active, deprecated with a removal date, removed. A consumer team can then plan, and a producer knows when it is safe to contract. Without a lifecycle, deprecated fields linger forever and the schema grows without bound.

Conclusion

Message schemas are interfaces mediated by durable storage, so a change must be compatible across the upgrade window. Add optional fields with defaults, use expand-migrate-contract for renames, type changes and removals, enforce compatibility in a schema registry, and version the envelope so a consumer can detect a shape it does not understand. Measure field usage before removing anything, and give every deprecated field a removal date. Then a schema evolves while old and new consumers coexist, without a flag day and without a surprise break.

Sources: Confluent: Schema Registry compatibility, Avro schema resolution, JSON Schema.

FAQ

What is the safest order to change a field?
Expand, migrate, contract: add the new field alongside the old and write both, migrate consumers to read the new one with a fallback, then stop writing the old field once no consumer reads it. Each step is compatible, so old and new versions coexist during the rollout.
How do I know when it is safe to remove a field?
When no consumer reads it. Instrument consumers to report field access or check the registry for schema versions still in use, and wait at least one full deploy cycle after usage reaches zero before contracting the schema.

Related Examples