Video in progress
You have to make a breaking change in the contract of an event with many consumers. How do you roll it out?
I don't break the old topic in place; I release the new version in parallel (orders.v2 or a new event type), the producer writes both for a while, consumers move at their own pace, and v1 is shut down once the last one has moved. The key is knowing exactly who reads what.
📖 Answer
Example: the amount field was a double (which is a mistake in itself), and now we need amountMinor: long and currency. This breaks compatibility: old consumers can't read the new message.
First I check: is breaking really necessary? Often you can add the new field, mark the old one "deprecated", and fill both for a while. That doesn't break compatibility and is the cheapest way.
If breaking is necessary:
-
A new contract. A
payments.charge.completed.v2topic with its own schema. You can also mix two versions in one topic (with atype/versionheader), but that's confusing for consumers and also requires changing the schema registry's subject strategy. -
The producer emits both. Two different events from the outbox, or one event and a small stream application that converts it to
v1. The second is better: the producer code knows only the new model, and the old format is produced at the edge. -
The consumers move. I find out who is reading
v1from the consumer group list. Each team gets a deadline (say, 2 sprints) and a migration guide. When they start readingv2, where to start matters: from the point in time where they stopped inv1, and be ready for duplicates at the crossover. -
Removing
v1. When no active member is left in the consumer groups, the producer stops writingv1. The topic is kept until retention runs out, then deleted.
What you prepare in advance for such rollouts: a catalog of topics and schemas (who reads), a deprecation policy ("the old version is supported for 3 months") and a communication channel with consumers. Without them, a breaking change becomes an organizational problem, not a technical one: finding the last consumer takes months.
Sign up to mark studied questions and save your progress.