Change an API without breaking clients
Mobile apps in the wild call an old shape for years.
Say it like this
Mobile clients live for years, so I make every change additive, version the API only for incompatible changes, and keep old versions behind the gateway with a published sunset date.
Basic solution
Only add fields; version the path or header when you must remove or change semantics; keep old versions for a sunset period.
Two versions, one core
The gateway routes by path to thin per-version adapters that both call the same domain logic and tables. v1 responses carry Sunset headers until its traffic reaches zero and it returns 410.
How it works
- Classify each change before shipping it. Adding an optional field or a new endpoint is compatible, because an old client that does not know about it keeps working; ship it with no version bump. Removing a field, changing a type, or changing what a field means is incompatible, because an old client would misread the response; that needs a new version.
- For compatible changes, keep every response a superset of what it was. Old clients ignore fields they do not recognise and new clients read the new ones. Never make a previously optional field required, because old clients do not send it and their requests would start failing.
- For incompatible changes, introduce v2 alongside v1 rather than replacing it: either a new path prefix (/v2/urls) or a header (Accept-Version: 2). The gateway reads the path or header and routes each request to the matching handler; both handlers read and write the same data model underneath.
- Announce the deprecation of v1 with a date. Return a Deprecation header and a Sunset header (the date v1 stops working) on every v1 response, and watch v1 traffic broken down by client so you know who still depends on it.
- On the sunset date, make v1 return 410 Gone with a message pointing to v2, then delete the v1 handler.
What makes this manageable
- You version the contract, not the service: one codebase serves both versions by translating at the edge of the handler, instead of forking the whole application into two deployments.
Worked example
URL shortener public API
- 2,000 API customers; the median customer updates their integration every 18 months. Any breaking change strands real traffic for at least that long.
- v1 returned clicks as an integer; the business wants clicks broken down by day. Adding "byDay" as a new field is compatible: v1 clients keep reading "clicks", newer ones read both. No version bump.
- Later the team wants to rename "longUrl" to "target" and make aliases case-insensitive, which changes semantics. That is v2.
- Traffic during the overlap: 40 creates/s total, 35 on v1 and 5 on v2 in month one; by month twelve it is 8 on v1. The gateway routes by path, and both handlers write the same table, so there is no data migration.
- Sunset: announced 12 months ahead with Sunset headers; the final 8 requests/s come from 30 customers who get a direct email; v1 returns 410 at month 14. Cost of the overlap: one translation layer of about 200 lines, kept for 14 months.
Variants and when each wins
Path versioning (/v1, /v2)
- The version number is the first segment of every URL. It wins for visibility, caching and routing, because the version is in every log line and the gateway can route on it without reading headers; the cost is that the whole API surface gets a new version even when one endpoint changed.
Header versioning (Accept-Version or media type)
- The URL stays stable and the client names the version in a request header. It wins when you want clean URLs and per-endpoint granularity; the costs are that a browser cannot test it by typing a URL, and caches must be told to key on that header (Vary) or they will serve one version's response to the other.
Date-based versions (2026-10-01)
- A client pins the date it was written against, and the server applies every change made after that date as a transformation on the way out. It wins when you ship many small changes to many clients, as Stripe does; the server carries a chain of adapters that grows over time.
No explicit versions, additive only
- Fields are added and never changed, and deprecated fields keep working indefinitely, in the style of Protobuf and GraphQL. It wins while semantics never change; it stops working the day a field has to mean something different.
Recommendation: additive by default, path versions for the rare incompatible change, and Sunset headers plus client-version metrics to retire old versions on a schedule.
Failure modes
Accidental breaking change
- A subset of mobile users crash immediately after a server deploy. A field was made required, renamed or retyped as part of an unrelated change, with no new version, so old app builds send or parse the old shape. Add contract tests in CI that diff the OpenAPI or .proto schema against the last release and fail the build on any incompatible edit.
Versions that never die
- Five versions are live in production, each with its own bugs and its own support burden. Nobody set a sunset policy, so every version stayed until someone complained. Allow at most two live versions, publish a support window, and keep a dashboard of traffic per version per client so the decision to retire one is based on numbers.
Version in the URL but not in the cache key
- A v2 client receives a response shaped for v1. The version is sent in a header, and a cache in the path ignored that header because the response did not say Vary on it, so it reused the v1 body for the same URL. Include the version in the cache key by adding a Vary header, or switch to path versioning where the URL itself differs.
Forking the service per version
- Every bug fix has to be applied twice and tested twice. v1 and v2 were built as separate deployments with duplicated business logic. Run one service with one domain model and keep each version as a thin adapter at the handler boundary, so a fix in the core applies to both.
Clients that cannot update
- One client is pinned to the old version forever, because it is a hardware device or an embedded integration with no update path. Agree a much longer support window for that client class before shipping to it, or serve it a frozen snapshot of the old API behind a dedicated hostname so the main API can move on.
Interviewer follow-ups
Answer out loud before you open each one.
Is adding a new required request field a breaking change?
Yes. Old clients do not send it, so their previously valid requests start failing. Add it as optional with a server-side default, or introduce it only in a new version. The same applies to tightening validation on an existing field.
How do you know when it is safe to turn off v1?
Measure requests per client identifier per version. Announce a date, add Sunset headers, contact the remaining callers directly, and switch when the residual traffic is from clients you have reached or that are abandoned. Returning 410 with a clear message is better than silently serving stale behaviour.
How does versioning differ for internal gRPC services?
Internally you control both sides and deploy often, so additive Protobuf evolution covers almost everything: add fields, never renumber. For real semantic changes, add a new RPC method and migrate callers service by service, then delete the old method. Path-style versions are rarely needed inside.
What is the cost of keeping two versions live?
Translation code at the handler boundary, double the contract tests, and the operational risk that a fix lands in one version only. Keep the adapters thin, test both versions against the same core, and set a sunset date before v2 ships so the overlap has an end.
Connections
The same parts on other clouds
The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.
| AWS | Used here as | Google Cloud | Microsoft Azure | Open source and others |
|---|---|---|---|---|
| Amazon API Gateway | API gateway | API Gateway, Apigee | API Management | Kong, Tyk |
| Amazon EC2 Auto Scaling | v1 adapter, v2 adapter | Compute Engine managed instance groups | Virtual Machine Scale Sets | Kubernetes Deployment with a HorizontalPodAutoscaler, Nomad |