Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

You are deciding whether machine-readable API contracts (OpenAPI, AsyncAPI, protobuf) should be mandatory for every service in the company. What long-term benefits and costs would you weigh?

Machine-readable contracts pay off over many years: they make APIs discoverable, let us generate clients, check compatibility and security automatically, and make onboarding and audits cheaper. The costs are tooling, review effort and the risk that teams treat the spec as paperwork, so I would mandate them only where a boundary crosses teams, enforce them in the build, and pick formats with strong ecosystems so we never have to migrate thousands of contracts.

Why this question is asked

A decision like this outlives the person who makes it. Once a company has several hundred services, the way they describe their interfaces decides how fast new teams can integrate, how safely old ones can change, and how much an audit or a platform migration costs. Interviewers ask it at this level because the answer shows whether we can weigh a long-term asset against short-term friction, and whether we know how mandates fail in practice. In this answer, we will recap what a machine-readable contract is, go through the benefits and the costs, decide where the mandate should apply, look at contracts as a long-lived asset, and finish with how to choose formats and roll the rule out.

1A Quick Recap of Machine-Readable Contracts

An API contract is the description of what a service accepts and returns. A machine-readable contract is one that a program can parse, not a wiki page. OpenAPI describes HTTP APIs: paths, methods, request and response schemas, status codes and security schemes. AsyncAPI does the same for messages on channels such as Kafka topics or queues. Protocol Buffers (protobuf) define messages and gRPC services in .proto files, from which code is generated for many languages.

What these formats share is that the contract becomes an input to tools. A generator reads it and writes a client. A linter reads it and checks naming rules. A diff tool compares two versions and says whether the change will break existing callers. That is the whole reason to make them mandatory: a document nobody can execute ages quickly, while a document the build depends on stays true.

2What We Gain Over the Years

The first gain is discoverability. If every contract is published to a catalog, an engineer who needs customer data can search for it instead of asking around in chat. The second is generated clients: a team consuming the orders API generates a typed Java or TypeScript client instead of hand-writing request classes, which removes a whole class of typo and mapping bugs.

The third gain is the one that matters most at scale: automated compatibility checks. When the provider changes the contract, CI can compare it with the published version and fail the build if a field was removed or a type changed. The fourth is security review: a reviewer can see from the contract which endpoints have no security scheme, which ones return fields marked as personal data, and which accept free-form input. The fifth is onboarding: a new engineer can read a contract and try the API from generated documentation on their first day.

Benefits and who feels them
BenefitWho gainsWhen it pays off
Discoverability in a catalogEvery consuming teamFrom the first month
Generated clientsConsumers in any languageEvery new integration
Compatibility checks in CIProviders and consumersEvery change, for years
Security and privacy reviewSecurity team, auditorsEach review and audit
Faster onboardingNew engineersEach new hire or team

3What It Costs, and How Mandates Fail

The costs are real. Teams need tooling: generators, linters, a catalog, CI steps, and someone to maintain all of it. Every change to a contract needs review, and reviews take time from people who would rather ship features.

The worst cost is hidden. If the contract is not wired into the build, teams write it once to satisfy the rule and never update it. After a year the spec says one thing and the service does another, and a wrong contract is worse than none because people trust it. So the rule I would set is that a contract only counts if the build uses it: either the server is generated from it, or the spec is generated from the code and checked against the published one. In both cases a mismatch fails the pipeline, and the spec can never quietly drift.

4Where the Mandate Should Apply

Not every interface deserves the same rigour. A contract is most valuable where the two sides are owned by different teams, because there nobody can just look at the other side's code or change both in one pull request. Inside one team, where the same people own the caller and the provider and deploy them together, a full review process mostly adds friction.

So a sensible rule is: mandatory, reviewed and published for every boundary that crosses a team, and every public or partner API; lighter rules inside one team, such as a generated spec without a formal review. The flow below shows the decision a team would follow.

Step throughDoes this interface need a governed contract?
  1. Is it called by another team, a partner or the public?
    YesMandatory contract, reviewed and publishedNoGo to the next question
  2. Is it an event other teams may consume later?
    YesMandatory AsyncAPI or schema in the registryNoGo to the next question
  3. Inside one team onlygenerated spec in the build, no formal review
  4. Every governed contractlinted, diffed against the last version, published to the catalog

