Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Error contracts outlive the services that produce them. How would you govern error codes across a company for many years so that clients can rely on them?

I would keep a central registry of error codes, each with an owner, a description and the APIs that use it. Codes are never reused for a different meaning, adding codes is always allowed, and changing a code's meaning is treated as a breaking change. Codes are documented in the API specs and the developer portal, and the registry is reviewed periodically so unused codes are deprecated and retired with notice rather than silently removed.

Why this question is asked

Clients write code against error codes: if the response says insufficient_funds, show the top-up screen. That client code may run for ten years, long after the team that created the code has been reorganised and the service rewritten twice. If a code quietly changes meaning, or disappears, clients break in ways nobody notices until customers complain. Interviewers ask this leadership question to see whether we can design governance that outlives teams and services. In this answer, we will look at why codes need governance, then set up the registry, the rules for adding and changing codes, documentation, and the periodic review.

1Why Error Codes Need Governance

An error code is a promise: whenever this situation happens, you will see this code, and this code only means this situation. Services keep the first half of the promise through tests. The second half is harder, because it spans teams and years. A new team building a payment service may invent card_declined for a slightly different situation than the old one, or reuse LIMIT_EXCEEDED for a rate limit when it meant a spending limit. Each decision looks local, but clients see one company API.

So the codes must be managed as a shared vocabulary with rules, not as constants scattered across 80 code bases. That is what governance means here: a single source of truth, clear rules and a light process that people actually follow.

2A Registry With Owners and Descriptions

The registry is a small repository, a file per code or one structured file, reviewed through pull requests. Each entry records the code, its meaning in one or two sentences, the HTTP status, whether it is retryable, the owning team, the APIs that use it, and its lifecycle state.

YAML
# registry/errors/insufficient_funds.yaml
code: insufficient_funds
status: 422
retryable: false
owner: payments-platform
description: >
The account balance is lower than the requested amount at the time of the request.
Clients should ask the user to add funds or choose another account.
apis: [payments-v1, transfers-v2]
state: active # proposed -> active -> deprecated -> retired
since: 2024-03-11
Lifecycle of an error code
StateMeaningWho can see it
proposedunder review in a pull requestregistry reviewers
activemay be emitted by any listed APIeveryone, documented
deprecatedstill emitted, scheduled for removal on a datedocumented with the date
retirednever emitted again, and never reusedkept in the registry as history
Retired codes stay in the registry forever so their names can never be reused.

From this file we generate the documentation pages, the constants used by the shared error library, and a check that every code a service emits exists in the registry. Generating from one source is what keeps the registry true; a registry that is only a wiki page goes stale within months.

3The Rules: Add Freely, Never Reuse, Never Change Meaning

Three rules carry most of the weight. First, adding a code is always allowed and cheap, because clients are told to handle unknown codes by their HTTP status. A team that needs a new situation gets a new code in a day, so nobody is tempted to stretch an old one. Second, a code is never reused for a different meaning, even after it is retired, which is why retired entries stay in the registry. Third, changing the meaning of an active code, for example widening limit_exceeded from daily limits to all limits, is a breaking change: it requires a new code, with the old one deprecated, or a new API version.

Small edits are allowed: fixing the wording of a description, adding an API to the list or improving the documentation. The review question is always the same: could a client that handles this code today do the wrong thing after this change? If yes, it is breaking.

4Document Codes Where Developers Look

Clients learn codes from two places, and both are generated from the registry. Each API's OpenAPI spec lists, per operation, the codes it can return, and the developer portal has one page per code at its type URI, such as https://developer.example.com/errors/insufficient-funds, explaining the cause and the recommended client reaction. A build check compares the codes thrown by a service's code, through the shared library's constants, with those listed in its spec, so the documentation cannot fall behind the implementation.

5Review the Registry Periodically

Once or twice a year, the registry owners review it using data, not memory. Metrics from the shared error library count how often each code is emitted per API. Codes with zero occurrences for a long period, or with owners who no longer exist, are candidates for deprecation. A deprecated code is announced in the changelog and the portal with a removal date, typically six to twelve months ahead for public APIs, and only then retired. Orphaned codes get a new owner, usually the team that now runs the service.

The review also looks for duplicates, two codes with nearly the same meaning created by different teams, and for codes whose descriptions no longer match how they are used. These are fixed through the same rules: deprecate one, document the other.

Step throughPeriodic registry review
  1. Pull usage per codefrom error metrics, last 12 months
  2. Emitted at all?
    Yescheck owner and description still accurateNopropose deprecation
  3. Deprecate with noticedate in portal and changelog
  4. Retire after the datekeep the entry, never reuse the name

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

6Follow-up questions

Who should own the registry?

An API governance or platform group owns the registry itself and the rules, while each code has a domain owner who decides its meaning. Reviews of new codes are lightweight, often one reviewer from governance and one from the domain, with a response within a day so the process does not slow teams down.

Should codes be global or per API?

A global namespace works best, with domain prefixes when it grows, such as payments.insufficient_funds. Generic codes like validation_failed and not_found are shared everywhere, and domain codes are owned by their domain. Per-API codes tend to multiply near-duplicates across a company.

How do we stop teams from emitting unregistered codes?

The shared error library only accepts codes from the generated constants, and a build check fails if a service's spec or code mentions a code that is not in the registry. Making the registered path the only easy path is more reliable than policing it in reviews.

7Conclusion

In this answer, we governed error codes as a long-lived shared vocabulary. A registry gives every code an owner, a description, a status and a lifecycle, and generates the documentation and library constants. Codes are never reused, adding them is easy, and changing their meaning is breaking. They are documented in API specs and the developer portal with checks against the implementation, and a periodic, data-driven review deprecates and retires unused codes with notice.

What to say in the interviewAbout 90 seconds aloud

Open with

Error codes are a promise clients code against for years, so I'd manage them as a shared vocabulary rather than constants in each service. I'd set up a registry, a small repository reviewed through pull requests, where each code has its meaning, HTTP status, whether it's retryable, an owning team, the APIs that use it and a lifecycle state: proposed, active, deprecated, retired.

Then, if they want more

Docs pages and the constants in our shared error library are generated from it, and a build check makes sure services only emit registered codes. The rules are simple. Adding a code is easy and fast, and clients are told to handle unknown codes by their status, so nobody stretches an old code.

A code is never reused for a different meaning, even after retirement, so retired entries stay in the registry forever. Changing an active code's meaning is a breaking change, which means a new code plus deprecating the old one, or a new API version.

Codes are documented in each OpenAPI spec per operation and on a developer portal page per code at its type URI. Once or twice a year we review the registry using emission metrics: unused codes are deprecated with a date, typically six to twelve months for public APIs, then retired, and orphaned codes get a new owner.

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 "Error contracts outlive the services that produce them. How would you govern error codes...": https://scrivio-interview-library.netlify.app/spring-boot/error-handling/542108486b/