Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Validation and business errors are often reported as 500 in older services, which hides real failures in dashboards. How would you change this across the company and measure the effect?

I would first agree on a short, company-wide rule for which failures are the client's fault (4xx) and which are ours (5xx), then ship it as a shared error-handling library so validation and domain exceptions map to the right status everywhere. Once 5xx means a real server failure, we can base alerts and SLOs on the 5xx rate and latency. During the migration we measure the share of 5xx responses caused by client errors, starting with the services whose alerts are noisiest, and we know we are done when that share is near zero and the pages that wake people up are real.

Why this question is asked

When a missing field and a database outage both produce a 500, the error dashboard turns into noise. On-call engineers learn to ignore alerts, real incidents hide behind validation failures, and the error budget of an SLO is spent by clients sending bad requests. Clients also suffer: many retry on 5xx, so a bad request gets sent three times. Interviewers ask this at a senior level because the fix is partly technical and partly organisational: it needs a shared definition, a shared library, a migration plan and a metric that shows progress. In this answer, we will walk through why old services do this, define the classification, build the shared handler, fix the alerting, and plan and measure the rollout.

1Why Older Services Report Client Errors as 500

In a Spring application, any exception that no handler maps to a status becomes a 500. Older services often throw IllegalArgumentException or a home-made BusinessException for a bad request, and nothing maps those. Services that use @Validated on the class get ConstraintViolationException, which Spring Boot does not map to 400 by default, so it becomes a 500. Hand-written catch blocks that wrap everything in RuntimeException make it worse, because the original meaning is lost.

Nobody chose this. It is the default outcome of a framework that cannot know which exceptions are the client's fault. That is why the fix has to be a deliberate decision, made once and applied everywhere, rather than a code review comment in each team.

2Defining What Is a Client Error and What Is a Server Error

The rule is simple to say: a 4xx means the client can fix it by changing the request, and a 5xx means the client did nothing wrong and should try again later or call us. We write it down as a one-page standard with the common cases, because people decide faster with examples than with principles. Business rule violations deserve particular care. An order that exceeds the credit limit is not malformed, but the client still cannot get a different result by retrying, so it is a 4xx (we use 422 or 409 consistently), never a 500.

Company error classification
SituationStatusWhose problem
Malformed JSON, wrong type400Client
Field validation failed400Client
Not logged in / not allowed401 / 403Client
Resource does not exist404Client
Business rule broken (credit limit)422 or 409Client
Rate limit exceeded429Client
Bug, null pointer, unexpected state500Us
Dependency down or timed out502 / 503 / 504Us
Everything above the line can be fixed by changing the request; everything below cannot.

3Shipping the Rule as a Shared Library

A standard that every team implements by hand will be implemented thirty different ways. So the platform team ships it as a Spring Boot starter: an auto-configured @RestControllerAdvice that maps the standard validation exceptions to 400 with a consistent body, maps a small hierarchy of domain exceptions to their statuses, and maps everything else to 500. Teams adopt it by adding a dependency and, where needed, making their own business exceptions extend the shared base classes.