4 steps in order. Play them, or step through them one at a time.

5Contracts as a Long-Lived Asset

The benefit that is easiest to miss is what happens five or ten years later. Suppose the company must answer an auditor's question: which services expose a customer's date of birth? With contracts in a catalog, someone can search every schema for that field in an afternoon. Without them, it is a months-long survey of teams, some of which no longer exist.

The same is true of migrations. When we move from one API gateway to another, change the authentication scheme, or add rate limits, a tool can read every contract and generate the gateway configuration. When we retire a service, the contract tells us who generated a client from it. Over many years the contracts become an inventory of the company's interfaces, and automated tooling we have not yet imagined can be built on top of it.

6Choosing Formats That Will Still Be Supported

A format chosen today will be with us for a decade, and moving thousands of contracts from one format to another is a project nobody wants to fund. So the format must have a strong ecosystem: many generators, linters, editors, and an active standards body. OpenAPI 3.1, AsyncAPI and protobuf all meet that bar, and each fits a different kind of interface.

The trap is an in-house format, such as a custom YAML dialect: it works for a year, and then every new tool must be written by us. I would allow only the standard formats, pin the versions we support (for example OpenAPI 3.1 for new specs, 3.0 accepted for existing ones), and publish shared templates so teams start from a good example.

7Rolling It Out Without Losing the Teams

A mandate announced in an email and enforced by nobody produces paperwork. I would start with new services and cross-team APIs, give teams a starter that already generates or validates the spec in the build, and make the catalog useful from day one so teams see the benefit themselves. For existing services, the rule applies when a team next changes the API, not as a big-bang deadline.

I would also measure it. Useful numbers are the share of cross-team calls covered by a published contract, the number of breaking changes caught in CI instead of in production, and the time a new consumer needs to make a first successful call. If those numbers do not improve after two or three quarters, the rule is costing more than it gives, and we adjust it.

8Follow-up questions

What if a team writes the spec after the code is finished?

That is fine as long as the build ties them together. Code-first teams can generate the spec from annotations with springdoc and compare it with the published version in CI. What matters is not the order in which things are written but that the published contract and the running service can never disagree without a failing build.

Should events be covered too, or only HTTP APIs?

Events should be covered, and they often matter more, because a topic may have consumers the producer has never heard of. A schema in a registry with a compatibility mode, or an AsyncAPI document, gives the same protection that OpenAPI gives to HTTP: a producer cannot publish a breaking change without the check noticing.

9Conclusion

In this answer, we saw that machine-readable contracts such as OpenAPI, AsyncAPI and protobuf turn an interface description into an input for tools. Over the years they give discoverability, generated clients, compatibility checks, security review and faster onboarding, and they become an asset for audits and migrations. Their costs are tooling, review effort and the risk of paperwork, so the mandate should cover cross-team boundaries, be enforced by the build, and use standard formats with strong ecosystems.

What to say in the interviewAbout 90 seconds aloud

Open with

I would make contracts mandatory, but not everywhere in the same way. The benefits compound over years: a catalog makes APIs discoverable, consumers generate clients instead of hand-writing them, CI can diff a new version against the published one and catch breaking changes before production, security can review auth schemes and personal data from the spec, and new engineers onboard faster.

Then, if they want more

Five years later the contracts are also the inventory I need for an audit or a gateway migration. The costs are tooling, review time, and the real danger that teams treat the spec as paperwork and it drifts from the code, which is worse than having nothing.

So my rule is that a contract only counts if the build enforces it, either by generating the server from it or by generating the spec from code and checking it against the published one. I would mandate reviewed, published contracts for anything that crosses a team or goes to partners, and allow a lighter generated spec inside one team.

I would only allow standard formats with strong ecosystems, OpenAPI, AsyncAPI and protobuf, because migrating thousands of contracts out of an in-house format later would be a huge cost. Then I would roll it out with a starter that does the work, apply it on change rather than by deadline, and measure coverage and breaking changes caught.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You are deciding whether machine-readable API contracts (OpenAPI, AsyncAPI, protobuf)...": https://scrivio-interview-library.netlify.app/spring-boot/rest-api-design/d41cb4c36e/