Lesson 2 of 9 · 26m
Choosing a Versioning Strategy You Can Operate
Compare path, header, media type, query, and evolutionary versioning with attention to routing, cacheability, client ergonomics, and operational cost.
There is no universally correct API versioning mechanism. There is only a mechanism whose failure modes your organization can operate. Path versioning is easy to see and easy to overuse. Header versioning is elegant and easy to forget in debugging. Media types are precise and often hostile to casual integration. Choose deliberately, then be consistent enough that clients can build muscle memory.
Path versioning
The common form is simple:
GET /v1/invoices/inv_123
GET /v2/invoices/inv_123It is visible in logs, easy to route, easy to document, and easy for humans to test with curl. It also encourages teams to duplicate the entire API when only one resource changed. A major-version path should represent a broad compatibility contract, not a folder you copy whenever a serializer changes.
Routing is easy to understand, whether terminated in nginx, a cloud load balancer, or the application itself. Do not let infrastructure topology become product design: two versions can share one application behind a compatibility layer.
Header and media type versioning
Header versioning keeps URLs stable:
GET /invoices/inv_123
Accept: application/vnd.acme.invoices+json; version=2This is semantically attractive when the resource identity stays stable but representations evolve. The operational cost is that version information is easy to omit from screenshots, browser tests, support tickets, and casual scripts. If you choose headers, log the negotiated version and include it in error responses.
A simpler custom header is easier for integrators:
Acme-Version: 2026-03-01Date-based versions work well for continuously evolving platforms. They still need policy: how many dates are active, how they map to behavior, and when old dates stop being accepted.
Query versioning is convenient but cache-hostile
GET /invoices?version=2 is easy to experiment with and easy to log, but query parameters are often treated as filtering rather than contract selection. They can be dropped by clients, proxies, or generated documentation. Use query versioning for beta opt-in if you must, not as the primary long-term compatibility mechanism.
Evolutionary versioning
Some APIs avoid major versions by only adding fields, endpoints, and enum values while never removing behavior. This works best when the contract is carefully designed and clients are tolerant readers. It fails when the original model is wrong, because permanent support becomes the price of a bad first guess.
{"created_at": "2026-03-01T12:00:00Z", "created_on": "2026-03-01"}Duplicating old and new fields forever is not elegance. It is deferred deletion with interest.
Decision criteria that matter
Choose based on client sophistication, public versus private audience, routing complexity, cache behavior, documentation tooling, SDK generation, debugging ergonomics, and how often you truly expect incompatible change. Then test the boring paths: OpenAPI output, generated SDKs, error examples, support runbooks, logging, analytics, and cache keys.
Field notes
- Never mix versioning systems casually.
/v2plus a media-type version creates ambiguity nobody wants to debug. - Defaulting unversioned traffic to the newest version is a breaking change waiting for a deploy.
- Version negotiation belongs at the edge of the application, not scattered through controllers.
- Whatever mechanism you choose, include the effective version in logs and traces.
Was this lesson helpful?