SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
  • What is an API?
  • API Styles
  • Idempotency
  • Data Formats
  • REST, GraphQL, gRPC
  • Pagination, Filtering and Sorting
  • API Versioning
  • Error Handling and Status Codes
  • OpenAPI / Swagger
  • Bulk APIs and File Upload
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/APIs and Communication/API Design

API Versioning

Change an API without breaking the apps that already use it.

⏱ 12 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

API versioning is how you change an API without breaking the apps that already use it.

  • Once other people write code against your API, you cannot freely rename or remove things. That would break their apps.
  • A version (like v1 and v2) lets the old shape keep working while the new shape is introduced.
  • Many changes need no new version at all. Adding an optional field is safe. Removing or renaming one is not.

02Concept: What is it?

An API is a contract. Clients rely on the URLs, the field names, the types and the meaning of every response. When you control both sides (a web app and its own backend), you can change both together. But a mobile app stays on a user's phone for months, and a partner's code is not yours to edit. If you change the contract in place, those clients break the moment you deploy.

So the first question is always: is this change breaking?

ChangeBreaking?Why
Add an optional response fieldNoClients ignore fields they do not know.
Add a new endpointNoNobody calls it yet.
Remove or rename a fieldYesClients that read it now get nothing.
Change a field’s type or meaningYesOld code may crash or compute the wrong answer.
Make a request field requiredYesOld clients do not send it, so their calls fail.
Change an error code or statusOftenClients may branch on the old value.
Without and with versions
Change in place
πŸ“±Old app
πŸ–₯️New app
↓one API, changed
πŸ”ŒAPIold app breaks
Versioned
πŸ“±Old app
πŸ–₯️New app
↓/v1
↓/v2
πŸ”Œv1
πŸ”Œv2
With versions, old and new clients can live together. Without them, one change reaches everyone at once.
🧠Be liberal in what you accept
Good clients follow the tolerant reader rule: ignore fields you do not understand and do not rely on field order. This is what makes additive changes safe.

03Real-Life Example

🍡The Restaurant Menu
A restaurant prints a menu and regulars order by the dish name. If the chef quietly renames "Chicken Soup" to "Poultry Broth", the regulars' usual order stops working. A kinder chef adds new dishes to the menu and keeps the old names working for a while. When a dish must go, the menu says "this dish ends on 1 March", and the waiter reminds anyone who still orders it.
Restaurant
API
The printed menu
The API contract
Regulars who order by name
Clients that depend on field names
Adding a new dish
Adding an optional field (safe)
Renaming a dish
Renaming a field (breaking)
Keeping the old menu for a while
Keeping /v1 alive
A note: ends on 1 March
Deprecation and Sunset headers
Waiter reminds old orderers
Warning logs and emails to old clients
The life of a version
πŸš€Releasedv2 is live
→↓
πŸ“’Deprecatedv1 still works, warn users
→↓
⏳Sunset dateannounced in advance
→↓
πŸͺ¦Retiredv1 returns an error

04Why Do We Need It?

πŸ›‘οΈDo not break clients
Apps you do not control keep working while you improve the API.
πŸš€Freedom to improve
You can fix a bad design in a new version instead of living with it forever.
🀝Trust with partners
A clear promise about changes makes other teams comfortable building on you.
πŸ“…Time to migrate
Clients get a deadline and time to move, instead of a surprise.
πŸ§ͺSafer releases
You can ship new behaviour to new clients first and watch before moving everyone.
πŸ“œA clear history
Versions document what changed and when, which helps support and debugging.
Treat your API like a promise. Add freely, change carefully, and give people time before you take anything away.

05Where Do We Use It?

🌍Public APIs
Anyone can build on them, so breaking changes need a new version and a long notice period.
🀝Partner APIs
Other companies cannot update on your schedule.
πŸ“±Mobile backends
Old app versions stay in the wild for a long time.
🧩Microservices
Services call each other and deploy independently, so they need compatible contracts.
πŸ“¨Event schemas
Messages on a queue need versions too, because old consumers still read them.
πŸ—ƒοΈWebhooks
You send payloads to other people’s servers. Changing them in place can break those servers.

