Managing API Versioning Patterns

1. API Versioning Pattern

StrategyDetail
URL Path/v1/orders
HeaderX-API-Version: 2
Query Param?version=2
Content NegotiationAccept: application/vnd.shop.v2+json
Hostnamev2.api.shop.com

2. URL Path Versioning Pattern

ProsCons
Most discoverableURI changes break REST hypermedia
Cache-friendly per versionCouples version to resource identifier
Easy testing in browser

3. Header Versioning Pattern

AspectDetail
HeaderCustom (X-API-Version) or standard (Accept-Version)
ProsURI stable; per-resource versioning
ConsLess discoverable; harder to test

4. Query Parameter Versioning Pattern

AspectDetail
Format?api-version=2024-05-01
ProsEasy to test, opt-in
ConsCache fragmentation; clutter
Used ByAzure REST APIs (date-based)

5. Content Negotiation Versioning Pattern

AspectDetail
MechanismAccept: application/vnd.shop.v2+json
ProsRESTful; URI stable
ConsComplex client config; tooling friction

6. Semantic Versioning Pattern

ComponentBump When
MAJOR (X.0.0)Breaking change
MINOR (0.X.0)Backward-compatible feature
PATCH (0.0.X)Backward-compatible bugfix
For APIsUsually only MAJOR exposed in URL

7. Backward Compatibility Pattern

RuleAllowed?
Add optional fieldYes
Add new endpointYes
Rename fieldNo (use Expand & Contract)
Remove fieldNo (mark deprecated, remove in next major)
Tighten validationNo (rejects previously valid input)
Change typeNo
Add new required fieldNo (must be optional)

8. Forward Compatibility Pattern

PracticeDetail
Tolerant ReaderIgnore unknown fields
Use DefaultsFor missing optional fields
Schema-FirstGenerate clients from schema (Protobuf, OpenAPI)
BenefitOld clients survive new server features

9. Deprecation Pattern

StepAction
AnnounceDocs + email + dashboard
Header SignalDeprecation, Sunset (RFC 8594)
Track UsagePer-client metrics; identify stragglers
Migration GuideCode examples; new vs old
Sunset DateMin 6-12 months for public APIs
RemoveConfirm zero traffic; remove code

Example: Deprecation Headers

HTTP/1.1 200 OK
Deprecation: Tue, 01 Jul 2026 00:00:00 GMT
Sunset: Tue, 31 Dec 2026 00:00:00 GMT
Link: <https://api.shop.com/v2/orders>; rel="successor-version"

10. Parallel Versions Pattern

AspectDetail
Run Side-by-Sidev1 and v2 served simultaneously
ImplementationSame service different routes, or separate services
CostMaintain N versions; bug fixes ported to all supported
LimitCap supported versions (e.g., last 2 majors)