Scrivio Interview library
DebuggingFoundations6 min read · updated 13 November 2026

A smart-home platform has 3 million devices that each report their status once an hour. Average load is about 830 requests per second, yet monitoring shows over 60,000 requests per second in the first seconds of every hour, with timeouts, and the rest of the hour is quiet.

What causes this pattern, and how do you smooth it out on the device side and the server side?

The devices are synchronised: each reports at minute 0 by its own clock, or they all restarted together and kept the same phase, so load meant to spread over 3,600 seconds arrives in a few seconds. On the device side we add jitter, a random or id-derived offset within the hour, and jittered backoff on retries. On the server side we accept reports quickly into a queue, process them at a steady rate, and tell devices when to report next or when to retry, which spreads even devices we cannot update soon.

Why this question is asked

This is a classic pattern called a thundering herd, and it hides behind a reassuring average. 3 million reports an hour is only about 830 per second, a load any modest service handles. But the averages are lying: almost all of that load arrives at once. Interviewers ask this question because the same shape appears in many places, cron jobs, cache expiry and batch jobs, and the cure is the same. In this answer, we will find the cause, see why retries make it worse, then fix it on the device and on the server, and look at where else the pattern hides.

1A Quick Recap of the Numbers

3 million devices reporting once an hour gives 3,000,000 / 3,600, about 833 requests per second, if the reports are spread evenly. Monitoring instead shows over 60,000 requests per second in the first seconds of every hour, then quiet. If all 3 million reports arrive within 50 seconds, that is 60,000 per second, about 72 times the average. The service was sized for the average, so it times out.

2Why the Devices Are Synchronised

There are two usual causes. The first is the schedule itself: the firmware says report at minute 0 of every hour, and since devices sync their clocks with network time, they all agree on when minute 0 is, to within a second. The second is a shared start: the schedule is every 60 minutes since boot, but a power cut, a firmware update or a backend outage made most devices restart or reconnect at the same moment, so they all share the same phase and stay in step forever.

Notice that the problem is not the number of devices. It is that their timing is correlated. The fix is to break that correlation.

The same hourly load, two shapes
ScheduleSeconds the load spansPeak requests per second
All report at minute 0about 50about 60,000
Random offset within the hour3,600about 830 plus noise
Offset derived from device id3,600about 830, stable per device

3Why Retries Make It Worse, and the Fix on the Device

When the server is overwhelmed, many reports time out. If the devices retry after a fixed delay, say 5 seconds, the failed reports all come back together 5 seconds later, creating a second spike, which fails again, and so on. A spike that should have lasted seconds becomes a minute of overload.

So retries need jitter too. Exponential backoff with full jitter means each device waits a random time between zero and a growing maximum, for example up to 2, 4, 8 and 16 seconds on successive failures. The failures from one spike are then spread out instead of clustered.

Java
// On the device: spread the regular report, and spread the retries
long offsetSeconds = Math.floorMod(deviceId.hashCode(), 3600); // e.g. 1,847: stable for this device
scheduleHourly(offsetSeconds, this::report); // reports at 00:30:47, 01:30:47, ...
void onReportFailed(int attempt) {
long capMs = Math.min(60_000, 2_000L << attempt); // 2 s, 4 s, 8 s ... up to 60 s
long waitMs = ThreadLocalRandom.current().nextLong(capMs); // full jitter: anywhere in [0, cap)
retryAfter(waitMs);
}

The offset derived from the device id has a nice property: it is spread evenly across the hour, yet each device keeps the same time slot, which makes its behaviour predictable and easy to debug. A purely random offset chosen at each boot works too, but changes after every restart. Either way, the firmware change should roll out gradually, so we do not create a new herd of devices all updating at once.

4Fixing It on the Server

We cannot rely only on firmware, because some devices update slowly or never. So the server must protect itself. The first step is to make accepting a report cheap: the endpoint validates the message, writes it to a queue such as Kafka, and returns at once. A consumer group then processes reports at a steady rate the database can sustain. A spike now becomes a backlog that clears in a minute or two, instead of timeouts.

The second step is to let the server shape the schedule. In the response, the server returns when the device should report next, chosen to fill quiet slots in the hour, or a Retry-After header when it is busy. Devices that honour these instructions spread themselves out, even with old firmware, as long as that firmware already reads the field. This is the most powerful tool, because it puts the schedule under the server's control.

Step throughA report with a server-chosen next time
DeviceIngest APIKafkaProcessor
POST status report
append report
202 Accepted, next report at :37:12
poll at a steady rate
update device state in the database

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

The API only queues; the processor sets the pace, and the server spreads the next reports.

5The Same Pattern Elsewhere

Once we know the shape, we see it often. Cron jobs scheduled at midnight in hundreds of services all hit shared databases at 00:00. Cache entries created together, for example when a cache is warmed at deployment with a fixed one-hour TTL, all expire together and send a wave of misses to the database. Batch jobs started on the hour compete for the same resources. Clients that reconnect after an outage all come back at the same instant.

The general cure is to spread start times: jitter on schedules, TTLs with a random extra few percent, staggered job start times, and jittered reconnects. Wherever many independent actors share a clock or a starting moment, we should assume a herd will form and break the correlation on purpose.

6Follow-up questions

How would you move devices to new report times without a firmware change?

Use whatever control the current protocol already gives the server. If responses carry a next report time or the devices honour Retry-After, the server can assign each device a slot spread across the hour and move them gradually. If the server cannot influence timing at all, it can still spread processing by accepting reports into a queue cheaply, and it can respond to some devices with a retry instruction at a randomised time, which over a few hours shifts their phase if they schedule from the last successful report. If none of that is possible, the protocol needs that capability added in the next firmware.

Why not just autoscale for the first minute of each hour?

Scheduled scaling could add capacity before each hour, but we would pay for 72 times the needed capacity to handle a minute, and the database behind the service would need the same headroom. Spreading the load removes the problem for free.

Is a random offset better than one derived from the device id?

Both spread the load evenly. An id-derived offset is stable, so the same device always reports at the same minute, which helps debugging and gives the server a predictable load per slot. A random offset chosen at each restart avoids any accidental patterns in the ids, but changes after reboots. A good hash of the id gives the benefits of both.

7Conclusion

In this answer, we saw that the hourly spike comes from synchronised devices, all reporting at minute 0 or sharing the phase of a common restart, so an average of 830 requests per second arrives as 60,000 per second. Retries with fixed delays cluster failures into more spikes. The cure on the device is an offset within the hour and jittered backoff; on the server it is cheap acceptance into a queue, steady processing, and server-chosen report times or Retry-After. The same shape appears in midnight cron jobs, cache expiry and batch jobs, and spreading start times is the general cure.

What to say in the interviewAbout 80 seconds aloud

Open with

This is a thundering herd. Three million reports an hour is only about 830 per second on average, but the devices are synchronised. Either the firmware reports at minute 0 by a network-synced clock, or they all restarted together and kept the same phase, so an hour's load arrives in under a minute, about 60,000 per second.

Then, if they want more

Retries make it worse: if failed reports retry after a fixed delay, they come back together and form the next spike. On the device side I would add jitter, an offset within the hour, ideally derived from the device id so it is even across the hour and stable per device, and exponential backoff with full jitter on retries.

The firmware update itself rolls out gradually. On the server side I would make accepting a report cheap: validate, write to Kafka, return 202, and process at a steady rate, so a burst becomes a short backlog instead of timeouts.

And I would have the server tell each device when to report next, or send Retry-After when busy, so it can spread even devices that cannot be updated soon. The same pattern shows up with midnight cron jobs, cache entries expiring together and batch jobs on the hour, and spreading start times is the cure.

About this answer

Last updated
13 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 official documentation for the version you use. 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 "What causes this pattern, and how do you smooth it out on the device side and the server...": https://scrivio-interview-library.netlify.app/architecture/high-availability/e6a7161d4d/