06Types / Parts / How It Works

Where to put the version

StrategyLooks likeGoodNot so good
URL pathGET /v2/ordersObvious, easy to test in a browser, easy to routeThe URL of a thing changes between versions
HeaderAccept-Version: 2URLs stay the sameHidden from view, harder to test and cache
Media typeAccept: application/vnd.shop.v2+jsonFits the idea of one resource, many representationsMost complex for clients
Query parameterGET /orders?version=2Simple to addEasy to forget, and it clutters caching
No version (additive only)GET /ordersNothing to manageYou can never remove or change anything

Announcing a retirement

Response headers on an old version (example)
HTTP/1.1 200 OK
Deprecation: true
Sunset: Wed, 01 Jul 2026 00:00:00 GMT
Link: <https://api.example.com/docs/migrate-v2>; rel="deprecation"

The Deprecation and Sunset headers tell clients, in a way that tools can read, that a version is on its way out and when it will stop. Pair them with docs, emails and logs of who still calls the old version.

Other ways to avoid a new version

  • Expand and contract: add the new field next to the old one, move clients across, then remove the old one in a later version.
  • Feature negotiation: clients ask for the fields they want, so new fields never surprise them.
  • Default values and optional fields: new request fields are optional, with a sensible default.
VisualizerPick a change and a strategy: who breaks?Start with a rename and no versioning, and watch the old clients break. Then switch to URL versions. Try an optional new field, which is safe in every case. Change how many versions you keep alive.
1. What change do you want to make?

⚠️ Breaking change. Old clients still read name, which is now missing.

2. How do you version the API?

One API. Every client gets the change at once.

3. How many versions do you keep alive?
What happens to each client after the release?
πŸ“±Old mobile app
Built for v1. Cannot be updated for weeks (app store review).
❌ Breaks
The old shape was changed in place, so this client breaks.
🀝Partner integration
Built for v1. Another company's code. You cannot change it.
❌ Breaks
The old shape was changed in place, so this client breaks.
πŸ–₯️New web app
Built for v2. Updated with every release.
βœ… Works
Built for the new shape. Works.
Changing the API in place broke 2 clients the moment you deployed. You cannot force a partner or an old app to update that fast.
Clients broken
2
of 3
Versions to run
1
live at once
Extra upkeep
+0%
illustrative

A simplified model with three fixed clients and no random numbers. The upkeep figure is illustrative: it only shows that every live version adds testing, documentation and security work. Real costs depend on your team.

07How to Use It / Steps / Implementation

Changing an API safely

  1. 1
    Classify the change
    Is it additive (safe) or breaking? When unsure, treat it as breaking.
  2. 2
    Prefer additive changes
    Add optional fields, new endpoints and new enum values (only if clients are told to expect unknown ones).
  3. 3
    Choose a version style once
    Pick path, header or media type for the whole company and stay consistent. The URL path is the most common and the easiest to explain.
  4. 4
    Use big versions only for big breaks
    Use v1, v2 for breaking changes. Do not make a new version for every small tweak.
  5. 5
    Write a deprecation policy
    For example: a version stays supported at least 12 months after the next one is released. Put it in the docs.
  6. 6
    Warn early and measure
    Send Deprecation and Sunset headers, and log which clients still call the old version, so you can contact them.
  7. 7
    Retire for real
    After the date, return a clear error, then delete the old code. Old versions you never remove become a security risk.
πŸ’‘Few versions beat many
Every live version needs tests, docs, monitoring and security fixes. Keep the number of supported versions small (often two) and give a clear migration path.
⚠️Versioning the data is harder than versioning the URL
If v1 and v2 share one database, a schema change must work for both. Use expand-and-contract steps, so old and new code can read and write the same data at once.

08Key Terms to Know

TermMeaning in easy words
API contractThe promise about URLs, fields, types and behaviour that clients depend on
Breaking changeA change that can make existing clients fail
Non-breaking (additive) changeA change old clients can safely ignore, such as a new optional field
Backward compatibleNew server, old client: it still works
Tolerant readerA client that ignores fields it does not understand
DeprecationMarking something as old, with a plan to remove it
SunsetThe date when a deprecated version will stop working
Version pinningA client choosing one version and staying on it
Media type versioningPutting the version inside the Accept header (content negotiation)
Expand and contractAdd the new thing, move users across, then remove the old thing
Migration guideA document that shows clients how to move to the new version