Java
// In the shared starter
public abstract class ClientException extends RuntimeException { // 4xx family
protected ClientException(String code, String message) { super(message); this.code = code; }
public abstract HttpStatus status();
...
}
public class BusinessRuleException extends ClientException {
public HttpStatus status() { return HttpStatus.UNPROCESSABLE_ENTITY; } // 422
}
@RestControllerAdvice
class SharedErrorAdvice extends ResponseEntityExceptionHandler { // already maps MVC validation to 400
@ExceptionHandler(ConstraintViolationException.class)
ProblemDetail constraint(ConstraintViolationException e) { return validationProblem(e); } // 400, was 500
@ExceptionHandler(ClientException.class)
ProblemDetail client(ClientException e) { return problem(e.status(), e.code(), e.getMessage()); }
@ExceptionHandler(Exception.class)
ProblemDetail unexpected(Exception e) {
log.error("Unhandled exception", e); // only real failures are logged as errors
return ProblemDetail.forStatus(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

Notice that the library also changes logging. Client errors are logged at INFO or WARN without a stack trace, and only the unexpected branch logs at ERROR. That alone cleans up log-based alerts, because a validation failure no longer looks like an incident in the logs either.

4Fixing Alerts and SLOs Once 5xx Means Something

An SLO, a service level objective, is a target such as 99.9 percent of requests succeed within 300 ms over 30 days. Its error budget is the 0.1 percent that may fail. If client mistakes count as failures, a single misbehaving client can spend the whole budget and freeze releases for a problem that is not ours. After the fix, we define availability as the share of requests that are not 5xx and latency on the requests we served, and we alert on fast burn of that budget.

Spring Boot's http.server.requests metric already has the tags we need: status, outcome (CLIENT_ERROR or SERVER_ERROR) and exception. So the alert query becomes the rate of outcome SERVER_ERROR divided by all requests, and a separate, non-paging dashboard watches 4xx rates, because a sudden rise in 400s after a release can still mean we broke a client.

5Measuring the Migration

We need a number that shows progress before every service is fixed. The best one is the share of 5xx responses that were really client errors. We can compute it today, before changing anything, from the exception tag: every 500 whose exception is ConstraintViolationException, MethodArgumentNotValidException, IllegalArgumentException from input parsing, or a known business exception is misclassified. For a typical older service, this share is often the majority of its 500s; suppose service A has 1,200 500s a day and 900 of them are validation failures, a 75 percent misclassification rate.

We publish that number per service on one dashboard, together with the number of pages per week and the share of pages that led to real action. Those three numbers tell the story to engineering leadership: misclassification goes from 75 percent to near zero, pages drop, and the pages that remain are acted on.

Step throughMigration plan
  1. Measure misclassified 5xx per servicefrom the exception tag on http.server.requests
  2. Agree the classification standardone page, with examples
  3. Ship the shared starteradvice, exception base classes, logging
  4. Fix the noisiest services firstmost pages and highest misclassification
  5. Misclassification under 5 percent?
    YesSwitch alerts and SLOs to 5xxNoFix the remaining exception types
  6. Make the starter the defaulttemplates and new services get it

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

We start where the noise costs the most and switch alerting only when the signal is clean.

6Prioritising and Leading the Rollout

We do not ask forty teams to change at once. We rank services by the pain they cause: pages per week, misclassification rate and the number of clients that retry on 5xx. The top five usually account for most of the noise, and fixing them first gives a visible win within a few weeks, which makes the case for the rest. We pair with those teams rather than sending them a ticket, and we turn what we learn into the starter's documentation.

There is one risk to manage openly: changing a 500 to a 400 is a visible change for clients. A client that retried on 500 will stop retrying, which is what we want, but a client that checked for 500 to show a message will behave differently. We announce the change per API, and for external APIs we roll it out behind a version or a flag. Finally, we make the starter part of the service template and add a check in CI that fails when a service maps ConstraintViolationException to 500, so the problem cannot come back.

7Follow-up questions

Should a business rule violation be 400, 409 or 422?

The exact code matters less than consistency. Many companies use 400 for malformed or invalid input, 409 for conflicts with the current state (a duplicate order, a version mismatch) and 422 for well-formed requests that break a business rule. Whatever we pick, it goes into the standard with examples so every team chooses the same way.

Will hiding client errors from alerts make us miss real problems?

Not if we keep watching them separately. A spike of 400s after our own release often means we broke a client, so we keep a 4xx dashboard and a low-urgency alert on sudden changes. The point is only that client errors should not page someone at night or spend the availability error budget.

How do we stop the problem from coming back?

By making the right behaviour the default: the starter is in the service template, the base exception classes make the right status the easy choice, and an automated check flags 500 responses whose exception is a known client error. The misclassification dashboard stays in place, and a rise in it is reviewed like any other regression.

8Conclusion

In this answer, we saw that older services report client errors as 500 simply because nothing maps those exceptions, and that the fix has two halves. Technically, we define one classification of 4xx and 5xx, ship it as a shared starter with an advice, exception base classes and quieter logging, and then base alerts and SLOs on 5xx rate and latency. Organisationally, we measure the share of misclassified 5xx per service, start with the noisiest services, announce the visible status changes to clients, and make the starter the default so the problem does not return.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by measuring, because the exception tag on Spring's http.server.requests metric already tells us how many 500s are really validation or business errors. For a typical older service that is often most of them.

Then, if they want more

Then I would agree a one-page classification with the teams: 4xx when the client can fix the request, including business rule violations as 422 or 409, and 5xx only when we failed.

That standard ships as a shared Spring Boot starter with a controller advice that maps validation exceptions, ConstraintViolationException and a small hierarchy of client exceptions to the right status, maps everything else to 500, and logs client errors without stack traces.

I would roll it out to the five services with the noisiest alerts first, pairing with those teams, and publish a dashboard per service with the misclassified 5xx share, pages per week and how many pages led to action.

When a service's misclassification drops under a few percent, we switch its alerts and SLOs to 5xx rate and latency, and keep a separate low-urgency view of 4xx so we still notice when we break a client.

I would announce the status changes per API, because clients that relied on 500 will behave differently, and finally put the starter into the service template with a CI check so new services start right.

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 "Validation and business errors are often reported as 500 in older services, which hides...": https://scrivio-interview-library.netlify.app/spring-boot/error-handling/fa9645b5de/