Messaging patterns · senior
Event design and schema evolution
Events are a contract between teams. A rename breaks consumers. Use additive changes, a schema registry with a compatibility rule, and a standard envelope.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- A rename removes a field readers need, so it is a breaking change. Safe change: add an optional field with a default. For anything else: add the new field, publish both, move every consumer, then remove the old one, or publish a new version side by side.
- A schema registry checks every new schema against a compatibility rule. BACKWARD: consumers on the new schema can read old data, so upgrade consumers first. FORWARD: old consumers can read new data, so upgrade producers first. FULL is both. The _TRANSITIVE modes check against every older version.
- Consumer-driven contract tests (for example Pact message contracts) catch breaks before release.
- Readers should ignore unknown fields, but must not turn a missing money field into null. Fail loudly to a dead-letter topic.
- JSON is readable but has no enforced schema. Avro is compact and needs the writer's schema, usually with a registry id in each message. Protobuf has generated code and uses field numbers: never reuse or renumber them, and mark removed fields reserved.
- Envelope: event_id, event_type (past tense, such as OrderPlaced), schema version, occurred_at in UTC, producer, the order id as key, a per-order sequence and a trace id.
- Thin event (only an id) makes every consumer call back. Fat event gives independence but spreads data. Usual answer: the facts of the event and the fields most consumers need, not the database row. One fact per event, not a generic OrderUpdated.
- Money as integer paise plus a currency code, never a float. Keep personal data out unless a consumer truly needs it. For large payloads put the document in object storage and send a reference (claim check).
The red pen
Common traps: mistake → fix
Mistake: Tell the consumers to update
Fix: use a compatible change process.
Mistake: JSON is fine, we will be careful
Fix: convention fails with 40 services.
Mistake: Reuse a Protobuf field number
Fix: old data is read as the wrong field.
Mistake: Dump the database row as the event
Fix: it leaks internals and personal data.
Easy to hard
Questions interviewers ask, easy to hard
- Consumers crashed after a producer renamed a field. What now and how do you prevent it?
- Avro, Protobuf or JSON?
- What goes in an OrderPlaced event?
- What does BACKWARD compatibility mean?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.