At a Glance
| Approach | Problem It Solves | Trade-offs | Used By / Seen In |
|---|---|---|---|
| URI path versioning (/v1/, /v2/) | Simple, visible versioning that’s cache- and browser-friendly with no special client tooling | Creates a second, separately-maintained copy of every resource; cross-resource links become ambiguous about which version they point to | Many public REST APIs across the industry, older eras of several major platform APIs |
| Header / media-type versioning | Keeps one canonical URL per resource; version becomes a negotiation detail, not part of the resource’s identity | Harder to explore in a browser; requires clients to set headers correctly, which complicates naive URL-based caching | GitHub REST API (X-GitHub-Api-Version), content negotiation via the Accept header |
| Query-parameter versioning (?version=2) | Easy to add without touching path structure or routing | Easy to omit by accident and silently fall back to a default; mixes versioning into the same namespace as filters and pagination | Some internal or lower-traffic APIs; broadly discouraged in public API style guides |
| Calendar/date-based versioning | Ties a version identifier to a release date rather than an arbitrary sequence number, pairing naturally with changelogs | Still needs a transport mechanism (usually a header); naming alone doesn’t solve compatibility | GitHub REST API, Stripe API (e.g. a version dated 2024-09-30) |
| Contract-based compatibility (OpenAPI diffing + consumer-driven contract testing) | Catches breaking changes before release by comparing specs or replaying real consumer expectations against the provider | Depends on specs staying accurate (for diffing) or consumers publishing contracts (for Pact); complements a versioning scheme rather than replacing it | oasdiff, Pact and the Pact Broker, OpenAPI-based CI gates |
The Verdict
There is no single correct versioning strategy — the right choice depends on how often you expect to break compatibility and how much tooling complexity you’re willing to carry. URI path versioning is the easiest to explain and ship; header-based versioning keeps your resource model honest at the cost of discoverability; and contract-based approaches like OpenAPI diffing and consumer-driven contract testing don’t replace either scheme but catch the breaking changes that slip through both of them. Most teams need less versioning machinery than they assume, and more deprecation communication than they currently have.
What It Is / The Problem
Every public API eventually needs to change its contract in a way that would break clients relying on the old one — a field gets renamed, a parameter becomes required, a response shape changes. Versioning is the set of conventions an API uses to let old and new contracts coexist long enough for consumers to migrate on their own schedule, instead of being broken the moment the provider ships a change.
The debate over where to put the version — in the URL path, in a header, in a query string — gets more attention than the more consequential question underneath it: what actually counts as a breaking change, and how will clients find out a version is going away before it does, rather than after. A URI scheme with no deprecation signal and a header scheme with a clear changelog and a Sunset header will, in practice, produce very different outcomes for the people building against an API, almost independent of which versioning mechanism either one uses.
How It Works: Key Patterns
URI Path Versioning
Putting the version in the path — /v1/orders, /v2/orders — is the most common pattern in public APIs because it needs no special client tooling: it works in a browser address bar, in curl without extra flags, and is trivially visible in logs and cache keys. Its cost shows up less obviously at first. A widely cited critique published on Google Cloud’s blog by Apigee’s Martin Nally argues that a versioned URL effectively creates a second resource that has to be kept in sync with the first, and that hyperlinks between resources become ambiguous about which version they should point to — a representation under /v1/preferences linking to a related resource has no clean way to say whether that link should resolve to the v1 or v2 copy. For APIs built around linked, evolving resources rather than a handful of independent endpoints, that syncing cost compounds with every version still running in production.
Header and Media-Type Versioning
The alternative keeps a single canonical URL per resource and moves the version into a request header, either a custom header or standard content negotiation via the Accept header with a custom media type. GitHub’s REST API took this route explicitly, introducing an X-GitHub-Api-Version header pinned to a release date (for example, 2022-11-28) after more than a decade on an unversioned API with no clean mechanism for making breaking changes. GitHub’s published policy reserves a new version for genuinely breaking changes only — removing a response field, making an optional parameter required, deleting an endpoint — while additive changes like new endpoints ship continuously without a version bump, and each version is supported for at least 24 months after a newer one ships. The trade-off is discoverability: you can’t version-browse an API by changing a URL, and caching layers keyed purely on URL won’t see the header, so this scheme asks more of client tooling and of a provider’s own cache configuration.
Query-Parameter Versioning
Appending something like ?version=2 to a request is the least structurally invasive option, since it changes neither the path hierarchy nor the request headers. It’s also the scheme most often flagged in API design critiques: a query parameter is easy to omit by accident, silently falling back to whatever the default version happens to be, and it mixes versioning semantics into the same namespace as filtering and pagination parameters in the same query string. In practice it shows up more often on internal or lower-traffic APIs than as the primary scheme for a widely integrated public API.
Deprecation and Sunset Signals (RFC 9745 and RFC 8594)
Whichever scheme a team picks, clients still need a reliable, machine-readable way to learn that a version — or a specific endpoint — is going away, rather than finding out when it starts returning errors. Two IETF specifications standardize this. RFC 8594 defines the Sunset HTTP header field, an HTTP-date response header signaling that a resource is expected to become unresponsive at a specific future time; the RFC is explicit that this is a hint rather than a guarantee, and that it fits the later stage of deprecation — actual decommissioning — rather than an earlier stage where something is merely discouraged but still functional. RFC 9745, published more recently, defines a complementary Deprecation header whose value is a structured-field date marking when a resource was or will be deprecated, optionally paired with a Link header using rel="deprecation" that points to migration documentation. Per RFC 9745, a Sunset date present on the same response must not be earlier than the Deprecation date. Used together, they let an API communicate both “this is on its way out” and “this is the hard deadline” in a form any HTTP client can parse automatically, without reading a changelog:
HTTP/1.1 200 OK
Deprecation: @1718150400
Sunset: Fri, 01 Aug 2025 00:00:00 GMT
Link: <https://developer.example.com/docs/migrate-to-v2>; rel="deprecation"
Contract-Based Approaches: OpenAPI Diffing and Consumer-Driven Contracts
A versioning scheme only works if someone actually notices when a change breaks compatibility, and that’s increasingly treated as a CI problem rather than a documentation problem. Tools like oasdiff compare two revisions of an OpenAPI spec and separate a breaking command — changes that would actually break existing clients — from a broader changelog command that reports every consumer-relevant change, breaking or not. It can run as a GitHub Action or a pre-commit hook, so a pull request fails before a breaking change merges rather than after a client reports it.
Consumer-driven contract testing, with Pact as the best-known open-source implementation, approaches the same problem from the client’s side. According to Pact’s own documentation, a consumer’s test suite records the exact requests it makes and the minimal response shape it needs against a Pact mock provider, producing a pact file; that file is then replayed against the real provider in the provider’s own test suite, typically coordinated through a Pact Broker, and verification fails if the provider’s actual response no longer satisfies what a real consumer depends on. Because this checks real, current consumer expectations rather than a spec someone maintained by hand, it catches a category of break a pure OpenAPI diff can miss: a field the spec still documents but that no consumer actually reads won’t fail a diff-based check, while a field a consumer genuinely depends on will fail a Pact verification if the provider removes it.
The Upside: Benefits of Getting This Right
- Clients can adopt new capabilities on their own schedule instead of being broken by a provider’s release
- A documented breaking-vs-non-breaking policy, as both GitHub and Stripe publish, lets integrators judge upgrade risk without reading every changelog entry
- Sunset and Deprecation headers give automated tooling, not just humans, a way to flag an integration that’s about to break
- Spec diffing and contract tests catch breaking changes in CI, before a release, rather than in a support ticket after one
- A clear policy reduces the number of parallel versions a provider has to keep running in production at once
The Pitfalls: Common Mistakes
- Treating every change as a reason to cut a new version, leading to far more parallel versions in production than necessary
- Shipping a version scheme with no Sunset or Deprecation signal, leaving clients to discover retirement only when requests start failing
- Header-based versioning degrading the “paste a URL in a browser” experience that makes REST APIs approachable, and breaking naive URL-keyed caching unless cache keys account for the header
- Letting OpenAPI specs drift from the real implementation, which silently defeats any spec-diffing tool built on top of them
- Assuming Pact-style contract testing protects every interaction, when it only protects interactions an actual consumer test records
Who Needs to Care (and When It Matters Less)
This matters most for APIs with external, independently deployed consumers a provider doesn’t control — public APIs, platform APIs with a partner ecosystem, anything with mobile clients on release cycles slower than the backend’s. A breaking change to an API where every consumer is a service the same team deploys through the same pipeline can often be handled with a coordinated rollout instead of a formal versioning scheme, which is part of why Apigee’s own published guidance argues against reaching for a /v1/ prefix out of habit on day one. The more consumers a provider doesn’t control, and the more harm a broken integration causes them, the more a deliberate versioning and deprecation policy — documented, with real Sunset headers rather than a changelog nobody reads — pays for itself.
Bottom Line
The versioning mechanism matters less than most API design debates make it sound — URI paths, headers, and date-based identifiers all work in production for companies with very different traffic and consumer profiles. What separates a versioning policy that actually protects integrators from one that just relocates the breakage to a different status code is whether breaking changes are defined narrowly and documented, whether deprecation is signaled in a form clients can automate against, and whether breaking changes are caught before release through spec diffing or consumer-driven contract tests, rather than after release, by a support queue.
FAQ
Do I need /v1/ in my URL from day one?
Not necessarily. Martin Nally’s Google Cloud/Apigee-published critique of default path versioning argues many APIs ship a version prefix out of habit and never actually need a second version; adding a versioning scheme only once an actual breaking change is imminent avoids the ongoing cost of keeping multiple URL-rooted copies of a resource in sync.
What actually counts as a “breaking” change?
Conventions vary by provider, but the published policies that exist — GitHub’s and Stripe’s among them — draw a similar line: removing a field or endpoint, renaming something, or making an optional parameter required are breaking; adding a new optional parameter, a new response field, or a new endpoint is not, provided clients are expected to ignore unfamiliar fields and event types. Writing that expectation into client-facing documentation is as important as the policy itself, since a client that errors on an unrecognized field can still break on a technically non-breaking change.
What’s the difference between the Sunset header and the Deprecation header?
Deprecation (RFC 9745) marks that a resource has been or will be deprecated — it’s a structured-field date and can point to migration docs via a Link header, but it doesn’t change how the resource behaves. Sunset (RFC 8594) marks the later point at which the resource is actually expected to stop responding, using a standard HTTP-date. RFC 9745 requires that when both are present, the Sunset date can’t be earlier than the Deprecation date — deprecation is the warning, sunset is the deadline.
Is OpenAPI diffing a substitute for contract testing like Pact?
They catch overlapping but different things. A spec-diffing tool like oasdiff flags changes against the documented contract, which is only useful if the spec is kept accurate. Consumer-driven contract testing checks against what real consumers actually request and read, recorded as pact files and verified against the live provider, so it can catch a break that a stale or incomplete spec would miss — and, conversely, a diff tool can catch an undocumented breaking change in a part of the spec no consumer’s contract test happens to cover.
Can query-parameter versioning work for a public API?
It can, but it’s the scheme most frequently criticized in API design guides, largely because it’s easy for a client to omit the parameter and silently receive a default version, and because it mixes versioning semantics into the same namespace as filtering and pagination parameters. Where it is used successfully, it tends to be on lower-traffic or internal-facing APIs rather than as the primary scheme for a widely integrated public API.
Discover more from Software Online Review
Subscribe to get the latest posts sent to your email.
