Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

How do you build an organisation-wide culture where errors are handled consistently and are useful for operations, not only for API clients?

I would define error codes, logging and alerting as one standard rather than three, so every error has a code, a log line and a metric that agree. Every error response carries a correlation id that leads straight to the logs and the trace, expected business errors are counted separately from unexpected failures, incident reviews always ask whether error handling helped or hurt, and shared libraries and examples make the standard the easiest thing to do.

Why this question is asked

Most teams design error handling for the API client: a status code and a message. Operations needs something else from the same moment: the on-call engineer at 2 a.m. needs to know whether this is a real failure, how many users it affects and where in the logs the cause is. When these needs are handled separately, we get APIs with neat error bodies and dashboards full of noise. Interviewers ask this leadership question to see whether we can change how many teams behave, not just write a good handler. In this answer, we will look at an example of the gap, then go through a joint standard, correlation ids, separating business errors from failures, learning from incidents, and making the right way easy.

1The Gap: Errors That Help Clients but Not Operations

Picture a typical incident. The payment service starts returning errors at 02:10. The dashboard shows 4,000 errors per minute, but that number always includes 3,500 refused cards, which are normal. The logs contain thousands of lines that say only Internal error, at three different log levels, with no link between a client complaint and a log line. It takes the on-call engineer two hours to find that one downstream timeout started it.

Nothing in that story is a bug in a handler. Each team made reasonable local choices. The problem is that nobody decided, for the whole organisation, what an error must carry so that the people running the system can use it. That decision is the leadership work.

2One Standard for Codes, Logging and Alerting

The first step is a short standard, written with the teams that will follow it, that treats codes, logs and alerts as one design. Each error belongs to a category, and the category decides everything else: the HTTP status, the log level, whether a stack trace is logged, which metric is incremented and whether it can page someone.

One row per error category
CategoryStatusLogMetricAlert
validation400DEBUG, no stack traceclient_errorsnever
business rule (card_declined)409 or 422INFO, no stack tracebusiness_outcomesonly on unusual rate
not found404DEBUGclient_errorsnever
dependency failure502, 503, 504WARN or ERROR with causefailurespage above threshold
bug (unexpected exception)500ERROR with stack tracefailurespage above threshold
Decided once, so every service logs and counts the same error the same way.

Writing these rules together is what makes them consistent. A refused card is a business outcome: it gets a stable code like card_declined, a 422, an INFO log without a stack trace and a business metric, and it never pages anyone. A database timeout is a failure: 503, ERROR with a stack trace, the failure metric, and a page if the rate crosses the threshold.

3A Correlation Id on Every Error Response

A correlation id, usually the trace id from distributed tracing, is the bridge between what the client saw and what operations can search. With Micrometer Tracing in Spring Boot, the trace id is already in the logging context (MDC), so every log line for a request carries it. The standard requires the same id in every error body.

Java
// in the shared error advice
pd.setProperty("traceId", tracer.currentSpan() != null
? tracer.currentSpan().context().traceId() : "none");
// client sees: {"status": 503, "code": "upstream_timeout", "traceId": "4bf92f3577b34da6"}
// support finds: every log line and span with traceId=4bf92f3577b34da6, across all services

When a customer reports a problem with that id, support goes directly to the full story across every service the request touched. The id costs nothing to add and turns a vague complaint into a two-minute lookup.

4Separate Expected Business Errors From Failures

The number that should wake people up is the rate of unexpected failures, not the total number of error responses. If business outcomes like a declined card or a duplicate order are counted together with timeouts, the failure signal drowns in normal behaviour. Spring Boot's http.server.requests metric already tags each request with an outcome of CLIENT_ERROR or SERVER_ERROR and the exception name, and the standard adds a counter tagged with the error code and category.

Alerting then follows simple rules. Service level objectives are measured on failures only, for example fewer than 0.5% of requests ending in 5xx over five minutes. Business outcomes get dashboards and, at most, anomaly alerts, such as declined cards suddenly tripling, which might mean a partner is down. This also changes a habit: a team can no longer return 500 for a business rule, because it would show up as a failure in its own objectives.

5Review Incidents for Error-Handling Gaps

Standards stay alive through feedback. Every incident review gets one fixed question: did our errors, logs and alerts help us find the cause quickly, and if not, what was missing? The answers are concrete: a swallowed exception, a 500 that should have been a 503 with a retry hint, an alert that fired on business outcomes, a missing trace id in an async consumer. Each gap becomes an action item, and gaps that repeat across teams become a change to the shared library, so one fix reaches every service.

Step throughHow an incident improves the standard
  1. Incident happenson-call uses errors, logs and alerts
  2. Review asks: did errors help?
  3. Gap found in one service?
    Yesfix it there, add a testNostandard is fine
  4. Same gap in other teams?
    Yeschange the shared libraryNoclose the action
  5. Release library, track adoption

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

6Make the Right Way the Easy Way

A standard on a wiki changes little. What changes behaviour is a shared starter that a service adds as a dependency and that already does the right thing: the ProblemDetail format with code and trace id, the category-based logging, the metrics and the base exception types. We pair it with a reference service that shows the patterns in real code, a page of examples for the common cases and a review checklist.

As a leader I would also measure adoption openly, for example the share of services on the current starter version and the number of 500s without an error code, and give teams time in their plans to migrate. People follow the standard when following it is less work than not following it.

7Follow-up questions

How do you get teams to adopt the standard without forcing it?

By making it cheaper than the alternative and showing the benefit. The starter removes code teams would otherwise maintain, and the first teams to adopt it are those with recent painful incidents, whose story persuades others. For the remaining teams, we agree a deadline for external APIs and keep internal ones on a gentler path.

Should every error be logged?

Every error should be counted, but not every error deserves a log line at the same level. Validation failures and not-found results are normal traffic; logging them at ERROR with stack traces fills disks and hides real problems. The standard logs failures in full, business outcomes briefly, and client errors at DEBUG, while metrics count all of them.

What about errors in asynchronous processing, such as Kafka consumers?

The same categories apply. A consumer logs with the trace id carried in the message headers, counts the error by code, and sends unprocessable messages to a dead-letter topic. Retryable failures and poison messages are kept apart in the metrics, just like failures and business errors in HTTP.

8Conclusion

In this answer, we treated error handling as something that serves operations as much as clients. We wrote one standard that decides status, log level, metric and alerting per error category, required a correlation id in every error response, separated business outcomes from unexpected failures so alerts track real problems, used incident reviews to find gaps and fix them in the shared library, and made the standard easy to follow with a starter, examples and visible adoption metrics.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd start from the fact that an error has two audiences: the client, who needs to know what to do, and operations, who need to know whether something is broken and where.

Then, if they want more

So I'd write one standard, with the teams, that covers error codes, logging and alerting together. Each error category decides the status, the log level, whether we log a stack trace, which metric it increments and whether it can page.

A declined card is a business outcome, a 422 with an INFO log and a business counter, while a database timeout is a 503, logged at ERROR and counted as a failure.

Every error body carries the trace id, which Micrometer Tracing already puts in our logs, so support can go from a customer report to the full trace in minutes. Our objectives and paging use only unexpected failures, so normal business errors don't drown the signal.

Every incident review asks whether our errors helped, and repeated gaps become fixes in the shared library. Finally, I'd make the right way the easy way: a starter that produces the format, logging and metrics by default, a reference service, and an adoption dashboard, plus real time in team plans to migrate.

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 "How do you build an organisation-wide culture where errors are handled consistently and...": https://scrivio-interview-library.netlify.app/spring-boot/error-handling/c83c4ca978/