Quick revision
The short answer
I would choose ProblemDetail as the base format with a small set of shared extension fields, and make it the default by shipping a starter with the standard advice, error codes and security handlers. Clients are protected during the change by versioning or by supporting both formats for a transition period, OpenAPI specs are linted for the shared error schema, and the migration is tracked per service, with external APIs first.
What to remember
In this answer, we planned a common error contract for 80 services. We chose ProblemDetail with shared extension fields and a fixed status mapping, shipped a starter so migration is mostly adding a dependency, protected clients with versioning or a temporary dual format, linted every OpenAPI spec for the shared schema so nobody drifts back, and tracked the migration per service with external APIs first.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would choose ProblemDetail as the base format with a small set of shared extension fields, and make it the default by shipping a starter with the standard advice, error codes and security handlers. Clients are protected during the change by versioning or by supporting both formats for a transition period, OpenAPI specs are linted for the shared error schema, and the migration is tracked per service, with external APIs first.
Why this question is asked
With 80 services and many error formats, every client and the gateway carry special cases: if this service, read message, if that one, read error.description. Each new service adds another branch, and nobody dares remove one. A common contract fixes this, but at this scale the hard part is not choosing a format, it is moving 80 teams without breaking their clients. Interviewers ask this leadership question to see how we drive a cross-team change: making a decision stick, lowering the cost for each team and tracking progress honestly. In this answer, we will choose the contract, build the starter, plan the transition for clients, add automated checks, and then run and track the migration.
1Choosing the Contract
We choose RFC 9457 problem details as the base, because Spring supports it natively, gateways and client libraries understand it, and it removes any debate about whose format wins. On top of it, a short written contract fixes the shared extensions: a stable code from a registry, a traceId, and an errors list of field, code and message for validation. It also fixes the status mapping, so that for example a business rule refusal is 422 everywhere rather than 400 in some services and 409 in others.
The decision is made with representatives of a few large teams and the gateway owners, in a short time box, and published as a one-page standard. Inviting the people who will do the work into the decision is cheaper than convincing them afterwards.
2Provide a Starter So Teams Do Little Work
A standard that each team must implement 80 times will be implemented 80 slightly different ways. Instead the platform team ships a starter: a dependency whose auto-configuration brings a low-precedence advice extending ResponseEntityExceptionHandler, a base exception type carrying code and status, the security entry point and access denied handlers, an ErrorAttributes bean for /error, consistent logging and the shared fields. For most services, migration is adding the dependency, mapping their own exceptions to codes and deleting their old advice.
We prove the starter on two or three pilot services of different shapes, for example one public API, one internal service and one with heavy validation, and fix what the pilots find before asking anyone else to adopt it.
3Protect Clients During the Transition
Changing the error body is a breaking change for any client that parses it, so we never flip a format silently. For external APIs, the new format arrives with a new API version, or the service supports both formats for a period and lets clients choose, for example with the Accept header: application/problem+json returns the new shape, application/json keeps the old one until the deprecation date.
Internal clients move faster: the shared HTTP client library learns to parse ProblemDetail, and once it does, internal consumers get the new format with a library upgrade. The gateway keeps its old special cases until the last service behind them has migrated, then deletes them.
4Lint OpenAPI Specs for the Error Schema
To stop drift, the contract becomes a machine check. The shared error schema is published once, and every service's OpenAPI spec references it for its 4xx and 5xx responses. A linter, for example a Spectral rule set run in each build, fails the build when an operation declares an error response that does not use the shared schema or uses the media type application/json instead of application/problem+json. New services therefore start compliant, and migrated services cannot slide back.
5Track the Migration and Prioritise External APIs
We track the migration per service on a visible dashboard: starter version, legacy bridge on or off, spec lint passing. The order is set by client impact. External APIs used by partners come first, because their clients are the hardest to change and suffer most from inconsistency, followed by services behind the gateway with the most special cases, and finally purely internal services.
As a leader, I would also agree the migration with team leads as planned work with a date, not an extra task squeezed between features, and report progress regularly, say from 12 of 80 services to 60 of 80 over two quarters. Teams that are blocked raise it early, and the platform team fixes the starter rather than letting each team work around it.
- Agree contract
ProblemDetail+ code,traceId, errors - Build starter, pilot on 3 services
- External API?Yesnew version or dual format with deadlineNoupgrade starter, update shared client
- Lint OpenAPI specs in every build
- Track per service, remove bridges and gateway special cases
5 steps in order. Play them, or step through them one at a time.
6Follow-up questions
What if a team refuses because their clients depend on the old format?
That is exactly what the transition support is for. The team can enable the legacy bridge and keep the old shape for its clients until a deprecation date, while its new endpoints and internal callers use the contract. The concern is valid, and the plan answers it rather than overriding it.
How long should both formats coexist?
Long enough for the slowest important client, typically six to twelve months for external partners, with the date announced at the start. Usage metrics for the old format, counting responses served in the legacy shape, show when it is safe to remove the bridge.
How do you measure success?
By the number of services fully on the contract, the number of special cases removed from the gateway and shared clients, and the lint pass rate. A good sign at the end is that adding a new service requires no change in any client's error handling.
7Conclusion
In this answer, we planned a common error contract for 80 services. We chose ProblemDetail with shared extension fields and a fixed status mapping, shipped a starter so migration is mostly adding a dependency, protected clients with versioning or a temporary dual format, linted every OpenAPI spec for the shared schema so nobody drifts back, and tracked the migration per service with external APIs first.
Open with
I'd start by agreeing the contract quickly with a few big teams and the gateway owners: ProblemDetail as the base, plus a stable code from a registry, a traceId, an errors list for validation, and a fixed status mapping.
Then, if they want more
Then I'd make adoption cheap. The platform team ships a starter with a low-precedence advice extending ResponseEntityExceptionHandler, a base exception carrying code and status, security handlers, an ErrorAttributes bean for /error and consistent logging. For most teams, migrating means adding the dependency, mapping their exceptions to codes and deleting their old advice. I'd pilot it on three different services first.
Because the body change breaks clients that parse errors, external APIs get either a new version or a transition period where both formats are served, chosen by the Accept header, with a published deadline; internal clients move via the shared HTTP client library.
To prevent drift, every OpenAPI spec references the shared error schema and a linter in the build fails non-compliant specs. Then I'd track it per service on a dashboard, external APIs first, then services behind the gateway with the most special cases, and agree the work with team leads as planned work. When it's done, we remove the bridges and the gateway's special cases.
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.
- Official documentation
- Spring Framework reference, Spring Web MVC
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 formats differ across 80 services, which makes client and gateway code complex....": https://scrivio-interview-library.netlify.app/spring-boot/error-handling/54f4a5e6bb/