Lesson 08 of 13 · Designing the edge
The API lifecycle
APIs live longer than the code behind them. Treat them as products with a lifecycle: design the contract first in OpenAPI, lint it, detect breaking changes in CI, version only when you must (and how: path, header or media type), run versions side by side behind the gateway, deprecate with Deprecation and Sunset headers and real usage data, and give consumers a developer portal.
An API is a promise
Once someone outside your team uses an API, you can't change it whenever you like. Mobile apps stay installed for years, partners deploy quarterly, and scripts nobody remembers keep running. Managing that promise over time is the API lifecycle.
design → review → build → publish → operate → evolve → deprecate → retire
│ │ │ │ │ │
OpenAPI lint + portal, gateway additive Deprecation/Sunset
breaking-change docs, keys metrics changes headers, usage data
check in CI per consumer first
A bus timetable is a promise. You can add a new bus (safe). If you move a stop or cancel a route, everyone who planned around it is stranded, so you put up notices weeks before, count who still uses the old stop, and help them switch before you remove it.
Design the contract first
- Describe the API in OpenAPI (or protobuf for gRPC) before writing code: paths, schemas, errors, auth, examples.
- Review it like code, in a pull request, with consumers if possible.
- Lint it against house rules (naming, pagination, error format, required descriptions) with a tool such as Spectral.
- Generate docs, client SDKs and mock servers from it; test the implementation against it.
Safe and breaking changes
| Change | Safe? |
|---|---|
| New endpoint | ✔ |
| New optional request field or query parameter | ✔ |
| New field in a response | ✔ (if clients ignore unknown fields, which you should require) |
| New enum value in a response | ⚠ only if clients were told to tolerate unknown values |
| Removing or renaming a field or endpoint | ✘ |
| Changing a type (string → number) or format | ✘ |
| Making an optional request field required | ✘ |
| Stricter validation, new required header | ✘ |
| Changing the meaning of a field | ✘ (and the hardest to detect) |
Detect breaking changes automatically: compare the new OpenAPI file with the published one in CI (for example with oasdiff) and fail the build, unless the change is in a new version.
Versioning: only when you must
Most evolution should be additive, with no new version. When a breaking change is unavoidable:
| Style | Example | Notes |
|---|---|---|
| Path | /v2/orders |
Visible, easy to route and cache; the most common |
| Header | Api-Version: 2026-11-01 |
Clean URLs; date-based versions per change set are popular for large public APIs |
| Media type | Accept: application/vnd.example.v2+json |
Precise, less discoverable |
Behind the gateway, versions are just routes:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: orders-versions
namespace: shop
spec:
parentRefs:
- { name: edge, namespace: infra }
hostnames: ["api.example.test"]
rules:
- matches:
- path: { type: PathPrefix, value: /v2/orders }
backendRefs:
- { name: orders-v2, port: 80 }
- matches:
- path: { type: PathPrefix, value: /v1/orders }
backendRefs:
- { name: orders-v1, port: 80 }
Keep the number of live versions small (two is common): every version is code to maintain, test and secure.
Deprecate with data, not guesses
- Announce: changelog, email to registered consumers, docs banner.
- Signal in responses: the
Deprecationheader (when it was or will be deprecated) and theSunsetheader (when it will stop working), plus aLinkto the migration guide. - Measure: gateway metrics and logs per consumer (API key, client ID, tenant) for the old version.
- Help the remaining consumers move; contact them directly.
- Brown-outs (optional): short planned periods where the old version returns errors, so forgotten clients surface before the final date.
- Retire when usage is zero or agreed, after the Sunset date.
HTTP/1.1 200 OK
Deprecation: @1793836800
Sunset: Mon, 01 Mar 2027 00:00:00 GMT
Link: <https://developer.example.com/migrate-v1-v2>; rel="deprecation"
The gateway can add these headers to the old route with a ResponseHeaderModifier filter, so the application doesn't need a release.
The developer portal
For APIs used by other teams or customers, a portal turns the contract into a product: rendered docs, try-it consoles, sign-up and keys, usage dashboards per consumer, changelogs and deprecation notices. API-management products include one (lesson 11); internal platforms often use their developer portal's API catalog.
Try it
- Write a small OpenAPI file for
GET /orders/{id}andPOST /orders. - Make three changes in a copy (add a response field, rename a field, make a request field required) and run a breaking-change tool to see which it flags.
- Add the
/v1and/v2route above to the lab cluster, and aResponseHeaderModifierthat addsDeprecationandSunsetheaders to/v1only. - Write the deprecation timeline for one of your own APIs: dates, messages, metrics to watch.
Going deeper
- gRPC/protobuf has its own rules: never reuse field numbers, only add fields, use
reservedfor removed ones; tools likebuf breakingcheck them. - Consumer-driven contract tests let consumers publish what they rely on, so providers know exactly what they can change.
- For event APIs (Kafka topics), the same ideas apply to schemas: see the Kafka course's schema-registry lesson.
Recap
- Treat an API as a long-lived promise with a lifecycle: design, publish, operate, evolve, deprecate, retire.
- Contract first (OpenAPI), lint it and fail CI on breaking changes.
- Prefer additive changes; version only when necessary, and route versions at the gateway.
- Deprecate with headers, usage data per consumer and direct help; retire when usage is gone.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.