What you'll learn: By the end of this lesson you will be able to sort an API change into compatible or breaking from the client's side, compare the common ways an API names its versions (path, header, date, no version at all), read the
DeprecationandSunsetresponse headers and act on them, plan a migration with expand, migrate and contract, and design the client so that a retired version produces an alert before it produces an outage.
A restaurant prints a new menu. Regulars order by habit: dish number 14. If the kitchen quietly renumbers the dishes, the regulars get the wrong food. A good restaurant keeps old numbers working for a while, puts a note on the table, and removes a dish only after nobody asks for it. An API and its clients are in the same position, with one extra difficulty: some customers are still reading a menu printed last week.
API Contracts and Data Transformation showed how a client checks one response at the edge. This lesson is about time: the contract will change, and the client has to keep working while it does.
The core idea
The client does not choose when the server deploys. The server does not choose when the client updates. A user can keep a tab open for days, a cached bundle can outlive a release, and a mobile web view may run an older build. So at any moment several client builds talk to several server behaviours.
Three statements carry the lesson.
- Classify the change. A compatible change is one that clients written against the old contract keep working with. Everything else is breaking, and breaking changes need a plan.
- Move in three steps, not one. Add the new form beside the old (expand), move clients over (migrate), and remove the old form only when nothing uses it (contract). Martin Fowler's Parallel Change describes the same three phases for any interface.
- Make retirement visible. A deprecated thing still works. A sunset thing will stop. The client should learn about both from the response, and report it, long before the date.
A version names a contract. Deprecation says "stop using this". Sunset says "this will stop responding at about this time". A client that treats them as one will panic early or ignore both.
Which changes break a client
Two public sources draw the line in nearly the same place. GitHub's REST API documentation says breaking changes are released in a new API version (removing an operation, removing or renaming a parameter or response field, making an optional input required) and that additive changes, including new response fields and enum values, are available in all supported versions. Google's AIP-180 says removing or renaming a component is incompatible, an existing field's type must not change even if the new type is wire-compatible, and new required request fields must not be added. From the client's side:
| Change on the server | Compatible? | What it does to a tolerant client |
|---|---|---|
| New response field | Yes | Ignored. Nothing happens |
| New enum value | Yes by the server's rules | Can break a client that handles values with a closed switch |
| Field removed or renamed | No | The edge fails with a path, if it checks |
| Optional input becomes required | No | Requests start failing with a client error |
| Same field, different meaning | No, and the worst kind | Types and shapes still match, the numbers are wrong |
AIP-180 itself warns that user code may not handle new enum values gracefully. "Compatible" is a statement about the contract; the client still has to be written so that it holds.
Figure 1. Is this change safe for clients written against the old contract?
and remove nothing?"} B -->|"yes"| C{"Is it a new enum value?"} B -->|"no: remove, rename, retype,
require, or change meaning"| X["Breaking: plan expand,
migrate and contract"] C -->|"no"| OK["Compatible: ship it"] C -->|"yes"| D{"Do clients have a written
unknown-value policy?"} D -->|"yes"| OK D -->|"no"| X
How to read this: the left branch is the easy case. The enum branch shows why "additive" is not always safe: the answer depends on the clients, not only on the server.
Naming versions: four common styles
- In the path, such as
/v2/orders. Easy to see and to route, but a version is part of every URL, and a cache or link holds it. - In a request header. GitHub asks clients to send
X-GitHub-Api-Version, with version names based on the release date. Stripe lets a request override the account's default version with theStripe-Versionheader. The URL stays the same. - In a media type, chosen with the
Acceptheader. MDN describes this as server-driven content negotiation, and says theVaryheader is needed so a cache can reproduce the server's choice. A shared cache that ignoresVarycan hand one client another client's representation. - No version at all. GraphQL's documentation says it takes "a strong opinion on avoiding versioning" and offers the tools for the continuous evolution of a schema, because a client asks only for the fields it needs.
Semantic Versioning, a convention for software packages, raises the major version for incompatible API changes and the minor version for backward-compatible additions; it says nothing about the wire. Date-based names tell you when a contract was frozen, not how large the change was.
Illustration 1 (minimal example): the client pins, and says so. A client that names its version cannot be moved by a changed default. GitHub's documentation says requests without the version header use its default version, and that when a version's support window ends, unversioned requests fall back to the next oldest supported version. The minimal client habit is one line in the one function that builds requests:
// Sketch for illustration. It is not part of a tested lab.
const API_VERSION = "2026-03-10"; // an example name, chosen by the team
export function apiHeaders(): Headers {
const headers = new Headers({ Accept: "application/json" });
headers.set("X-GitHub-Api-Version", API_VERSION); // each provider names its own header
return headers;
}
Deprecation and Sunset: two signals
A deprecation announces that a thing should no longer be used. RFC 9745 defines a Deprecation response header whose value is a date, written as a Structured Field date such as @1688169599 (a Unix timestamp). The RFC says deprecation does not change any behaviour of the resource and calls the header a hint.
A sunset announces an end of service. RFC 8594 defines a Sunset header whose value is an HTTP date, for example Sat, 31 Dec 2018 23:59:59 GMT. It says a URI is likely to become unresponsive then, that clients should treat the timestamp as a hint, and not what the failure will look like: a client error, a redirect, or no answer. RFC 9745 adds that a Sunset time must not be earlier than the Deprecation time. Both RFCs define a link relation (deprecation, sunset) pointing to documentation, so a Link header can lead to the migration guide.
For the final state, MDN says a 410 Gone response means the resource is no longer available at the origin server and the condition is likely to be permanent, and that clients should not repeat the request. GitHub says requests naming a retired version get a 410.
Figure 2. What a response can tell the client, and where the client reports it
How to read this: the page's components never see headers. One wrapper reads the signals and sends them to monitoring, asynchronously, so a warning never slows a request.
The wrapper for Illustration 1's pin can read the signals too:
// Sketch for illustration. It is not part of a tested lab.
export type Retirement = { deprecated: boolean; deprecatedAt?: Date; sunsetAt?: Date };
export function readRetirement(headers: Headers): Retirement | null {
const dep = headers.get("Deprecation");
const sun = headers.get("Sunset");
if (dep === null && sun === null) return null;
const out: Retirement = { deprecated: dep !== null };
const m = dep?.match(/^@(-?\d+)$/); // Structured Field date: Unix seconds
if (m) out.deprecatedAt = new Date(Number(m[1]) * 1000);
const t = sun === null ? Number.NaN : Date.parse(sun); // HTTP-date
if (!Number.isNaN(t)) out.sunsetAt = new Date(t);
return out;
}
An odd header must never throw: the helper sits on the path of every request.
Expand, migrate, contract
For a breaking change the safe sequence has three steps and a deadline.
- Expand. The server serves the new form beside the old one. Nothing a client already does stops working.
- Migrate. Clients move to the new form, a few at a time. Fowler notes that this is often the longest phase when the clients are external.
- Contract. Once nothing uses the old form, it is removed. Fowler warns that skipping this step can leave you worse off than before, with two forms to maintain forever.
Figure 3. One breaking change over time
How to read this: the order matters more than the dates. "Old-form use is zero" is evidence, not a calendar entry, and client-side monitoring produces it.
A server sees requests, not front-end builds. If the client sends its own build id in a header (a name the team chooses), the server can see which builds still use the old form. Without it, "nobody uses this" is a guess.
Illustration 2 (realistic example): an order history page
A shop's account page lists past orders. Each order has an id, a status and a total. The server team wants total to become an object with amount_minor and currency, because the shop is adding a currency with no minor unit. The page, an order-detail drawer and a receipt component all read total, and many users keep the page open for hours.
With expand, migrate and contract:
- Expand. The server sends
total(the old number) andtotal_money(the new object). The client edge's schema is updated to accept both and to prefer the new one, so the domain type isMoneyeither way. - Migrate. The edge reports a count each time it had to fall back to the old
total. When no build in the last week does, migration is complete (the week is an illustrative choice). - Contract. The server stops sending
total. The edge's fallback is deleted in a later release, never in the same one.
The domain type never changed: the edge absorbed the wire change.
Illustration 3 (failure case): the silent redefinition. The riskier version of the same change keeps the field name and changes its meaning: total quietly becomes "total after discounts" where it used to be "before discounts". Every type still matches and every response still passes the check at the edge. The receipt shows a wrong number and nobody is told. Only a new name, a new field or a new version can carry a changed meaning safely; the edge cannot detect it, so the contract needs written promises and shared examples tested from both sides.
Choosing a strategy
| Strategy | Gains | Costs |
|---|---|---|
| Version in the path | Visible, easy to route | A new URL per version; links and caches hold old ones |
| Version in a header, pinned by the client | Same URL; the client chooses when to move | A header every request must send; Vary for caches if responses differ |
Media type with Accept |
Fine-grained negotiation | Harder to test; caches depend on Vary |
| Versionless evolution (additive only) | One contract; no migration for additive change | Removal needs a long deprecation; meaning must never change |
In practice: retiring an orders endpoint
This is a realistic scenario, not a case history. It is a composite built from common production patterns. It describes no specific company or product, and every number in it is an illustrative assumption.
The situation
The shop's platform team will retire version 1 of the orders API and serve only version 2. The account page, a support tool and a partner dashboard still call version 1. The platform team announces a retirement date three months away (an illustrative figure).
Starting architecture
Figure 4. Three clients, two contract versions, one retirement date
How to read this: all three arrows still end at the old version. The front-end team controls one client; the other two set their own dates, so the signal has to reach them early.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Migrate only the account page, tell nobody else | Least effort now | One team's work | The partner finds out when it breaks |
| Migrate all three behind the edge mapper | One domain model for all | A migration per client | Needs three teams to agree on dates |
The decision
| Field | Decision record |
|---|---|
| Context | Three clients on v1; one date announced; only one client is ours. |
| Decision | Migrate the account page through the edge mapper first. Add Deprecation and Sunset reading to the fetch wrapper in every client we own. Report build id and endpoint to monitoring. Tell the two other teams in writing. |
| Consequences, good | Retirement shows up in dashboards weeks before the date; the domain model is unchanged. |
| Consequences, bad | Three teams share one deadline; the edge keeps a fallback meanwhile. |
| Revisit when | The platform team moves the date, or a client cannot migrate in time. |
Rollout and verification
- Read the signals first. Ship the header reading before any migration, and confirm the counts of v1 use by build.
- Migrate behind a flag, and compare contract failures per path before and after.
- Test the retired state. Replay a
410against the client and check it shows a safe failure, not a blank page or a retry loop.
The 2 a.m. failure
A week after the retirement date, the support tool shows an empty order list for every agent. Nothing in the last release touched it. Its first request now returns a retired-version response, and the code treats any non-success as "no orders" and retries forever. Nobody owned the support tool's migration.
First three checks: (1) read the raw status and body of the failing request; (2) check whether the endpoint's Sunset date has passed; (3) check which clients still send the old version. Mitigation: ask the platform team for a short extension and ship the support tool's move to the new version. Follow-up: make the wrapper treat a retired-version response as its own failure kind with no retries, and alert on any client still on a deprecated version two weeks before the date.
The other side of this topic
The server team owns the promises: what is compatible, how long a version lives, which headers announce a change, and running two contracts during migration. The server view is in API Styles: REST, gRPC, GraphQL and WebSockets and System Design: API Design. A front end reads those promises as a list of dates and conditions it must watch.
Architect's notes
- Pin the version you tested. An unpinned client lets the provider's default decide when it changes.
- Read the signals in one place. A few lines in the fetch wrapper give weeks of warning.
- Never change a field's meaning under the same name. Add a new field or a new version.
- Contract is a step, not an intention. Put the removal of the old form in the plan, with the evidence that allows it.
Common mistakes
- Treating "additive" as always safe. A new enum value breaks a closed
switch. - Reading
Deprecationas "it has stopped working". The RFC says deprecation changes no behaviour. - Retrying a
410. The condition is likely permanent. - Skipping contract. Two forms live forever.
Key takeaways
- A compatible change is one old clients survive. Adding is usually compatible; removing, renaming, retyping, requiring and changing meaning are not.
- Versions can live in the path, a header, a media type or nowhere; each has a cost, and
Accept-based choices needVaryfor caches. Deprecationsays stop using this;Sunsetsays it will stop responding; both are hints, and a410is the end.- Expand, migrate and contract is the safe order, and the migrate step needs usage evidence from clients.
- A client that pins its version and reads retirement headers turns an outage into an alert.
Practice exercises
Exercise 1: Starter (30 min). Take one API you call. Find where its versions are named, whether your client pins one, and where it announces deprecation.
Exercise 2: Intermediate (2 hours). Write the header-reading function with tests for no headers, Deprecation only, Sunset only, both, and an unparseable Sunset.
Exercise 3: Advanced (half day). Pick a field to change on a real API. Write the three-step plan and say what evidence will tell you the migration is finished.
Related reading
In this course:
- API Contracts and Data Transformation, the edge that absorbs a compatible change.
- From OpenAPI to TypeScript Contract Types, where the contract's types come from and how drift is caught.
- API Integration Basics: Fetching, Headers and Failure, the call and its failure kinds.
- Client Retries and Backoff, why a retired version must not be retried.
- HTTP Caching, for
Varyand stored responses.
Official documentation
- Semantic Versioning 2.0.0, the meaning of major, minor and patch.
- RFC 9745: The Deprecation HTTP Response Header Field
- RFC 8594: The Sunset HTTP Header Field
- GitHub REST API: API versions, a worked example of header-based, date-named versions.
- Google AIP-180: Backwards compatibility, what is and is not compatible.
- Martin Fowler: Parallel Change, expand, migrate and contract.