Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

A production incident: a background thread that synchronised customer data died silently from an unchecked exception, and data stopped syncing for six hours before anyone noticed. You lead the incident review. What standards come out of it for all teams?

The review should produce standards, not blame: every background thread or executor has a named thread factory and an uncaught exception handler that logs and counts failures; long-running loops catch and log exceptions per iteration so one bad record cannot end the thread; each background process exposes a liveness signal such as a last-success timestamp metric with an alert; teams prefer framework-managed scheduling and executors with lifecycle and health checks over raw threads; and the checks go into review guidelines and the shared starter so every team gets them by default.

Why this question is asked

This incident has a shape every senior engineer should recognise: nothing crashed, no error page appeared, and the service looked healthy for six hours while customer data quietly stopped syncing. The technical cause is small, but the organisational lesson is large, because the same pattern exists in every team that writes background jobs. Interviewers ask how we would lead the review to see whether we can move from one bug to standards that prevent the whole class. In this answer, we will reconstruct the failure, run the review in a blameless way, and then go through each standard with the reasoning and an example, finishing with how we make the standards stick.

1Reconstructing the Failure

The sync was a raw thread started at application startup, with a loop that fetched changed customers, sent them to the downstream system, and slept. One customer record had a null field that the mapping code did not expect, and a NullPointerException escaped the loop. The exception ended the thread's run() method, so the thread died. It had no uncaught exception handler, so the default one printed the stack trace to System.err, which the service's log shipping did not collect. The rest of the application kept serving requests, health checks stayed green, and nothing measured whether syncing was still happening.

Java
new Thread(() -> {
while (true) {
for (Customer c : repo.changedSince(lastSync)) {
downstream.send(map(c)); // NPE on one bad record escapes the loop
}
lastSync = Instant.now();
sleep(30_000);
}
}).start(); // unnamed, no handler, no liveness signal
Step throughSix silent hours
Sync threadJVMMonitoringDownstream
sync batch, every 30 s
NPE on one record escapes run()
thread terminates
default handler prints to System.err
health check: UP (web layer is fine)
no metric for last successful sync
six hours with no updates

7 messages in order. Play them, or step through them one at a time.

Every layer that could have noticed was looking at something else.

2Running the Review Without Blame

We run the review blameless: the question is not who wrote the loop, but why our system allowed a background process to die without anyone knowing. That framing matters, because the author did what many teams do, and blaming them would hide the fact that the same pattern exists in other services. We build the timeline, then ask three questions. Why did one bad record stop all syncing? Why was the death invisible? Why did we find out from a customer rather than from monitoring? Each answer becomes a standard, and we check the other teams' code for the same pattern before closing the review.

3Standard 1: Named Factories and Logging Handlers

Every background thread or executor is created through a named thread factory with an uncaught exception handler that logs the thread name and exception through our logging and increments a counter tagged by thread prefix. A death then produces a log line in our aggregation and a metric we can alert on. We also set a default uncaught exception handler at startup as a safety net for threads we do not create ourselves.

Java
ThreadFactory f = Thread.ofPlatform()
.name("customer-sync-", 1)
.uncaughtExceptionHandler((t, e) -> {
log.error("Thread {} died", t.getName(), e);
registry.counter("threads.died", "prefix", "customer-sync").increment();
})
.factory();

The counter matters as much as the log line. A log line helps someone who is already looking, while a counter of thread deaths per prefix can raise an alert the moment it moves from zero, which is what was missing during the six hours.

4Standard 2: Catch per Iteration

A long-running loop must treat each unit of work as independent: catch and log exceptions per record or per batch, count them, and continue. One bad record should cost one record, not the whole process. Interruption is the exception to the rule, because it is the request to stop.

Java
for (Customer c : repo.changedSince(lastSync)) {
try {
downstream.send(map(c));
} catch (RuntimeException e) {
log.warn("Sync failed for customer {}", c.id(), e);
failures.increment();
deadLetters.save(c.id(), e); // keep it for a retry or a human
}
}

Notice the dead-letter record. Catching per iteration without keeping the failures just turns a loud failure into a quiet one, so failed records must go somewhere visible.

5Standard 3: A Liveness Signal for Every Background Process

