Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Teams across your organisation keep adding @Scheduled jobs inside request-serving services, which caused incidents when jobs competed with traffic or ran on every replica. What guidance would you set?

I would set guidance that classifies scheduled work first: light, short housekeeping may stay inside services, while heavy or business-critical jobs move to a batch platform or a Kubernetes CronJob. In-service jobs must be idempotent and protected by a distributed lock, run on their own bounded thread pool and connection budget, and come from a shared starter that adds ShedLock, metrics and missed-run alerts. Every scheduled job is listed in a central inventory with an owner.

Why this question is asked

Incidents caused by scheduled jobs are frustrating because they are rarely a single bug. A team adds a nightly recalculation to a request-serving service, it works in testing, and in production it runs on all eight replicas at once and saturates the database while customers are trying to check out. A different team hits the same problem a month later. Interviewers ask senior engineers this kind of question to see whether they can turn incident lessons into guidance that teams will actually follow, rather than a rule that bans something useful. In this answer, we will understand the two failure modes, classify scheduled work, define the rules for jobs that stay in services, provide a starter that makes the rules easy, isolate resources, and make jobs visible.

1Understanding the Two Failure Modes

The incidents fall into two groups, and the guidance has to address both. The first is competition with traffic. A scheduled job in a serving service shares that service's CPU, memory, database connection pool and downstream rate limits with user requests. Scheduled tasks run on scheduler threads, not request threads, but a job that takes 15 of the 20 connections in the pool leaves requests waiting for a connection, and that looks like an outage to customers.

The second is running on every replica. @Scheduled has no idea how many copies of the service exist, so a job written for one instance runs on all of them. At best that wastes work; at worst it sends duplicate emails or double-applies changes. Both failure modes come from treating an in-process scheduler as if it were a job platform.

2Classify the Work First

A blanket ban on @Scheduled would be wrong: refreshing an in-memory cache every minute or evicting expired sessions belongs in the service, and moving it elsewhere would only add complexity. So the first part of the guidance is a short classification that any engineer can apply in a design review.

Light housekeeping is short, cheap, local or idempotent, and failing one run is harmless. It can stay in the service, with the rules in the next section. Heavy or critical work is anything that runs for minutes, scans large tables, sends messages to customers, moves money or must be audited. It belongs on a batch platform, such as a Spring Batch service, or in a Kubernetes CronJob, where it runs in its own process with its own resources, history and alerting.

Step throughWhere should this scheduled job run?
  1. Does it touch customers, money or regulated data?
    Yesbatch platform or CronJobNonext question
  2. Does a run take more than about a minute or scan large tables?
    Yesbatch platform or CronJobNonext question
  3. Does it only touch this instance's memory?
    Yesin-service @Scheduled, no lock neededNoin-service with a lock
  4. In-service rules applyidempotent, locked, own pool, in the inventory

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

Two questions decide most cases; the rest is housekeeping that may stay.

3Rules for Jobs That Stay in Services

Work that stays must be safe on many replicas. The rule is two-fold: the job must be idempotent, so a repeat changes nothing, and it must take a distributed lock if running it on several replicas at once would be wasteful or wrong. The lock prevents the routine duplicate; idempotency covers the rare case where the lock fails, such as a lock that expires during a slow run.

Jobs that only touch the instance itself, such as refreshing a local cache, are the exception: they should run on every replica, and a lock would be a bug. The guidance should say this explicitly, because otherwise teams lock everything out of caution.

4A Starter That Makes the Right Thing Easy

Guidance that requires every team to wire ShedLock, metrics and alerting by hand will be followed by a third of them. So the platform team provides a Spring Boot starter. It auto-configures a ShedLock lock provider on the service's database, sets a sensible default lockAtMostFor, wraps every scheduled method with metrics for duration, success and failure tagged with the job name and owner, and publishes a 'last successful run' timestamp per job.

