Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Async code across your teams handles errors inconsistently: some chains swallow exceptions, others log the same failure at every stage, and alerts show CompletionException with no root cause. Define conventions for error handling in async chains and how you would roll them out.

I would set a few simple conventions. Every future must be observed, either returned to a caller or ended with a handler that records the error. A failure is logged once, at the boundary that decides what to do with it, not in every stage. CompletionException and ExecutionException are always unwrapped before logging and classifying, and every failure is counted as a metric tagged with its root cause type. I would roll this out through shared helper methods, review checklist items and static checks, starting with the services that page most often.

Background to this question

Inconsistent error handling in async code is expensive in a way that is easy to miss: alerts fire without useful information, real failures hide, and on-call engineers spend the first half hour of each incident finding the actual exception. Fixing it is less about one clever technique and more about agreeing on rules and making them easy to follow. In this answer, we will look at why async errors drift into these three bad patterns, define the conventions and the reason for each, show the shared helpers that make them cheap to follow, and plan a rollout that teams will actually adopt.

1Why Async Error Handling Drifts

In synchronous code, an exception travels up the call stack until someone catches it, and an uncaught one at least reaches a framework that logs it. CompletableFuture changes this. A failure becomes a value stored in a future. If nobody observes that future, the failure vanishes silently. If many stages observe it, each one may log it. And when a dependent stage fails, the exception is wrapped in CompletionException, so code that logs the exception directly shows the wrapper rather than the cause.

So the three symptoms in the question, swallowed errors, duplicate logs and alerts showing only CompletionException, all come from the same mechanism. Each team found its own workaround, which is why the code base is inconsistent. A shared convention replaces those workarounds with one way.

Symptoms and their cause
What we seeWhy it happensConvention that fixes it
Missing work, no error loggedfuture discarded, failure stored in itevery future is observed
Same stack trace 4 timeswhenComplete logging in each stagelog once, at the boundary
Alerts say CompletionExceptionwrapper logged instead of the causeunwrap before logging
No idea how often it failsfailures only in logscount failures by root cause type

2Convention 1: Every Future Is Observed

A future is either returned to the caller, who then owns its outcome, or it ends in a handler that records the failure. A fire-and-forget call like CompletableFuture.runAsync(task) with the result ignored is not allowed unless it ends in such a handler. The reason is simple: a failure stored in an unobserved future can never be seen by anyone, so data loss happens with no trace.

This rule is easy to check. Static analysis tools can flag ignored return values of methods returning CompletableFuture, and many teams already enable that check for other types. We turn it on as an error for our own code.

3Convention 2: Log Once, at the Deciding Boundary

Each failure is logged exactly once, by the code that decides what to do about it: return an error to the user, use a fallback, or give up on a background job. Intermediate stages either recover, or let the failure pass unchanged, or wrap it with added context and rethrow. They do not log. The reason is that one failure should produce one log line and one alert count. With logging in every stage, a single failure produces several stack traces, counts are inflated, and engineers cannot tell one failure from four.

4Conventions 3 and 4: Unwrap, Then Count by Root Cause

Before any code classifies an error or logs it, it unwraps CompletionException and ExecutionException to reach the real cause. Then it records a metric with the root cause type as a tag, so dashboards show, for example, that 80 percent of failures for the pricing dependency are SocketTimeoutException. Logs tell us about one failure; metrics tell us about the trend and drive alerts.

We put both in a shared library so nobody writes them by hand. The helpers below are small, and that is the point: if the right way is one method call, people use it.

Java
public final class AsyncErrors {
public static Throwable rootCause(Throwable ex) {
while ((ex instanceof CompletionException || ex instanceof ExecutionException) && ex.getCause() != null)
ex = ex.getCause();
return ex;
}
/** Ends a fire-and-forget future: logs once and counts the failure. */
public static <T> void observe(CompletableFuture<T> f, String operation, MeterRegistry m) {
f.whenComplete((v, ex) -> {
if (ex == null) return;
Throwable cause = rootCause(ex);
log.error("{} failed", operation, cause);
m.counter("async.failures", "operation", operation, "cause", cause.getClass().getSimpleName()).increment();
});
}
}
AsyncErrors.observe(CompletableFuture.runAsync(() -> audit.send(e), auditExecutor), "audit.send", meters);
// log: audit.send failed java.net.SocketTimeoutException: Read timed out
// metric: async.failures{operation=audit.send, cause=SocketTimeoutException} 1

