API Versioning 00:00:01 A price takes a new shape Yesterday a shop returned a price as a number. Today it wants to attach currency and tax information. An old checkout still expects the number. How can the new client get more information without breaking the old one? A name and a price as a plain number. The price becomes an object with a currency: breaking. Stock is new: an addition. Name is now title, price is pricing, stock moved into inventory. Three breaking changes at once. v2 could have kept price and added a second field. Then no v2 would have been needed. Adding currency inside a new structured price changes how an old caller parses the field. The internal record can change without forcing every existing public contract to change simultaneously. 00:00:51 Translate at the boundary A v1 request is answered by a core that only speaks v3. The gateway reads v1 from the path. The request passes the adapters and reaches the core. Title becomes name, pricing becomes price. The price becomes a number and stock is dropped. The client gets the form it knows, plus Deprecation and Sunset headers. A v2 client only needs the first adapter. Map public versions into a consistent internal model when their meanings permit it. Test both directions, including defaults and precision, because an adapter can quietly change a price while preserving valid JSON. 00:01:29 Make the version visible to routing Visible, easy to test, works in a browser. One thing has several addresses. Clean addresses, but hidden. Caches must vary by it. Standard content negotiation, harder for clients. Easy to switch, easy to forget, looks like a filter. A path, header or negotiated media type can carry the version. Choose a convention that clients, caches, logs and support tooling all interpret in the same way. 00:01:58 Which changes break existing clients? Old clients do not know it and ignore it. A client reads it and finds nothing. Code that multiplies the price fails. Requests that were fine are refused. Harmless for tolerant clients, a crash for those that list every value. Adding an optional field is often compatible for tolerant readers, but changing an enum or a field's business meaning can break behavior even if parsing still succeeds. Test actual client expectations. 00:02:27 Retire with evidence Four phases, with the traffic of v1 as the guide. Example numbers. v1 is the recommended version. v2 is ready. v1 still works and sends the Deprecation header. The date is public. Owners of the remaining keys are contacted, brownouts are announced. The date passed, but one partner still calls. Talk first, and agree on a last date. No calls for weeks. v1 answers 410 Gone with a link to the guide. Publish the migration path, count callers by version and give them a chance to verify the replacement. A deployment date alone cannot show whether a long-lived client has stopped using the old contract. 00:03:09 A cache gives the wrong shape The version is in a header, and the shared cache does not know it. The v2 client asks for /products/123. The answer is stored under the address. Same address, so the cache hands out the v2 answer. The v1 client breaks. With Vary and the header's name, the cache keeps one answer per version. If the version lives in a header, the representation cache must distinguish that header when responses vary on it. A cache hit with the wrong schema is still an incorrect response. Version the promise on which clients depend. Route, adapt and cache according to that promise, and retire it only after clients have a tested way to move.