API versioning and deprecation
What really breaks a client, how to change an API without breaking it, and how to retire an old version on purpose.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
Stripe's API moves money for many businesses. Once a business connects its code, it expects that code to keep working for years. A Stripe engineer compared the API to a power grid or water supply: after you hook it up, it should run without interruption. 1
In a 2017 post, Stripe gave an example of a change that would break that promise. A bank account had a true/false field called verified. Suppose Stripe replaced it with a text field called status. Every client that read verified would break, "because it depends on a field that no longer exists." 1
Stripe still needed to make changes like that. By 2017 it had made "almost a hundred backwards-incompatible upgrades" in six years. It also said it had kept compatibility with every version since the company started in 2011. 1
How do you change an API a hundred times and still not break code written years ago? That is what this lesson is about. Stripe's answer used dated versions and a translation layer. You will see both, plus the cheaper habit that should come first.
The idea in simple words
A breaking change is any change that makes a working client fail or behave wrongly. REST API design covered the obvious ones: removing, renaming or retyping a field.
The surprising ones are changes in behaviour. Hyrum Wright put it this way: with enough users, "all observable behaviors of your system will be depended on by somebody." 5 That is Hyrum's law. Your docs do not decide what is breaking. Your users' code does.
So you have three tools, in this order:
- Additive change first. Add new fields and endpoints next to the old ones. Nothing breaks.
- Versions when you must break something. Old clients keep the old contract.
- Deprecation and sunset to retire an old version on purpose, with dates and data.
The key idea. A version is a promise you have to keep running. Add instead of change, version only when you must, and switch an old version off only when your logs show nobody is left.
How it works
The surprising breaking changes
Google's AIP-180 names three kinds of compatibility. Old code must still compile, still talk to the server, and still get "what most reasonable developers would expect." 4 The third kind hides most surprises.
- New enum values. You add
refundedto astatusfield. AIP-180 warns that user code may not handle new values gracefully. 4 GitHub's GraphQL docs call this a "dangerous" change: queries still work, but clients may behave differently. 7 An oldswitchwith no default case may crash or do nothing. - Tighter validation. AIP-180 gives an example: if name formats become stricter, a request that used to succeed now fails. 4
- Changed defaults. A client that never sent a page size silently gets a different result. AIP-180 says changing a default value is breaking and must not be done. 4
- New required inputs. New required fields must not be added to existing requests. 4
- New error codes. Microsoft's guidelines say not to add new top-level error codes without a new version. 10
Rules differ between companies. GitHub's REST docs list adding an enum value as additive, and removing one as breaking. 6 Microsoft says a new enum value can be handled with an extensible enum, and removing a value breaks customer code. 10 Our advice: tell clients in your docs to expect new values and to handle unknown ones.
Additive change first
Most changes do not need a version. Stripe says it is safe to add a new endpoint, or a new field that was never there before. 1 To "rename" a field, add the new one and keep sending the old one. This is expand and contract at the API level.
Additive change only works if clients ignore fields they do not know. Say this in your docs, and test it in your own SDKs.
Versioning schemes
When you must break something, you need a way for each client to ask for the old contract.
- URL path, like
/v2/orders. Easy to see and to route in an API gateway. But each new major version forces every client to move. - Query parameter. Azure requires
api-versionon every call, as a date like2021-06-04. It returns 400 if the value is missing or unknown. It also says not to put a version in the path. 10 - Header with a date. GitHub's REST API reads
X-GitHub-Api-Version. Without it, you get2022-11-28. Old versions are supported for 24 months after a newer one ships. 6 - Dated version pinned to the account. In its 2017 design, Stripe pinned an account to the newest version on its first request. A client could override it per call with the
Stripe-Versionheader. 1 Since2024-09-30.acacia, monthly versions have no breaking changes. Breaking changes come in two major releases a year. 2 - No versions (GraphQL). A GraphQL server returns only the fields a query asks for, so adding fields breaks nobody. That is why GraphQL APIs are usually versionless. 8 You mark old fields with the built-in
@deprecated(reason: ...)directive. 9 GitHub announces GraphQL breaking changes at least three months ahead, and makes them only at the start of a quarter. 7
The translation layer
Many versions can mean many copies of the code. Stripe avoided that. Each breaking change lives in one small version change module: docs, a transformation, and the resource types it touches. 1
The core code builds every response in the newest shape. Then the layer walks back through the modules, newest first, until it reaches the client's version. 1 Step through it. Use Next and Back, or the ← and → keys.
- An old client calls the API. Its account was pinned to version 2024-01-15 on its first request, so every call is served in that version.
- The API code only knows one shape: the newest. It builds the response the way a client on 2025-03-01 would see it.
- A translation layer walks back in time. The 2025-03-01 change turned one email into a list, so this step turns the list back into one email.
- The 2024-06-01 change replaced the verified true/false field with a status text. This step turns the status back into true or false.
- The old client gets exactly the shape it was written for. A newer client skips the steps it does not need. Each old rule lives in one place.
A tiny version of the idea:
// Newest first. Each module knows how to undo its own change.
const changes = [
{ version: "2025-03-01", undo: (c: any) => { c.email = c.emails[0] ?? null; delete c.emails; } },
{ version: "2024-06-01", undo: (c: any) => { c.verified = c.status === "verified"; delete c.status; } },
];
export function render(body: any, clientVersion: string) {
for (const ch of changes) {
if (ch.version > clientVersion) ch.undo(body); // ISO dates sort as strings
}
return body;
}Changes that do more than reshape a response are harder. Stripe marks such a module has_side_effects. Its transformation then does nothing, and other code checks whether the change is active for this request. Stripe tries to avoid them. 1 Every version is "more code to understand and maintain." 1
Do not forget webhooks. Stripe renders webhook events in the endpoint's version, or the account default. 2 To upgrade, you create a second endpoint on the new version and move over. 3
Deprecation and sunset
Two response headers tell clients what is coming.
Deprecation: @1767225599
Sunset: Thu, 31 Dec 2026 23:59:59 GMT
Link: <https://api.example.com/docs/v1-retirement>; rel="deprecation"Deprecation comes from RFC 9745. Its value is a Unix timestamp after @. A past date means "already deprecated", a future date means "will be". A rel="deprecation" link points to human docs. 12
Sunset comes from RFC 8594. It says when the resource will likely stop responding. It is a hint, not a promise. 11 The Sunset date must not be earlier than the Deprecation date. 12
When the day comes, answer with a clear error. GitHub returns 410 Gone for a version it no longer supports. 6
Measure, then communicate
Headers only help if someone reads them. So log the version and the client id on every request. Then you can answer: "Who still calls v1, how often, and on which endpoints?" Stripe shows each customer the versions its own integration uses. 3
Our advice: email the owners of the remaining clients by name, not only a mailing list. Before the final date, consider short planned failures in quiet hours. A client that ignored every email will notice those.
Trade-offs
| Scheme | Easy to see and route? | Cost for clients | Cost for you | Use it when |
|---|---|---|---|---|
URL path (/v2/) | Yes | High. Each major version is a big move. | Medium. Two code paths. | Rare, large redesigns. |
| Query or header with a date | Partly. You must read the parameter or header. | Low. Small steps. | Medium. One version per release. | Public APIs that change often. |
| Pinned account plus translation layer | No It is hidden in account settings. | Lowest. Old code keeps working. 1 | High. Every module must be maintained. 1 | Long-lived integrations, like payments. |
| Versionless (GraphQL) | No version to route. | Low, until a field is removed. | Low, if you only add. 8 | Clients pick their own fields. |
Simple rule: try an additive change first. Version only when you must break something.
At work: how a senior uses this
- In every API review, ask: "Could any client see a different result after this change?" That includes defaults, validation, error codes and enum values.
- Treat new enum values as a change to announce. Tell clients up front to handle unknown values.
- Before you deprecate, ask: "Who calls this today?" Answer with request logs grouped by client and version, not guesses.
- Put a date on every deprecation. Send
DeprecationandSunsetheaders, with a link to a migration guide. - Write the support window into your public docs, the way GitHub states 24 months. 6
- Keep old-version rules in one layer. If version checks spread into business code, stop and refactor.
- Add a contract test for each supported version, so nobody breaks an old shape by accident.
With AI
What to ask the agent
"Compare this OpenAPI file with the one on main. List every change an existing client could notice, including new enum values, changed defaults, stricter validation and new error codes. Mark each one breaking, dangerous or safe."
"Write middleware that reads an API version header, logs it with the client id, and adds Deprecation and Sunset headers for versions older than 2025-01-01."
"Turn this breaking change into a version change module with a function that converts the new response shape back to the old one. Add a test for both versions."
What to check yourself
- The agent did not call a new enum value or a changed default "non-breaking" just because the schema shape stayed the same.
Deprecationuses the@timestamp format, andSunsetuses an HTTP date. 12 11- Version strings are full ISO dates like
2024-06-01(not2024-6-1), so comparing them as strings sorts them correctly. - Every translation step has a test with a real old response as the expected output.
- Webhook payloads follow the same version rules as API responses.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 12 sources and related lessons
- Brandur Leach, “APIs as infrastructure: future-proofing Stripe with versioning”, Stripe blog (5 August 2017) (opens in a new tab)
Dated versions, pinning an account on its first request, and version change modules that turn new responses into old ones. - Stripe API reference: Versioning (opens in a new tab)
Monthly releases with no breaking changes, two major releases a year, and the Stripe-Version header. - Stripe documentation: Upgrade your integration (opens in a new tab)
How a client moves to a new version, sees which versions it uses, and moves webhook endpoints safely. - Google, AIP-180: Backwards compatibility (opens in a new tab)
Source, wire and semantic compatibility, with rules on enums, defaults and stricter formats. - Hyrum Wright, “Hyrum's Law” (hyrumslaw.com) (opens in a new tab)
Why users depend on behaviour you never promised. - GitHub Docs: API Versions (opens in a new tab)
A date-based version header, a 24-month support window, and a list of breaking and additive changes. - GitHub Docs: Breaking changes (GraphQL API) (opens in a new tab)
How a versionless GraphQL API announces breaking changes three months ahead, and what counts as dangerous. - GraphQL Foundation, “Schema Design” (graphql.org) (opens in a new tab)
Why GraphQL APIs usually evolve without versions. - GraphQL Specification, October 2021 edition, section 3.13.3 “@deprecated” (opens in a new tab)
The built-in directive that marks a field or enum value as deprecated, with a reason. - Microsoft, Azure REST API Guidelines (GitHub, microsoft/api-guidelines) (opens in a new tab)
A required api-version query parameter with a date, no version in the path, and extensible enums. - E. Wilde, RFC 8594: The Sunset HTTP Header Field (IETF, May 2019) (opens in a new tab)
A response header that says when a resource is likely to stop responding. - S. Dalal and E. Wilde, RFC 9745: The Deprecation HTTP Response Header Field (IETF, March 2025) (opens in a new tab)
A response header that says a resource is or will be deprecated, and how it works with Sunset.
Related: REST API design · Schema evolution and encoding · API gateways and edge concerns · Webhooks and async APIs · Schema migrations without downtime · Contract and integration tests for services (coming soon) · GraphQL and backend-for-frontend (coming soon)
- REST API design: the basic breaking changes and why old mobile apps matter.
- Schema migrations: expand and contract, one layer down in the database.
- API gateway: routing
/v1and/v2at the edge. - Webhooks and async APIs: events your API pushes, which need versions too.
- Schema evolution and encoding: how JSON, Protobuf and Avro let old and new code read each other's data.
- Coming later: contract and integration tests.