Logging and handlers detect a dead thread, but not a thread that is alive and stuck, or one that runs but makes no progress. So every background process exposes a last-success timestamp, updated after each successful cycle, as a gauge. The alert fires when the time since the last success exceeds a threshold derived from the schedule, for example three cycles. For a 30-second sync, an alert after 2 minutes would have turned six hours into two minutes. The same signal can feed a Spring Boot health indicator so that dashboards show the sync as down, not only the web layer as up.

Step throughHow each layer now catches the failure
  1. Bad recordcaught per iteration, dead-lettered, loop continues
  2. Unexpected deathhandler logs and counts by prefix
  3. Stuck or no progresslast-success age exceeds 3 cycles
  4. Alert to the owning teamwithin minutes, not hours

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

6Standard 4: Prefer Framework-Managed Scheduling

Raw threads have no lifecycle, no health and no standard error handling. A @Scheduled method on Spring's ThreadPoolTaskScheduler, or a ScheduledExecutorService created through the platform's factory, gets named threads, orderly shutdown and error handling. With @Scheduled, Spring's scheduler logs an exception from one run by default and the next run still happens, unlike a raw scheduleAtFixedRate(), which silently cancels all future runs when one throws (check your Spring version for the default error handler details). For work that must not be lost or must run on exactly one instance, a job framework with persistent state is better still.

7Standard 5: Make the Right Thing the Default

Standards that live only in a document are forgotten within a quarter. So we put them in two places teams cannot miss. The review guidelines get a short checklist for any background work: named factory, handler, per-iteration catch, liveness metric with alert, framework scheduling. The shared Spring Boot starter provides the factory helper, the default handler, a BackgroundJob base type that records the last-success gauge and health automatically, and alert templates. A static check flags raw new Thread() in production code. We then track adoption across services and report it with the incident follow-ups, so the work is visible until it is done.

8Follow-up questions

Why not just restart the thread automatically when it dies?

A supervisor that restarts it helps availability, and some teams do that, but without the other standards it can hide a crash loop: the thread dies on the same bad record every 30 seconds forever. Per-iteration handling fixes the cause, and the liveness metric catches anything else.

How do you choose the liveness alert threshold?

From the schedule and the tolerance of the business. For a 30-second sync, alerting after about three missed cycles avoids noise from one slow run, and the business owner confirms whether two minutes of delay is acceptable.

How do you make sure other teams adopt the standards?

By making them the default in the starter, adding them to review guidelines, and running a quick scan of all services for raw threads and background loops right after the review, with a tracked list of follow-ups per team.

9Conclusion

In this answer, we reconstructed how a single bad record killed an unnamed background thread whose death went to System.err and was never measured. We ran a blameless review and turned each gap into a standard: named factories with logging and counting handlers, catching exceptions per iteration, a last-success liveness metric with an alert, framework-managed scheduling instead of raw threads, and defaults in the shared starter and review guidelines so every team gets them automatically.

What to say in the interviewAbout 90 seconds aloud

Open with

I'd run it as a blameless review and focus on why our system let a background process die silently, because the same pattern almost certainly exists in other teams.

Then, if they want more

The facts were: one bad record threw a NullPointerException out of a raw thread's loop, the thread died, the default handler printed to standard error which we don't ship, health checks stayed green because they only looked at the web layer, and nothing measured whether syncing was happening. Five standards come out of that.

One, every background thread or executor uses a named thread factory with an uncaught exception handler that logs through our logger and increments a counter by thread prefix, plus a default handler at startup.

Two, long-running loops catch exceptions per iteration, log and count them, and put the failed record in a dead-letter store, so one bad record costs one record.

Three, every background process publishes a last-success timestamp with an alert, for example after three missed cycles; that alone would have turned six hours into two minutes, and it also catches threads that are alive but stuck. Four, we prefer framework scheduling like @Scheduled or platform executors, which have names, lifecycle and error handling, over raw threads.

Five, we make it the default: a background job helper in the shared starter that does all this automatically, a checklist in review guidelines, a static check for raw threads, and tracked follow-ups across teams.

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 "A production incident: a background thread that synchronised customer data died silently...": https://scrivio-interview-library.netlify.app/java/threads/8ec4d32758/