Implementing API Versioning

1. Using URI Versioning

AspectDetail
Format/v1/orders
ProsVisible, cache-friendly, easy routing
ConsURLs change with versions
CommonMost public APIs (Stripe, GitHub)

2. Using Header Versioning

HeaderExample
AcceptAccept: application/vnd.shop.v2+json
CustomX-API-Version: 2
ProsStable URLs
ConsHarder to test in browser; CDN cache key

3. Using Query Parameter Versioning

AspectDetail
Format/orders?api-version=2
ProsEasy to test
ConsMixes filters and version semantics
UseDate-based versions (e.g. ?v=2026-05-01)

4. Using Content Negotiation

ElementDetail
Vendor media typeapplication/vnd.shop.v2+json
Profile parameterapplication/json; profile="https://api.shop.com/order/v2"
Server picksBest match from Accept

5. Implementing Backward Compatibility

RuleDetail
Add onlyNew optional fields/endpoints
Don't renameKeep old field; add new one
Don't tightenValidation can only relax
Default valuesFor new required fields
Tolerant readerIgnore unknown fields

6. Managing Breaking Changes

ChangeStrategy
Field removalNew version; deprecate first
Type changeNew field name; old stays
Behavior changeFeature flag or new endpoint
Required ↑Major version bump

7. Deprecating Old Versions

StepDetail
AnnounceChangelog + email + in-product
Sunset headerSunset: Wed, 31 Dec 2026 23:59:59 GMT
Deprecation headerDeprecation: true + Link: rel="successor-version"
BrownoutsPeriodic 410 to surface usage
Sunset window6–12+ months for public APIs

8. Supporting Multiple Versions

ApproachDetail
Single codebase + adaptersConvert v1 ↔ v2 at edges
Separate deploymentsv1 frozen, v2 active
Gateway translationBackwards compat at LB
CostLimit to ≤ 2 active versions

9. Implementing Version Routing

LayerMechanism
GatewayPath/header routes to version pool
Service meshVirtualService matches
Subdomainv2.api.shop.com

10. Documenting Version Changes

DocDetail
CHANGELOG.mdPer-version diff
Migration guidev1 → v2 mapping
OpenAPI per versionHosted side-by-side
Deprecation notesIn docs + headers

11. Using Semantic Versioning

ComponentBump When
MAJORBreaking change
MINORBackward-compatible feature
PATCHBackward-compatible fix
Public APIsExpose only MAJOR in URL/header

12. Implementing API Lifecycle Management

StageDetail
DesignOpenAPI-first, review
BetaLimited audience, breaking allowed
GAStable contract, semver
DeprecatedSunset announced
Retired410 Gone
ToolsBackstage, Apigee, Kong, Tyk