Implementing Service Versioning

1. Understanding Semantic Versioning

MAJOR.MINOR.PATCHWhen
MAJORBreaking change
MINORBackward-compatible feature
PATCHBackward-compatible fix
Pre-release1.2.0-rc.1
Build metadata1.2.0+sha.abc123

2. Implementing API Versioning Strategies

StrategyExamplePros / Cons
URI path/v1/ordersVisible, simple / URL churn
HeaderAPI-Version: 2Clean URLs / hidden, harder to test
Accept media typeapplication/vnd.acme.v2+jsonRESTful purist / verbose
Query param?v=2Cache-unfriendly

3. Implementing Schema Versioning

TechMechanism
ProtobufField numbers immutable; new = optional
AvroReader/writer schema, default values
JSON Schema$id + $version field
Schema RegistryConfluent SR, Apicurio — compat checks

4. Implementing Protocol Versioning

MechanismDetail
HandshakeClient sends supported versions
Server selects max commonNegotiated
ExamplesTLS, HTTP/2 ALPN, Kafka API versions

5. Handling Breaking Changes

TypeStrategy
Field removedDeprecate first, ship MAJOR
Type changeAdd new field, dual-write/dual-read
Behavior changeFeature flag + new endpoint
Expand-then-contractAdd new → migrate clients → remove old

6. Implementing Deprecation Policies

StageDetail
AnnounceDocs + Deprecation + Sunset headers (RFC 8594/9745)
Window≥ 6-12 months for public APIs
Track usagePer-client metrics → outreach
Final removal410 Gone with migration link

7. Understanding Version Compatibility Matrix

DirectionDefinition
Backward compatNew code reads old data
Forward compatOld code reads new data (ignore unknown fields)
Full compatBoth
Wire compatOld clients ↔ new servers and vice versa

8. Implementing Version Negotiation

PatternDetail
Server-drivenServer picks best supported
Client-drivenClient requests specific version
DefaultLatest stable if unspecified

9. Implementing Multi-Version Support

TacticDetail
Side-by-side handlersOne controller per version
Adapter / facadeTranslate v1 ↔ v2 on entry
Common coreShared domain logic
Limit numberAvoid > 2-3 active versions

10. Understanding Sunset Strategies

StepDetail
HeadersDeprecation: true, Sunset: <date>
BrownoutsPeriodic intentional 410s before final
Rate-limit old versionEncourage migration
FinalRemove + redirect docs