Every backend engineer has witnessed the debate: Should API versions live in the URL path (/api/v1/resource), a custom request header (X-API-Version: 1), or a query parameter (?version=1)?
While engineering teams argue over syntax, clients in production break because no one clearly defined what a "breaking change" actually meant.
The root problem isn't the routing mechanism. Most teams version too early, version too often, and lack an exit plan for old code.
Here is how to design and manage API versions without disrupting downstream clients.
Define What "Breaking" Really Means
A breaking change is any modification that forces an existing client to change its code or fail at runtime.
Before bumping a version number, evaluate the change against these criteria:
Non-breaking (Additive) changes:
- Adding a new endpoint.
- Adding a new optional request field.
- Adding a new property to a response payload.
Breaking (Subtractive or Altering) changes:
- Renaming or removing an existing field.
- Changing a field's data type (e.g., changing
idfrom an integer to a UUID string). - Adding a required request parameter or body payload field.
- Modifying existing error codes or response structure logic.
If a change is additive, you do not need a new API version.
Design for Additive Growth
The cleanest way to avoid versioning fatigue is to adopt an additive model. Keep the old field intact, and expose the new field alongside it.
Consider a user API that originally returned a full name as a single string, but now needs separate first and last names. Instead of removing name, retain it while adding first_name and last_name:
// GET /api/users/123
// Old Response Payload
{
"id": 123,
"name": "Jane Doe"
}
// Evolving Response Payload (Non-breaking)
{
"id": 123,
"name": "Jane Doe",
"first_name": "Jane",
"last_name": "Doe"
}
Existing frontend apps or integrations reading response.name will continue to work seamlessly. New integrations can start using first_name and last_name. No version bump required.
Use Standard Deprecation Headers
When a breaking change is unavoidable, you must provide a clear exit strategy for consumers before taking an endpoint offline.
Rather than relying on manual emails that get missed, communicate deprecation programmatically via standard HTTP response headers like Deprecation and Sunset (RFC 8594).
Here is an example using Python and FastAPI middleware to mark a legacy endpoint as deprecated:
from fastapi import FastAPI, Request, Response
app = FastAPI()
@app.middleware("http")
async def add_deprecation_headers(request: Request, call_next):
response: Response = await call_next(request)
# Intercept requests heading to legacy endpoints
if request.url.path.startswith("/api/v1/users"):
response.headers["Deprecation"] = "true"
response.headers["Sunset"] = "Sun, 31 Dec 2025 23:59:59 GMT"
response.headers["Link"] = '<https://api.example.com/docs/v2-migration>; rel="deprecation"'
return response
By sending an explicit Sunset timestamp and linking to a migration guide, consumer systems can log these deprecation warnings automatically and schedule migration work ahead of time.
Pick One Strategy and Stay Consistent
Whether you select URI path versioning (/v1/) or Header-based versioning (Accept: application/vnd.company.v1+json), consistency across all services is what prevents developer confusion.
-
URL Versioning (
/api/v1/): Easiest to debug, inspect, and test via browser or basic HTTP tools. -
Header Versioning (
Accept/X-API-Version): Keeps URLs clean, but requires tooling that supports custom headers during manual testing.
Select the pattern that best aligns with your team's existing infrastructure, document it, and enforce it globally. The routing strategy is simple mechanics—the real reliability comes from respecting your API contracts.
This principle applies equally when building core backend infrastructure or orchestrating autonomous AI agents. Systems inevitably evolve, but the real test is whether you can grow them without breaking what already works.
Tanmay builds AI agents and automation for businesses and is open to freelance projects. Feel free to connect on LinkedIn.
Top comments (0)