Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

Thousands of jobs across your services are scheduled at midnight UTC, and every night the shared database and message broker overload for ten minutes. How would you fix this across teams?

Thousands of jobs start at the same instant because 0 0 0 * * * is everyone's default for 'once a day', not because they need midnight. We would find the jobs and owners from schedulers and logs, ask teams whether the exact time matters, spread the ones that do not with fixed offsets or a stable hashed minute per job, documented as a convention, limit how many heavy jobs can hit the shared database and broker at once with a queue or central scheduler, and monitor load around schedule hotspots so new pile-ups are seen early.

Why this question is asked

Every night at 00:00 UTC the dashboards turn red for ten minutes and then recover. No single team's job is the problem; the problem is that thousands of reasonable decisions to run 'at midnight' add up to a stampede, often called a thundering herd. Interviewers ask this cross-team scenario because the fix is partly technical and partly organisational: finding the jobs, changing a habit across many teams, and putting a limit in place that does not depend on everyone remembering. In this answer, we will see why midnight overloads, find the jobs, separate those that need midnight from those that do not, spread start times with a stable convention, limit concurrency on shared resources and monitor the result.

1Why Midnight Becomes a Stampede

When an engineer writes a daily job, the first cron expression that comes to mind is 0 0 0 * * *, and in UTC-based infrastructure that means every daily job in the company starts at the same second. Each job is small on its own: a few queries, a few thousand messages. Multiplied by thousands, they open connections at once, run their heaviest queries at once and publish their batches at once.

Shared systems are sized for the average load plus a margin, not for the whole company's daily work squeezed into one minute. So the database's connection limit is reached, queries queue, the broker's disks and partitions are saturated, jobs time out and retry, which adds even more load. The ten minutes of overload is that queue draining.

2Find the Jobs and Their Owners

We cannot fix what we cannot list. The inventory comes from every place schedules live: Spring services expose their scheduled tasks through the Actuator scheduledtasks endpoint, Quartz keeps cron triggers in QRTZ_CRON_TRIGGERS, Kubernetes lists CronJobs across namespaces, and a code search for cron expressions with 0 0 0 or @daily finds the rest. The database and broker logs give the other half of the picture: which clients connect and publish between 00:00 and 00:10, so we can match load to jobs.

Each job in the list gets an owner team and a rough weight, such as the queries and messages it produces. Usually a few dozen jobs cause most of the load, and those are the ones to fix first.

3Ask Whether the Exact Time Matters

Most jobs only need to run once per day, not at midnight. A cleanup job, a daily summary email or a cache rebuild works just as well at 00:47 or 03:12. A smaller group really is tied to a time: an end-of-day financial cut-off, a report that must include the full previous day as soon as possible, or a partner integration that delivers files at midnight.

Asking each owner one question, 'does this job need to start at a specific time, and if so why?', usually shows that the large majority can move freely. Those that cannot get special treatment rather than holding everyone else at midnight.

4Spread Start Times With a Stable Convention

For jobs that can move, we spread them over a window, for example 00:00 to 04:00 UTC. Fixed offsets assigned by hand work for a few dozen jobs. For thousands, a better convention is a hashed minute: a stable number derived from the job's name decides its start time, so every job gets a different but predictable slot, and nobody has to coordinate. Jenkins popularised this idea with its H symbol; Spring cron has no such symbol, so a shared library can compute the expression.

Java
public final class SpreadSchedule {
/** A daily cron expression at a stable minute within the first windowMinutes after midnight UTC. */
public static String daily(String jobName, int windowMinutes) {
int offset = Math.floorMod(jobName.hashCode(), windowMinutes);
return "0 %d %d * * *".formatted(offset % 60, offset / 60);
}
}
SpreadSchedule.daily("invoice-export", 120); // "0 48 1 * * *" -> 01:48 UTC
SpreadSchedule.daily("ledger-close", 120); // "0 44 0 * * *" -> 00:44 UTC
// used as a property, so @Scheduled stays declarative
// jobs.invoice-export.cron=0 48 1 * * *
Load in the first hour, before and after spreading
Minute (UTC)Before: jobs startingAfter: jobs starting
00:002,60030 (time-bound only)
00:01 to 00:59about 100about 1,100 spread evenly
01:00 to 01:59about 50about 1,100 spread evenly
Peak database connections4,800 (limit 2,000)about 900
Illustrative numbers: the same work, spread over two hours, stays under the shared limits.