From that timestamp, the shared alerting rules raise a missed-run alert when a job has not succeeded within its expected interval. Missed runs are the failure nobody notices otherwise, because a job that never starts produces no error. With the starter, a team adds one dependency and one annotation, and gets locking, dashboards and alerts that look the same in every service.

5Isolate Resources From Request Traffic

To stop jobs competing with traffic, the guidance sets resource boundaries. Scheduled work runs on its own scheduler pool, sized deliberately, and any asynchronous work it starts uses its own bounded executor, never the shared one that request handling uses. For database access, a job either uses a small separate connection pool, for example 3 connections out of a service's 20, or is limited by a semaphore so it can never take more than its share.

Downstream calls get timeouts and, where the downstream has a rate limit, the job uses a smaller share of it than the request path. The aim is that the worst a misbehaving job can do is make itself slow, never the service's customers. A good sign that a job does not fit these limits is that it needs more than its small budget, which by the classification means it should move out.

6Make Every Job Visible in a Central Inventory

Finally, nobody can manage what nobody can see. The guidance asks for every scheduled job, in-service or on the platform, to appear in a central inventory with its service, schedule, owner team, classification and runbook link. The starter can register jobs automatically from the scheduled tasks it finds at startup, the same information the Actuator scheduledtasks endpoint shows, so the inventory stays current without manual updates.

The inventory pays off in several ways. During an incident, on-call engineers can see which jobs were running at that time. In reviews, we can spot jobs that should have been classified as heavy. And when a team is reorganised, the jobs it owned do not become orphans. Rolling the guidance out works best by applying it first to the services that had incidents, measuring incidents linked to scheduled jobs per quarter, and reporting that number to show whether the guidance works.

7Follow-up questions

How do you get teams to follow the guidance?

By making the compliant path the easiest path. The starter does most of the work, the service template includes it, and architecture reviews ask the two classification questions for any new scheduled job. I would also share the incident history behind each rule, because engineers follow rules they understand much more readily than rules they are handed.

Should housekeeping jobs also be in the inventory?

Yes. They are cheap to list, and the inventory is how we notice when a 'housekeeping' job has quietly grown into something heavy. Listing them also gives an owner for each one, which matters when one of them starts failing.

What about existing jobs that break the rules?

I would not ask for an immediate rewrite of everything. Teams first add the starter, which gives locks and alerts quickly, then the jobs classified as heavy or critical are moved in priority order, starting with those that caused incidents or that touch customers and money.

8Conclusion

In this answer, we turned scheduled-job incidents into guidance. We separated the two failure modes, competition with traffic and running on every replica, classified work so light housekeeping can stay while heavy or critical jobs move to a batch platform or CronJob, and required in-service jobs to be idempotent and locked. A shared starter delivers ShedLock, metrics and missed-run alerts, resource isolation keeps jobs from starving requests, and a central inventory gives every job an owner.

What to say in the interviewAbout 80 seconds aloud

Open with

I would not ban @Scheduled, I would classify the work. Light housekeeping, short and cheap and harmless if one run fails, like refreshing a cache, can stay in the service.

Then, if they want more

Anything heavy, long-running, customer-facing, financial or audited moves to a batch platform or a Kubernetes CronJob, where it has its own process, resources and history.

For jobs that stay, two rules: they must be idempotent, and if they touch shared state they take a distributed lock, so they don't run on every replica; jobs that only touch local memory are the exception and should run everywhere.

To make that easy, the platform team ships a starter that configures ShedLock, adds metrics per job tagged with the owner, and publishes a last-success timestamp so we can alert on missed runs, which nobody notices otherwise.

I would also isolate resources: a sized scheduler pool, a bounded executor of its own, and a small database connection budget, so a job can only slow itself, never requests. Finally, every job goes into a central inventory with an owner and a runbook, registered automatically by the starter.

I'd roll it out to the services that had incidents first and track job-related incidents per quarter.

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 "Teams across your organisation keep adding @Scheduled jobs inside request-serving...": https://scrivio-interview-library.netlify.app/spring-boot/scheduling/3d3f6818f0/