Evolving event schemas

Queues, Kafka and event-driven systems Senior Python 3.13+ PostgreSQL 17+ Reviewed By Best Latest Apps

Pick the fix

You need amount as an object (value, currency) instead of a number in OrderPlaced. Safest path?

Options
Hint 1 of 1

Can old consumers still read the event?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Add an optional amount_v2 object, keep amount, and migrate consumers before retiring the old field

Correct. Additive and reversible.

Consumers deploy on their own schedules, so a change must work with old and new readers at once. Add the new shape beside the old field, move consumers over, then remove the old one.

Why not the others?
  • B Change amount to an object in the next deploy. Every consumer parsing a number breaks.
  • C Remove amount and add value and currency. Removing a used field is breaking.
  • D Tell consumers to update the same day. Coordinated big-bang deploys fail.

30-second answer

Treat events as a public contract. Make only compatible changes: add optional fields with defaults, never remove, rename or retype a field consumers use. Enforce it with a schema registry (Avro, Protobuf or JSON Schema) set to a compatibility mode such as BACKWARD, so incompatible schemas are rejected at publish time. For a real break, publish a new event type or version alongside the old one until consumers move.

Practise saying it · 30 s. No recording, just a timer

How do you evolve event schemas?

Say your answer out loud, then check which of these points you covered:

  • Events are contracts
  • Additive changes only
  • Registry with compatibility mode
  • New type for breaks
  • Tolerant consumers

Deep dive

BACKWARD: new consumers can read old data; FORWARD: old consumers can read new data; FULL: both.

Consumers should ignore unknown fields.

Include an event type, version and id in an envelope.

Upcasters convert old event versions to the new shape when reading history.

Common mistakes

  • Renaming a field in place.
  • No registry, so a producer deploy breaks every consumer at once.
  • Reusing an event name for a different meaning.

Senior take & follow-ups

Compatible changes only, registry with a compatibility mode, and versioned types for breaks.

Follow-up questions

Think of your answer first, then open the hint.

  1. What does BACKWARD compatibility mean?

    Show hint

    Consumers on the new schema can read data written with the old one.

  2. How do you remove a field?

    Show hint

    Deprecate it, confirm no consumer reads it, then remove in a new version.

Suggest a fix if something here is wrong or out of date.