Because the offset comes from the name, the time never changes between deployments or replicas, which matters for locks and monitoring. The convention should be documented in one place, with the window and the rule, so new jobs follow it by default. For the time-bound jobs that cannot move, we look at making them lighter instead, for example by doing incremental work through the day so the midnight run only finishes the last hour.

5Limit Concurrency on Shared Resources

Spreading changes the habit, but it does not guarantee that the next 300 jobs added at 01:00 will not pile up again. So shared resources also need a limit that holds regardless of schedules. For heavy jobs, the cleanest form is a queue in front of the work: jobs submit a request, and a fixed number of workers, say 20, process them, so the database never sees more than 20 heavy jobs at once. A central scheduler with resource pools achieves the same by refusing to start more than N jobs tagged with a resource at a time.

At the resource itself, per-service connection limits on the database, per-client quotas on the broker and rate limits on producers stop one team's surge from using everything. These limits turn an overload into a slower night for the jobs that exceed their share, rather than an outage for everyone.

Step throughHandling a daily job under the new convention
  1. Must it start at an exact time?
    Yeskeep the time, review its weightNouse a hashed minute in the window
  2. Is it heavy on shared resources?
    Yessubmit through the limited queue or resource poolNorun directly
  3. Monitorload per minute, lateness, errors around hotspots

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

6Monitor Load Around Schedule Hotspots

Finally, we make hotspots visible before they become incidents. Dashboards for the shared database and broker should show load per minute with schedule density overlaid: how many jobs start in each minute, taken from the inventory. An alert on 'more than N jobs start in one minute' or 'connection usage above 70 percent' in the night window catches new pile-ups.

It is also worth reporting progress across teams, such as the number of jobs still at 00:00 and the peak load per night, so the improvement is visible and the convention stays alive when new teams arrive.

7Follow-up questions

Why not just add capacity to the database and broker?

Because the load is concentrated in ten minutes and idle for the rest of the day, so capacity bought for the peak is wasted 99 percent of the time, and the peak keeps growing with every new job. Spreading the work is free and fixes the cause.

Do randomised start times work instead of hashed ones?

Random times on each startup spread load, but the job's time changes with every deployment and differs between replicas, which confuses locks, monitoring and the people who expect a report at a predictable time. A hash of the name spreads just as well and stays stable.

What about Kubernetes CronJobs at midnight?

They have the same problem, plus a cluster-level one: hundreds of pods starting at once can exhaust node capacity and trigger autoscaling. The same convention applies to their schedules, and the CronJob timeZone field should be set explicitly.

8Conclusion

In this answer, we saw that the nightly overload is a thundering herd: thousands of daily jobs default to midnight UTC and hit shared systems in the same minute. We found the jobs and owners from schedulers, code and logs, separated the few that need an exact time from the many that do not, spread the rest with a stable hashed minute documented as a convention, put concurrency limits on heavy jobs with a queue or resource pool, and added monitoring of load around schedule hotspots so the problem does not quietly return.

What to say in the interviewAbout 90 seconds aloud

Open with

This is a thundering herd: 0 0 0 star star star is everyone's default for daily, so thousands of jobs hit the database and broker in the same minute.

Then, if they want more

First I'd build the inventory, from the Actuator scheduled tasks endpoints, the Quartz cron trigger tables, Kubernetes CronJobs and a code search, and match it with database and broker logs between 00:00 and 00:10 to see which jobs carry the load and who owns them.

Then I'd ask each owner one question: does it need to start at an exact time? Most don't; they just need to run once a day.

For those, I'd spread start times over a window, say two hours, using a stable hashed minute from the job name, computed by a small shared library and put into the cron property, so the slot is predictable and the same on every replica. That convention gets documented so new jobs follow it.

For the few that are time-bound, I'd look at making them lighter. Because spreading relies on habits, I'd also add hard limits: heavy jobs submit work to a queue or a central scheduler resource pool with a fixed concurrency, and the database and broker get per-service connection limits and quotas.

Finally, dashboards showing load per minute with job start density, and alerts on hotspots.

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 "Thousands of jobs across your services are scheduled at midnight UTC, and every night...": https://scrivio-interview-library.netlify.app/spring-boot/scheduling/c06cb12a15/