Versioning and Evolving an API

Topics Covered

Breaking and Non Breaking Changes

What clients actually depend on

Changes that are usually safe

Changes that break clients

The enum problem

Response shape and nullability

A practical test

Why most changes should not need a version

Design choices that make evolution cheap

Behaviour changes without schema changes

Clients you do not know about

Every successful API changes. Products add features, teams learn which names were confusing, and requirements that were out of scope in the first version become urgent in the third. The hard part is that once an API has clients, those clients depend on its exact behaviour, and you usually cannot update them. A mobile app version stays installed on phones for years. A partner's integration was written by a contractor who has moved on. An internal service is owned by a team with other priorities. So the central skill of API evolution is changing the API without breaking the people who already use it.

In an API design interview, evolution normally comes up in the last step of the framework from lesson one, or when the interviewer asks how you would add a feature to the API you just designed. A candidate who says we will bump the version has given a shallow answer. A strong candidate explains which changes are safe without a version, which are breaking, how to make most changes safe, and what happens on the rare occasions a breaking change is unavoidable.

What clients actually depend on

A client depends on far more than the documented schema. It depends on field names and types, on which fields are present, on which values an enum can take, on status codes, on error codes, on default values, on the order of items in a list, on pagination behaviour, on validation rules, on rate limits and even on latency. Hyrum's law states the problem precisely: with enough users, every observable behaviour of your system will be depended on by somebody, whether or not you promised it.

That does not mean you can never change anything. It means you need a clear definition of what you promise, written into the documentation, and a conservative rule for everything else. The usual definition is that the documented schema and semantics are the contract, and clients are expected to follow a few rules, such as ignoring unknown fields. Anything outside that contract may change, but you still treat widely relied on behaviour with care.

Changes that are usually safe

Additive changes are the backbone of safe evolution. Adding a new endpoint or resource is safe, because no existing client calls it. Adding an optional request parameter or field is safe, provided the default when it is absent preserves the old behaviour. Adding a field to a response is safe if clients ignore fields they do not recognise. Relaxing validation, for example allowing longer names, is usually safe. Adding a new error code inside an existing category is safe if clients fall back to the category, as lesson six described. Adding a new optional header is safe.

Adding a field is only safe if clients ignore what they do not recognise.

The condition attached to adding response fields matters a great deal. A client written in a language with strict deserialisation, or generated with a setting that rejects unknown properties, will crash when a field appears. This is why the tolerant reader principle is part of the contract: clients must ignore unknown fields in responses. State it in the documentation, configure official SDKs that way, and test it, because every additive change relies on it.

Changes that break clients

Removing a field or an endpoint is breaking. Renaming is breaking, because to a client a rename is a removal plus an addition. Changing a field's type is breaking, even when it looks harmless, such as from integer to string for an id that grew too large, or from a number to an object. Making an optional request field required is breaking. Tightening validation, such as reducing a maximum length or rejecting values that used to be accepted, is breaking. Changing a default value is breaking, because clients that relied on the default now get different behaviour without changing their code. Changing the meaning of a field, such as amount switching from dollars to cents, is breaking and the worst kind, because nothing fails loudly and the data is silently wrong.

Each proposed change goes in one of two bins before it ships.

Some changes are breaking in ways that are easy to miss. Changing the default sort order of a list breaks clients that assumed newest first. Changing the page size default breaks clients that never paginated because the first page used to contain everything. Changing which status code an error returns breaks retry logic. Changing an error code string breaks client switch statements. Making a synchronous operation asynchronous, returning 202 instead of 201, breaks every client that expected the created resource in the response.

The enum problem

Adding a value to an enum looks additive, but for many clients it is breaking. If an order status was always one of pending, paid or shipped, a client may have a switch statement with no default branch, or a generated SDK with a closed enum type that fails to parse an unknown value. Adding refunded then crashes that client. There are two defences. First, document from day one that enums are open and clients must handle unknown values, ideally with an explicit unknown fallback in the SDK. Second, for enums where a new value changes semantics, such as a new payment status that clients must act on, treat the addition as a breaking change or gate it behind a version. In an interview, raising the enum problem unprompted is a reliable sign of real experience.

Response shape and nullability

Nullability and presence are another trap. If a field was always present and you start omitting it when empty, or returning null, clients that read it without checks will fail. Decide early whether optional fields are omitted or sent as null, and keep that rule. Similarly, wrapping a top level array response in an object later, for example to add pagination metadata, breaks every client. That is why lesson four recommends returning list responses as an object with a data array from the start, even when there is no pagination yet. Small decisions in the first version determine how cheaply the API can evolve.

A practical test

A simple test sorts most changes: could any client that works correctly today, following the documented rules, fail or behave differently after this change, without changing its code? If yes, the change is breaking. If the only clients that would fail are ones that break documented rules, such as rejecting unknown fields, the change is non breaking by contract, though you may still want to check your largest integrations before shipping. Apply this test to both requests and responses, and to behaviour as well as schema.

Why most changes should not need a version

Versions are expensive. Every live version is code you maintain, test, document and support, and every version boundary is a migration your clients must perform. So the goal is to evolve almost entirely through additive, backward compatible changes, and to reserve a new version for the rare change that cannot be made additive. A healthy public API might ship hundreds of additive changes for each breaking one. In the interview, say that you would design for additive evolution first, by making list responses objects, enums open, optional fields optional and clients tolerant, and only then talk about how you would version.

Design choices that make evolution cheap

A few choices in the first version buy years of flexibility. Return objects rather than bare primitives or arrays, so fields can be added. Use string identifiers rather than integers, so their format can change. Use string enums rather than booleans for states that might gain more values: a boolean is_active cannot grow into active, suspended and closed, but a status field can. Put money in an object with amount and currency, even if you only support one currency today. Accept options objects instead of long positional parameter lists in SDKs. Each of these costs nothing at launch and avoids a breaking change later. Mentioning two or three of them while you define the schema in step four is a good way to show foresight without slowing down.

Behaviour changes without schema changes

Some of the most damaging breaks change no schema at all. A search endpoint that starts returning results in a different relevance order, a rate limit that drops from 100 to 50 requests per second, a webhook that starts arriving before the resource is readable, or a cache that makes reads stale for a few seconds where they were fresh before, can each break real integrations. Treat behaviour as part of the contract, document the parts you guarantee, such as ordering and consistency, and announce changes to undocumented but widely relied on behaviour as carefully as you would a schema change.

Clients you do not know about

Public APIs always have clients the provider never hears from: scripts written once and left running, spreadsheets that call an endpoint, integrations built by agencies. They do not read changelogs and cannot be asked. This is why the conservative rule matters most for public APIs, and why the documented contract, published early and kept stable, is the only promise these silent clients can rely on.

Design the first version to evolve

Most breaking changes are caused by choices made on day one: bare arrays, closed enums, booleans that should have been states, integer ids. Making these extensible costs nothing at launch and is the cheapest versioning strategy there is.