API governance and versioning
Keep hundreds of APIs consistent and evolvable with style guides, contract checks and a clear versioning policy.
15 min readAPIs are the architecture
In a service-based organisation, APIs are the load-bearing walls. Internal code can be refactored freely; a published API is a promise to every consumer. Inconsistent APIs (different pagination, error formats and auth per team) add friction to every integration. API governance is the lightweight set of rules and automation that keeps APIs consistent, discoverable and safe to evolve, without a central committee approving every endpoint. Good governance is mostly automation plus a short list of rules that every team agrees to follow.
A style guide enforced by linting
Write a short API style guide and enforce it with tooling, not meetings. Spectral can lint OpenAPI specs in CI, and buf does the same for protobuf schemas.
- Naming: plural resource nouns, consistent casing
- Errors: one format, such as RFC 9457 problem details, with stable error codes
- Pagination: cursor-based with a maximum page size
- Idempotency: an Idempotency-Key header on all non-idempotent POSTs that move money or create orders
- Auth: OAuth scopes documented per operation
- Every API has an owner, an SLO and a changelog
Compatible change and versioning
Most changes should be backward compatible so no version bump is needed: adding optional fields, adding endpoints, adding enum values that clients are told to tolerate. Breaking changes include removing or renaming fields, changing types, tightening validation and changing semantics. Detect them automatically by diffing the spec against the last release in CI (oasdiff, buf breaking). When a break is unavoidable, introduce a new major version (/v2 or a version header), run both in parallel, and publish a deprecation timeline.
Consumer-driven contracts
Provider-side checks only know the schema, not how consumers actually use it. Consumer-driven contract testing (for example Pact) has each consumer publish the interactions it relies on; the provider's pipeline verifies it still satisfies all of them before deploying. This catches the change that is technically compatible but still breaks a real consumer, and it tells you exactly who is affected before you remove anything. Publish contract results in a broker so both teams can see which versions are compatible before deploying.
Key takeaways
- Published APIs are promises; govern them with a short style guide and automated linting.
- Standardise errors, pagination, idempotency and auth across all APIs.
- Prefer additive, compatible changes; detect breaking changes automatically in CI.
- Use consumer-driven contracts to know exactly who a change will break.
Sign in to track lessons and earn badges.