09Pros, Cons and Trade-offs

βœ… Pros
  • Old clients keep working
  • You can fix past design mistakes
  • Clear promises build trust
  • Clients get time to migrate
  • Easy to test side by side
⚠️ Cons
  • Every live version costs upkeep
  • Two code paths can drift apart
  • Old versions may linger for years
  • Shared data models are hard to keep compatible
  • Clients must learn and follow the policy

Trade-offs

ChoiceWe gainWe lose
Version in the URLObvious and simpleResource URLs change between versions
Version in a headerClean URLsHarder to see, test and cache
Additive-only policyNo versions to manageCannot ever remove or reshape things
Many live versionsHappy old clientsA heavy burden of tests and fixes
Short support windowLess upkeepClients feel pushed, partners may complain
Long support windowCalm clientsOld, possibly insecure code stays alive

10Common Problems and Mistakes

Common mistakes

  1. Changing the API in place. Renaming a field "because it is cleaner" breaks every client that read the old name.
  2. A new version for every tiny change. You end up with v14 and nobody knows which to use.
  3. Never retiring old versions. They grow old and insecure, and they slow the whole team down.
  4. No deprecation notice. Clients find out when their app stops working.
  5. Not knowing who calls the old version. Without logs and API keys you cannot contact the people you are about to break.
  6. Clients that crash on unknown fields. Strict parsing turns safe additions into outages.
  7. Forgetting events and webhooks. Message formats need versions as well.

Things to watch

πŸ§“Zombie versions
Old versions nobody owns still run in production. Give each version an owner and an end date.
πŸ”€Drift
Bug fixes land in v2 but not v1. Decide which fixes you back-port.
πŸ”ŒShared database
Both versions read the same tables, so schema changes must be compatible with both.
πŸ“ŠUsage tracking
Count requests per version and per client. This tells you when a retirement is safe.

11Real-World Examples

πŸ’³Payment APIs
Some pin each account to an API version, so an account only sees changes when it chooses to upgrade.
☁️Cloud providers
Many keep long-lived versioned APIs and announce retirements far in advance.
πŸ“±Mobile apps
Backends often keep old endpoints alive until the share of old app versions is tiny.
🧰Developer platforms
Public APIs often use a version in the URL path, which is the style most developers know.
🧬gRPC and Protobuf
Adding new fields is safe by design, and field numbers must never be reused.
πŸ“¨Event streams
Schema registries check that a new event schema stays compatible with older readers.
πŸ“Note
Practices differ from company to company. Check the documentation of any API you depend on, and look for its deprecation policy.
Mini case: renaming a field safely
βž•Add full_namekeep name too
→↓
🚚Move clientswarn and measure
→↓
βž–Remove namein the next version
Safe Wait Breaking, so a new version
Add, migrate, then remove. No client ever sees a break.

12Related Topics to Read Next

What is an API?β†’

The contract that versioning protects.

REST, GraphQL, gRPC→

Each style has its own way to evolve without breaking.

Data Formats→

Some formats (like Protobuf) make safe additions easier.

Schema Migrations→

Database changes must stay compatible with old and new code.

Rolling Deployments→

During a rollout, two code versions run at the same time.

Error Handling and Status Codes→

How to tell clients a version is gone.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”What: a way to change an API without breaking clients that already use it.
  • βœ”Safe: adding optional fields and new endpoints.
  • βœ”Breaking: removing, renaming or retyping fields, or new required inputs.
  • βœ”Styles: URL path (most common), header, media type, query parameter.
  • βœ”Retire: announce a policy, send Deprecation and Sunset headers, measure usage, then switch off.
  • βœ”Clients: be tolerant readers. Ignore unknown fields.
  • βœ”Keep few versions: each one costs tests, docs and security fixes.
  • βœ”One line: β€œAdd freely, break rarely, and never surprise anyone.”
← Previous
Pagination, Filtering and Sorting
Next β†’
Error Handling and Status Codes