Side Read: The Rolling Window — What "10 Buckets × 1s" Means

The problem — a window that forgets, at thousands of calls per second. A counter that runs from process start never forgets, so an outage from an hour ago would keep the breaker nervous for good. The exact answer is to keep a timestamp for every call and evict anything older than 10 seconds. At the call rates of an API tier that means allocating, storing and scanning tens of thousands of entries per command, on the hot path of every request. Hystrix gives up a little precision to avoid that.

The mechanism — a ring of per-second counters.

One HystrixCommand's rolling window

        ← older                                          newer →
      ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┐
      │  b1  │  b2  │  b3  │  b4  │  b5  │  b6  │  b7  │  b8  │  b9  │ b10  │ ← "now"
      └──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┘
each bucket:  success · failure · timeout · thread-pool-rejected · short-circuited · …

  error % = (failure + timeout + rejected) summed over b1..b10
            ─────────────────────────────────────────────────
                     total requests summed over b1..b10
  1. Write: each call's outcome increments one counter in the current bucket. That is a single atomic add with no allocation and no list to grow.
  2. Roll: when a second ends, a fresh empty bucket becomes "now" and the oldest one is discarded whole. Nothing is evicted call by call.
  3. Read: the breaker doesn't scan the buckets on every call. Hystrix adds them into a health snapshot (every ~500 ms by default), and gate 1 reads that snapshot: total ≥ ~20 and error % ≥ ~50 → OPEN.

Worked example — the rate climbing, one second at a time. A dependency that normally takes 5 calls/s starts failing every call at t = 3s:

After secondIn window (total / bad)Error %Breaker
315 / 00%CLOSED
525 / 1040%CLOSED: enough volume, rate below 50%
630 / 1550%OPEN (at the next snapshot)

The healthy seconds from before the outage dilute the failures, so a total outage takes about 3 seconds to trip the breaker rather than tripping it on the first failure. That lag is deliberate: the window is there so that one bad second doesn't count as a trend.

Why 10 × 1s, and not one 10-second bucket. The number of buckets sets how smoothly the window slides. The total span sets how much history it remembers.

Layout (same 10s span)How it slidesCost
1 × 10sResets to empty every 10s. Just after each reset it holds almost no data, so it's below the volume floor and can't trip.Cheapest
10 × 1s (Hystrix default)Always holds 9–10s of history and moves in 1s steps10 counter sets; 10 adds per snapshot
100 × 100msClose to a true sliding window10× the memory and summing work for smoothness a breaker doesn't need
Spanmetrics.rollingStats.timeInMilliseconds = 10000
Bucketsmetrics.rollingStats.numBuckets = 10. The span must divide evenly by it.
Snapshot intervalmetrics.healthSnapshot.intervalInMilliseconds = 500

The same structure — fixed buckets, write to the newest, add them up to read — is the sliding-window counter used in rate limiters, and it's how Resilience4j's time-based window works. Any "rate over the last N seconds" at high throughput tends to come out as a ring of buckets.