Foundations · L2API versioning and deprecation

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.

L2 SeniorFoundations19 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 9 Nov 2026 · How we check content
Section 1 of 8

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.

Section 2 of 8

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:

  1. Additive change first. Add new fields and endpoints next to the old ones. Nothing breaks.
  2. Versions when you must break something. Old clients keep the old contract.
  3. 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.

Section 3 of 8

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 refunded to a status field. 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 old switch with 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-version on every call, as a date like 2021-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 get 2022-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-Version header. 1 Since 2024-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.

One codebase, many versions: build the newest response, then undo each change back to the client's versionOld client API pinned to 2024-01-15GET /customers/42 newest shape (2025-03-01)status: "verified", emails: [ … ] undo 2025-03-01: emails → emailstatus: "verified", email: "a@x.in" undo 2024-06-01: status → verifiedverified: true, email: "a@x.in" ✓ old client sees the 2024 shapeA client on 2025-03-01 skips both steps.Old rules live in two small modules,not in if-statements all over the code. SeniorPath
  1. 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.
  2. The API code only knows one shape: the newest. It builds the response the way a client on 2025-03-01 would see it.
  3. 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.
  4. 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.
  5. 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.
Step 1 of 5

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.

Section 4 of 8

Trade-offs

SchemeEasy to see and route?Cost for clientsCost for youUse 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 datePartly. You must read the parameter or header.Low. Small steps.Medium. One version per release.Public APIs that change often.
Pinned account plus translation layerNo It is hidden in account settings.Lowest. Old code keeps working. 1High. Every module must be maintained. 1Long-lived integrations, like payments.
Versionless (GraphQL)No version to route.Low, until a field is removed.Low, if you only add. 8Clients pick their own fields.

Simple rule: try an additive change first. Version only when you must break something.

Section 5 of 8

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 Deprecation and Sunset headers, 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.
Section 6 of 8

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.
  • Deprecation uses the @ timestamp format, and Sunset uses an HTTP date. 12 11
  • Version strings are full ISO dates like 2024-06-01 (not 2024-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.
Section 7 of 8

Check yourself

1. Your response has status with values pending and paid. You add a third value, refunded. Is that safe?

Show answer

Not always. Old client code may not handle a value it has never seen. Google's AIP-180 warns that user code may not handle new enum values gracefully, and GitHub's GraphQL docs call a new enum value a "dangerous" change.

2. You change the default page size of a list endpoint from 50 to 20. No field changed. Is this a breaking change?

Show answer

Yes. Clients that relied on the old default now get different results. AIP-180 says changing a default value is breaking and must not be done. Clients that send their own value are not affected.

3. In Stripe's 2017 design, how does an old client get the old response shape?

Show answer

Stripe builds the newest shape, then applies version change modules backwards until it reaches the client's version. The Stripe post describes building the response for the current version, then walking back through each version change module.

4. A response has Deprecation: @1798761599 (31 December 2026) and Sunset: Tue, 30 Jun 2026 23:59:59 GMT. What is wrong?

Show answer

The Sunset date is earlier than the Deprecation date, which RFC 9745 does not allow. RFC 9745 says the Sunset date must not be earlier than the Deprecation date. RFC 9745 uses an @ timestamp, and RFC 8594 uses an HTTP date.

5. Which fact best tells you an old version is safe to switch off?

Show answer

Your request logs show almost no traffic on it, and you have contacted the clients that remain. Announcements and age do not prove anyone moved. Measured traffic per client does.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 12 sources and related lessons
  1. 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.
  2. 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.
  3. 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.
  4. Google, AIP-180: Backwards compatibility (opens in a new tab)
    Source, wire and semantic compatibility, with rules on enums, defaults and stricter formats.
  5. Hyrum Wright, “Hyrum's Law” (hyrumslaw.com) (opens in a new tab)
    Why users depend on behaviour you never promised.
  6. 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.
  7. 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.
  8. GraphQL Foundation, “Schema Design” (graphql.org) (opens in a new tab)
    Why GraphQL APIs usually evolve without versions.
  9. 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.
  10. 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.
  11. 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.
  12. 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)

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper