Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Hundreds of batch jobs across teams need consistent run reports, metrics and alerting. Design how you would use Spring Batch listeners and other features to provide this as a platform capability.

We would ship a small internal starter that every batch service adds as a dependency. It registers shared job and step listeners that publish counts and durations, turns on Spring Batch's Micrometer metrics and tracing for dashboards and alerts, enforces a standard set of exit codes with an owner tag for alert routing, and writes one summary row per run to a reporting table of its own. All of it is built to fail quietly, so a reporting problem never fails a business job.

Why this question is asked

When a company has five batch jobs, every team can build its own reports by hand. When it has hundreds, run by many teams, the result is chaos: one job emails a CSV, another logs a line, a third reports nothing, and on-call engineers cannot tell whether last night's runs were healthy. Interviewers ask this design question at a senior level to see whether we can turn a framework feature into a platform capability: something teams get by default, consistent across jobs, cheap to adopt and safe. In this answer, we will set out the goals, design the shared listeners and how they attach to every job, add metrics and tracing, standardise exit codes and alert routing, store an audit summary, and make the whole thing failure tolerant.

1What the Platform Must Deliver

Before choosing classes, we should agree on the outcome. For every run of every job, we want the same facts recorded in the same way: which job, which team owns it, when it started and ended, how many items were read, written, filtered and skipped, how it ended, and why. We want dashboards that show trends across all jobs, alerts that reach the owning team rather than a shared channel, and an audit record that survives for years.

Just as important is what teams should not have to do. If adopting the platform takes more than adding a dependency and a couple of properties, adoption will stall at 30 percent. So the design goal is reporting by default, with small, explicit extension points for teams that need more.

Step throughThe batch reporting platform
  1. Dashboards and alertsone dashboard for all jobs, alerts routed by owner tag
  2. Metrics and traces backendPrometheus or similar, a tracing backend
  3. batch-platform startershared listeners, exit code rules, summary writer, auto-configuration
  4. Spring Batch with Micrometerbuilt-in job, step and item metrics and observations
  5. Team's job codereaders, processors, writers, and an owner property

5 layers, from the top down. Step through them one at a time.

Teams write only the bottom layer; everything above comes with the starter.

2Shared Listeners Delivered in a Starter

The core of the platform is a Spring Boot starter, a dependency that brings auto-configuration with it. It contains a JobExecutionListener and a StepExecutionListener written once by the platform team. The step listener reads the counters Spring Batch already keeps on StepExecution, such as getReadCount(), getWriteCount(), getFilterCount() and getSkipCount(), plus start and end times. The job listener collects the step results in afterJob and hands them to the publishers.

The interesting question is how to attach these listeners to jobs we did not write. Asking every team to call .listener(...) on every job and step is fragile, because someone always forgets. Instead, the starter registers a BeanPostProcessor that sees every Job and Step bean as it is created and adds the platform listeners to it.

Java
@AutoConfiguration
@ConditionalOnClass(Job.class)
class BatchReportingAutoConfiguration {
@Bean
static BeanPostProcessor batchReportingAttacher(ObjectProvider<RunReporter> reporter) {
return new BeanPostProcessor() {
public Object postProcessAfterInitialization(Object bean, String name) {
if (bean instanceof AbstractJob job) {
job.registerJobExecutionListener(new ReportingJobListener(reporter));
}
if (bean instanceof AbstractStep step) {
step.registerStepExecutionListener(new ReportingStepListener(reporter));
}
return bean;
}
};
}
}
// Every job in the service now reports, with no change to the team's job definitions.

Notice that the listener only gathers numbers and passes them on. Formatting, sending and storing happen in separate publishers, so we can add a new output later without touching the hook. Some job types are not subclasses of AbstractJob or AbstractStep, so the starter should log which beans it could not decorate; check your version for the exact classes.

3Metrics and Tracing With Micrometer

Spring Batch 5 is instrumented with Micrometer, the metrics library Spring Boot uses. It records timers for jobs and steps, item read and process timings, chunk write timings, and a gauge of active jobs, tagged with the job and step names and the status. It also creates observations, so with a tracing bridge on the classpath a job run becomes a trace with a span per step. Metric names such as spring.batch.job and spring.batch.step are stable in recent versions, but check your version before building dashboards on exact names.

The starter's job is to make these useful across hundreds of jobs. It adds common tags, above all the owning team and the job's criticality, through a MeterFilter, so every metric can be grouped by owner. On top of that we build one shared dashboard, with duration trends, failure rate and skip counts per job, and alert rules based on the same tags.

YAML
spring:
application:
name: billing-batch
batch-platform:
owner: team-billing # added as a tag to every batch metric and summary row
criticality: high # high pages on failure, low only opens a ticket
expected-by: "06:00" # alert if no successful run of a daily job by this time

The expected-by setting matters more than it looks. A failure alert only fires if a job runs and fails. A job that never starts, because its trigger broke, produces no failure at all, so we also need an absence alert: 'no successful run of this job since its expected time'.

