Contract Versioning
In this article
- Sort a change to a tool's message format into additive or breaking by asking what an existing reader does with it.
- Fill in the four pairs of old and new producer and consumer for a change, and mark the pair that breaks.
- Write a dual-read adapter that lets a run saved under the old version resume, and say when to remove it.
- Spot a new enum value reaching a reader that knows only the old set, and make that reader fail loudly.
- Terms defined here: additive change, tolerant reader, breaking change, compatibility adapter, migration window, version negotiation.
Overview
A made-up online shop's support agent issues refunds through a create_refund tool; order O-1042 was paid 49.00 EUR. Its refund is paused, waiting for a person to approve it, when version 2 of the tool goes live. One of the v2 changes looks harmless: the amount field gets a new name and a new unit. When the approval arrives, will the saved refund still go through, and for how much?
By the end you can tell an additive change from a breaking one by asking what existing code does with the new message, mark which pairing of old and new code fails, write the small adapter that lets the paused refund resume, and keep a new reason code from breaking a program that never touches money.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- What an existing reader does
- The paused refund
- A dual-read adapter
- A reason nobody expected
- Naming the version
- Common mistakes
- In production
- Sources
- Check yourself, 13 questions