Backwards Compatibility: API Evolution

Maintaining backwards compatibility is the discipline of allowing a system to change while ensuring that existing consumers continue to function without modification.

1. Defining Breaking Changes

A "Breaking Change" is any modification to the API contract that causes a consumer to fail.

2. Versioning Strategies

StrategyExampleProsCons
URI/v1/usersEasy to route/cache.Pollutes URI namespace.
HeaderAccept-Version: 2Clean URIs.Harder for browser testing.
Media TypeAccept: application/vnd.v2+jsonREST purest.Complex client implementation.

Expert Recommendation: Use URI versioning for major architectural shifts (e.g., moving from XML to JSON). Use Header-based versioning for iterative data model changes.

3. The "Expand and Contract" Pattern

To safely remove or rename a field, follow this three-phase rollout:

  1. Phase 1 (Expand): Add the new field (new_email) to the response but keep the old field (email). Both fields return the same data.
  2. Phase 2 (Migrate): Update documentation and issue Deprecation Headers (e.g., Sunset: Wed, 15 May 2025). Encourage clients to switch.
  3. Phase 3 (Contract): Once telemetry shows 0% usage of the old field, remove it.

4. Schema Evolution: Protobuf and JSON

5. Automated Verification


See Also: