Four hundred instances on one hourly schedule sent 400 requests in one second. Hash offsets cut the peak to 12; slotting reached the bound of 7.
Four hundred servers and one second
Every shop server at Belgavi's Book Store refreshes its stock snapshot from the central inventory service once an hour. The job was written once, packaged once and deployed to 400 instances with the same schedule: run at minute zero of every hour. Each run sends one request per second for five seconds. The inventory service comfortably handles 50 requests per second.
At the top of every hour it receives 400 requests in the same second, for five seconds in a row. Dashboards averaged over a minute show a modest bump. The service's own latency histogram shows a wall: timeouts, retries from the shop servers that make the next second worse, and alerts that resolve themselves before anyone opens them.
Nothing is misconfigured. Each instance does exactly what its schedule says. The problem is that the schedules are identical, and identical schedules across a fleet are a synchronisation mechanism nobody designed.
Clock skew does not save you
A common assumption is that clocks drift enough to spread the load. They do not. Instances synchronised with NTP are typically within milliseconds of each other, and the companion model draws a skew of up to 500 ms per instance. With that skew, the worst second still receives all 400 requests and the service is over capacity for 30 seconds in six hours, every one of them at the top of an hour. Even 5 seconds of skew, far worse than any healthy fleet, leaves the peak at 400, because a five-second run overlaps all the others.
Spreading has to be deliberate.
Four ways to choose the start second
The companion model, and the lab built on it, place each instance's run inside a window after the scheduled time using one of four strategies:
- None: start at the scheduled second, shifted only by clock skew.
- Random each run: a fresh uniform offset in the window every time the job runs.
- Hash offset: a fixed offset per instance, derived from a hash of the instance name modulo the window.
- Slotted: offset equals the instance's index times the window divided by the fleet size.
With a 300-second window and the same fleet:
| Strategy | Worst second | Best hour peak | Seconds over capacity in 6 hours | Same peak every hour |
|---|---|---|---|---|
| None | 400 | 400 | 30 | yes |
| Random each run | 16 | 13 | 0 | no, mean 14.8 |
| Hash offset | 12 | 12 | 0 | yes |
| Slotted | 7 | 7 | 0 | yes |
The lower bound for any spreading is the even spread: 400 runs of five seconds in a window of 300 seconds means at least 7 requests in some second. Slotted reaches it. Hash offsets come close. Random offsets are close too, but their peak changes every hour, between 13 and 16 in this run.
Why stable offsets are usually the better choice
Random and hash offsets give similar peaks, so the difference is operational.
Reproducibility. With a hash offset, instance shop-0017 always runs at the same second past the hour. A latency spike at 14:03:41 can be traced to the instances that run at second 221, and it will recur at 15:03:41, so it can be investigated. With random offsets, every hour is a different experiment.
Testing. The peak under hash offsets is a fixed property of the fleet and the window. It can be computed before a deployment and asserted in a test. The peak under random offsets is a distribution, and the bad hour is the one you did not sample.
Downstream caches and quotas. A stable pattern lets a dependency plan; a random one forces it to provision for the tail.
Slotted offsets are optimal but need every instance to know its index and the fleet size. When an autoscaler adds instances, indices change and offsets move. Hash offsets need only the instance name.
The hash itself is a few lines. The companion hashes the instance name with FNV-1a, so that the browser lab reproduces the Python numbers exactly; in production, add the job name to the input:
def fnv1a(text):
h = 2166136261
for ch in text:
h = ((h ^ ord(ch)) * 16777619) & 0xFFFFFFFF
return h
def start_offset_seconds(instance_name, job_name, window_s):
return fnv1a(instance_name + "/" + job_name) % window_sIncluding the job name means two different hourly jobs on the same instance do not start at the same second.
What the schedulers you already use provide
You rarely need to write this yourself.
- systemd timers.
RandomizedDelaySec=delays each firing by a random amount up to the given value, chosen again for every iteration. AddingFixedRandomDelay=yes(systemd 247 and later) makes the delay stable, derived from the machine ID, the manager's user ID and the timer unit name.AccuracySec=defaults to one minute and lets systemd coalesce timers within that range; the documentation recommendsAccuracySec=1ustogether with a larger randomized delay to stretch events fully. - Jenkins. The
Hsymbol in a cron expression is a hash of the job name, soH * * * *gives each job a stable minute. - Amazon EventBridge Scheduler. A flexible time window, such as
{"Mode": "FLEXIBLE", "MaximumWindowInMinutes": 15}, lets the scheduler invoke the target at any point in the window after the scheduled time. - Kubernetes CronJob. It has
startingDeadlineSeconds,concurrencyPolicyandtimeZone, but no built-in jitter. Add a sleep derived from the pod or job name at the start of the container, and keepstartingDeadlineSecondslarger than the window.
A systemd unit for the stock refresh might read:
[Timer]
OnCalendar=hourly
RandomizedDelaySec=300
FixedRandomDelay=yes
AccuracySec=1us
Persistent=trueWhen jitter is not enough
The model makes two limits visible.
A window too short for the fleet. With a 30-second window, hash offsets still produce a peak of 78 requests per second, and the service is over capacity for 162 seconds in six hours. The even-spread bound for that window is 59, so even slotted offsets would overload it. The window must be at least the fleet's total work divided by the capacity, plus headroom.
Runs too long for the period. If each run sends 60 requests instead of 5, even a perfect spread over 300 seconds gives 67 requests per second against a capacity of 50. Hash offsets peak at 91 and the service spends 1,710 seconds over capacity. No placement fixes demand that exceeds capacity; the job must do less per run, or the dependency must offer a bulk endpoint or a change feed.
Jitter also shifts when work happens. A 300-second window means some instances refresh their snapshot nearly five minutes later than others. If the business needs every shop to see the same stock at the same time, the design needs a different mechanism, such as a published snapshot that shops download rather than compute.
Failure modes to test
- Cloned machine images that share a machine ID. With
FixedRandomDelay, they also share an offset, and the fleet resynchronises. Regenerate machine IDs on first boot. - Instance names with a shared prefix and a sequence number. FNV-1a spreads these well, but a weak hash such as a sum of characters does not; test the distribution on your real names.
- Retries without jitter. A failed run that retries immediately lands back at the peak; retry with exponential backoff and jitter.
- A schedule change that resets every offset at once, such as a restart of all instances at the same minute with a startup-relative timer.
Verification
The interactive lab replays the model in the browser: change the fleet size, window, skew, run length and strategy, and read the peak per hour, the decision trace for each instance and the seconds over capacity. The companion's python -m unittest -v test_example.py asserts every row in the tables above and checks that no strategy beats the even-spread bound on 20 seeded fleets per strategy. In production, plot the dependency's request rate per second, not per minute, around the scheduled times; a fleet that is spread well shows a plateau, not a spike.
Interactive experiment
Scheduled job jitter: peaks, offsets and a shared dependency. Synthetic browser-local fixtures, adjustable inputs, decision traces and JSON export.