Skip to content

Lesson 7 of 9 · 26m

Versioning Without Freezing the Future

Additive evolution, media type and URL versioning tradeoffs, compatibility windows, and how to remove fields without breaking clients.

The best versioned API is the one clients never notice changing. Most evolution should be additive: a new optional field, a new endpoint, a new enum value with forward-compatible handling. True breaking versions are sometimes necessary, but every unnecessary version splits your users, your docs, your SDKs, and eventually your attention.

Know what is actually breaking

Usually safe:

  • Adding optional request fields with defaults.
  • Adding response fields.
  • Adding new endpoints or resources.
  • Widening accepted input, such as accepting a string where a stricter format was once required.

Usually breaking:

  • Removing or renaming response fields.
  • Narrowing accepted input.
  • Changing field type or meaning.
  • Changing default behavior, pagination order, or error shape.
  • Reusing an enum value with new semantics.

Adding an enum value is the subtle middle: old clients that strict-parse enums may break even though the wire format is additive. Document enums as open unless they truly are closed.

Choose a versioning mechanism you can operate

/v1/invoices
Accept: application/vnd.acme.billing+json; version=2
X-API-Version: 2026-11-01

URL versions are visible, cache-friendly, and easy for support to reproduce. Media-type versioning is architecturally elegant but harder for casual clients and browsers. Date-based versions are good when behavior changes continuously and you can pin accounts to a release train. None is morally superior; choose the one your clients can debug.

Whatever you choose, do not run unlimited parallel implementations. Internally, versions should be adaptation layers over one domain service:

v2 handler -> normalize -> domain service -> render v2
v1 handler -> normalize -> domain service -> compatibility renderer v1

Use version lifetimes as product policy

A version policy might say: "Breaking versions remain available for 24 months after the next version is announced. Sunset headers begin 12 months before removal." Then implement it mechanically:

Sunset: Sat, 30 Nov 2028 23:59:59 GMT
Deprecation: Tue, 30 Nov 2027 23:59:59 GMT
Link: <https://docs.example.test/api/migrations/v1-to-v2>; rel="deprecation"

Version removal is a migration program, not a pull request. Measure active callers, contact integrators, provide a compatibility checker, and block new keys on old versions before shutting anything down.

Compatibility needs tests, not intentions

Keep golden contract fixtures for each supported version. A response field accidentally omitted from v1 is a breaking production incident even if your domain model never changed. Generate versioned snapshots from real handlers and test representative migrations in CI.

Field notes

  • Never repurpose an existing field because "it is mostly unused"; mostly unused means someone depends on it.
  • Optional does not mean harmless if your clients use strict schema validation.
  • Deprecating a parameter without a replacement migration path creates support tickets, not adoption.
  • A compatibility layer that becomes unmaintainable is a signal the domain abstraction is wrong, not that versioning failed.

Was this lesson helpful?

Sign in to rate