4Standard Exit Codes and Alert Routing

Hundreds of jobs inventing their own exit codes make alerting impossible. The platform publishes a short list, for example COMPLETED, COMPLETED_WITH_SKIPS, FAILED_VALIDATION, FAILED_DEPENDENCY and FAILED, with a written meaning for each and the alert it triggers. The shared step listener can apply common rules itself, such as returning COMPLETED_WITH_SKIPS when the skip count is above zero, while teams return the validation codes from their own listeners.

Alert routing then becomes a table rather than custom code: a failure of a high-criticality job pages the owner tag's on-call rotation, a COMPLETED_WITH_SKIPS opens a ticket for the owner, and a missing run pages the owner if the job is high criticality. Because the owner travels with every metric and summary row, the alerting system needs no knowledge of individual jobs.

Standard exit codes and what they trigger
Exit codeMeaningAlert
COMPLETEDall items processednone
COMPLETED_WITH_SKIPSfinished, some items skippedticket to the owner
FAILED_VALIDATIONdata checks failed, nothing publishedpage owner if high criticality
FAILED_DEPENDENCYan upstream system was unavailablepage owner, link the dependency
FAILEDunexpected errorpage owner
(no run)no success by expected-by timepage owner if high criticality

5A Summary Row per Run, Kept Apart From the Job Repository

Spring Batch's own BATCH_ tables already record every execution, so why add another table? Because those tables belong to the framework. Their schema changes between major versions, teams clean them up to keep them small, each service often has its own, and they describe executions in the framework's terms rather than ours. An audit question such as 'show every run of the interest jobs in 2025 with its counts' should not depend on any of that.

So the starter writes one row per job run to a reporting table, ideally in a shared reporting database or through a message to a central collector: job name, service, owner, run id, start and end time, BatchStatus, exit code and description, and the main counters. The row is small, append-only and kept as long as audit rules require, while the BATCH_ tables can be purged after 90 days.

6Keeping Reporting From Failing Business Jobs

The most important rule of the design is that reporting is a passenger, never the driver. A metrics backend outage or a full reporting table must not fail the nightly payroll. So every publisher call in the shared listeners is wrapped in a try/catch that logs and counts the failure, writes to the summary table happen with a short timeout or asynchronously through a bounded queue, and the listeners never do per-item work.

We also give teams a clear switch to disable a single publisher by property, and the platform team gets its own metric of reporting failures, so a broken reporting path is visible to the people who own it instead of to the business. This is what lets us roll the starter out to hundreds of jobs with confidence.

7Follow-up questions

Why not let each team write their own listeners with a shared guideline?

Because guidelines drift. Within a year we would have many slightly different reports, missing tags and some jobs with nothing at all. A starter that attaches itself gives consistency for free, and teams can still add their own listeners next to it for job-specific needs.

How do we roll this out to hundreds of existing jobs?

We add the starter to the shared parent build or service template so new jobs get it automatically, then migrate existing services in waves, starting with the high-criticality jobs where alert routing pays off most. A coverage dashboard that shows which jobs report and which do not keeps the migration honest.

Should the summary row be written in the job's own transaction?

No. If the summary write shared the business transaction, a reporting failure would roll back business work, and a business rollback would hide the very run we want to record. Writing it separately, after the job finishes, keeps the two independent.

8Conclusion

In this answer, we designed batch reporting as a platform capability. A starter attaches shared job and step listeners to every job through a BeanPostProcessor, Spring Batch's Micrometer metrics and tracing feed one dashboard tagged by owner, a standard set of exit codes maps to alert routing, and a summary row per run is kept apart from the framework's job repository for audit. Throughout, the listeners stay light and failure tolerant, so reporting can never fail the business jobs it reports on.

What to say in the interviewAbout 80 seconds aloud

Open with

I would make reporting something teams get by adding one dependency. The platform team writes a Spring Boot starter with a shared JobExecutionListener and StepExecutionListener that read the counters Spring Batch already keeps, read, write, filter and skip counts and durations, and publish them.

Then, if they want more

The starter attaches them to every Job and Step bean with a BeanPostProcessor, so nobody has to remember to register them. Spring Batch 5 is already instrumented with Micrometer for job and step timers and observations, so I turn that on, add owner and criticality tags through a MeterFilter, and build one dashboard and alert rules on those tags.

I also add absence alerts, because a job that never starts produces no failure. Then I standardise a short list of exit codes like COMPLETED_WITH_SKIPS and FAILED_VALIDATION, each mapped to an alert type routed to the owning team.

For audit I write one summary row per run to a reporting table of our own, separate from the BATCH tables, which change with versions and get purged. Finally, every publisher is wrapped so failures are logged and counted, with timeouts or async sending, because a reporting outage must never fail a business job.

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 Batch reference
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 "Hundreds of batch jobs across teams need consistent run reports, metrics and alerting....": https://scrivio-interview-library.netlify.app/spring-boot/spring-batch/5177b035ed/