liveBook · Manning

Backward compatibility

As explained in The Design of Web APIs, Second Edition

Backward compatibility is the ability of a changed API to continue supporting existing consumers and their prior usage expectations.

Backward compatibility lets an API change while existing consumers continue working with the data, operations, flows, and expectations they already rely on. It protects end users from crashes, confusing errors, silent behavior changes, and corrupted outcomes. section 1.2.4 section 15.2

Evolving a Shopping API

Replacing a product's category string with a categories array breaks applications that still read category. A compatible alternative keeps category and adds a new optional field. Similarly, replacing a numeric price with a value-and-currency object can be avoided by retaining price and adding priceCurrency with a default value. Existing consumers continue working while updated consumers adopt the richer representation. section 15.0 section 15.1.1

Use these boundaries when modifying an API:

  • For output data, add fields, retain expected fields and types, and modify values only within their original limits. Do not rename, remove, newly require, or unexpectedly retype consumer-visible data. section 15.2.1
  • For input data, make required data optional, add optional data, or expand existing limits. Preserve accepted values and meanings so old requests cannot trigger errors or harmful reinterpretations. section 15.2.2
  • Check headers, paths, operations, statuses, flows, and security schemes as well as bodies; version the interface contract when a breaking change cannot be avoided. section 15.2 section 15.8
Figure 15.3 Breaking changes can occur in headers and bodies of any success or error response. Only add or modify data within the limits of the original data to be backward compatible.
figure

Use the compatibility boundary as a quick review rule: add or adjust response data only within the original data limits. section 15.2.1

How The Design of Web APIs, Second Edition covers it

How deep it goes
Distinguishes compatible and breaking changes across data, operations, flows, and security, then connects them to versioning decisions.
Examples
Uses Shopping API category and price changes, transaction response schemas, transfer inputs, error models, and consumer migration scenarios.
What you can do after
Apply it to design safer API modifications, identify breaking changes, preserve old consumers, and choose when versioning is necessary.
How it connects
Connects backward compatibility with API versioning, extensible design, breaking changes, OpenAPI, and security.

Also explained in

Compare how 18 books explain backward compatibility →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.