# API versioning and backward compatibility

> Most API changes can be made without a new version if you only add. Learn which changes break clients, how to version when you must, and how to deprecate.

Published 2026-11-20 · Language: en · Tags: architecture, api

Once other people depend on your API, every change is a negotiation with code you cannot see. The best versioning strategy is to need versions rarely.

 

## Changes that are safe

 

Adding is usually safe if clients ignore what they do not know:

 

- A new optional field in a response.
- A new endpoint.
- A new optional request parameter with a sensible default.

 

This works only if clients are written to **tolerate unknown fields**. State that rule in the documentation.

 

## Changes that break clients

 

- Removing or renaming a field or endpoint.
- Changing a field's type or meaning, such as seconds becoming milliseconds.
- Making an optional parameter required.
- Tightening validation so formerly accepted input now fails.
- Changing error formats or status codes that clients handle.

 

## Where to put the version

 

- **In the URL**: `/v2/orders`. Obvious, easy to route and to cache. The most common choice.
- **In a header**: `Accept: application/vnd.example.v2+json`. Keeps URLs clean but is less visible and harder to try in a browser.
- **Date-based versions**: a client pins the API behaviour as of a date, and the server keeps compatibility shims. Powerful, but needs discipline.

 

```json
{
  "id": 42,
  "total": 1999,
  "currency": "USD",
  "total_formatted": "19.99"
}
```

 

Adding `total_formatted` next to `total` is compatible. Replacing `total` with a string would be a new version.

 

## Deprecation process

 

1. Announce the change with a date, in docs and by email to registered developers.
2. Mark old endpoints with a `Deprecation` or `Sunset` header so tools can detect them.
3. Measure who still calls the old version, and contact them.
4. Remove only after the announced date, and only when usage is negligible.

 

## Internal APIs

 

Services you control can use expand and contract: add the new field, migrate every consumer, then remove the old field. No version number needed if you coordinate.

 

## Takeaway

 

Prefer additive changes, document the tolerance rule, and when a break is unavoidable give clients a long, visible and measured migration path.

Source: https://tdphat.io.vn/blog/api-versioning-and-backward-compatibility