Notice that the metric uses a fixed operation name and the exception's class name as tags, never the message or an id, because tags with unbounded values would overload the metrics system.

5Rolling the Conventions Out

Conventions only help if teams adopt them, and a big-bang rewrite rarely succeeds. I would start by writing the four rules on one page with a short example for each, and agree them with the tech leads of the teams that own the most async code, so the rules are theirs too. Next, the shared library with rootCause, observe and a few chain helpers goes into the common platform dependency.

Then we add the rules to the review checklist, with concrete questions such as: is every future either returned to the caller or observed, and does this chain log anywhere except at its end? We enable static analysis for ignored futures, first as a warning so teams can see their count, then as an error for new code. Finally, we fix existing code where it hurts most: services whose alerts most often show CompletionException are the first candidates, because there the change visibly shortens incidents.

We measure progress with numbers people care about: the share of alerts whose root cause type is known, the count of ignored-future warnings per service, and duplicate log lines per failure. When those numbers improve, the conventions sell themselves.

Step throughRollout plan
  1. Agree four rules with tech leadsone page, one example each
  2. Ship helpers in the platform libraryrootCause, observe, chain helpers
  3. Add review checklist itemsobserved? logged once? unwrapped?
  4. Static check for ignored futureswarning first, then error for new code
  5. Fix the noisiest services firstwhere alerts show only CompletionException
  6. Track known-cause alert shareprogress visible to every team

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

6Follow-up questions

Why not log in every stage just to be safe?

Because it is not safer, only noisier. One failure becomes several log entries and alert counts, and on-call engineers cannot tell whether there was one problem or four. Logging once at the deciding boundary, with context added by wrapping along the way, gives one complete entry per failure.

What if a team uses Reactor instead of CompletableFuture?

The same four rules apply in different words: every publisher is subscribed or returned, errors are logged once at the edge with doOnError only there, wrapped exceptions are unwrapped, and failures are counted. The shared library can offer an equivalent helper for Reactor.

How do you handle teams that disagree with a rule?

Ask for the concrete case. Often the disagreement reveals a missing helper or an unclear rule, for example a background job that has no boundary. Adjust the rule or add the helper, and keep the decision documented, rather than allowing silent exceptions.

7Conclusion

In this answer, we saw that swallowed exceptions, duplicate logs and alerts showing only CompletionException all come from failures being stored in futures. The conventions are that every future is observed, each failure is logged once at the boundary that decides what to do, wrapper exceptions are unwrapped before logging and classifying, and failures are counted by root cause type. Shared helpers make the rules cheap to follow, and checklist items, static checks and a rollout that starts with the noisiest services make them stick.

What to say in the interviewAbout 90 seconds aloud

Open with

All three symptoms come from the same thing: in CompletableFuture a failure is a value stored in a future. If nobody observes the future, it vanishes; if every stage observes it, it is logged many times; and because dependent stages wrap it in CompletionException, logs show the wrapper.

Then, if they want more

So I would define four conventions. First, every future is observed: it is either returned to the caller or ends with a handler that records the failure, and fire-and-forget without a handler is not allowed.

Second, a failure is logged once, at the boundary that decides what to do with it, like the controller or the job runner; intermediate stages recover, pass the failure on, or wrap it with context, but do not log. Third, we always unwrap CompletionException and ExecutionException before logging and classifying.

Fourth, every failure increments a metric tagged with the operation and the root cause type, so we can alert on trends.

To roll it out, I would agree the rules with the tech leads, put small helpers like rootCause and observe in the shared platform library, add checklist items to code review, and turn on a static check for ignored futures, as a warning first.

Then I would fix the services whose alerts show CompletionException most often, and track the share of alerts with a known root cause to show progress.

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 "Async code across your teams handles errors inconsistently: some chains swallow...": https://scrivio-interview-library.netlify.app/java/completable-future/e008becf35/