Skip to content

Scale-down hysteresis — why your auto-scaler is flapping, and how to fix the cool-down

Auto-scalers that add and remove the same node every twelve minutes look correct on paper and ruin every cache, warm pool, and connection-pool health they touch. Set hysteresis on purpose.

Your Jelastic auto-scaler did exactly what it was told for two weeks. Then someone graphed node count over the same period and the line looks like a heartbeat: 4 nodes, 5 nodes, 4 nodes, 5 nodes, every twelve to fifteen minutes, all day. P95 latency on the application has a sawtooth pattern that lines up perfectly with the scale events. Each new node spends its first 90 seconds warming caches, opening DB pool connections, and JIT-compiling hot paths — during which it serves requests slower than the old nodes — and then gets removed forty minutes later when the threshold drops back below the cutoff. Your auto-scaler is correct. Your auto-scaler is also the cause of your latency.

What’s happening

Flapping is what happens when the same input metric oscillates around the scale-up and scale-down thresholds, and the scaler reacts to each crossing. With a single threshold (e.g. “scale up at CPU > 60, scale down at CPU < 60”), even a one-percent jitter triggers a node event every cycle. With two thresholds that are too close (60 / 55), it takes longer, but it still happens because traffic isn’t steady — it breathes.

The cost of each scale event is non-zero and often non-obvious:

  • Cache warmup. New nodes start cold. Database query caches, Redis connection pools, Lambda warm pools, JVM JITs — all begin in the worst state and converge over seconds to minutes.
  • Connection-pool reshuffle. Removing a node forces every in-flight connection to reset. Connection-pool exhaustion alerts that fire “for no reason” right after a scale-down are this.
  • Health-check noise. A node coming up enters the load balancer at “weight = ramping” and a node going down spends 30-60 seconds draining. During the overlap, total capacity dips below what the dashboard says.
  • Operator load. Every scale event is a paging-grade signal somewhere — a slack notification, a row in an audit log, an entry in the on-call shift summary. Twenty scale events a day is twenty signals operators learn to ignore, until the one that mattered also gets ignored.

The solution is hysteresis: make the conditions to scale up and scale down intentionally different, with three knobs.

1. Asymmetric thresholds. The scale-up threshold must be substantially above the scale-down threshold. “Up at 70%, down at 30%” leaves a 40-point band where the scaler does nothing. Inside the band, the load is “fine” by definition.

2. Asymmetric cooldowns. A cooldown is the minimum interval between two scale events of the same kind. Scale-up cooldown should be short — 30-90 seconds — because lateness costs revenue. Scale-down cooldown should be long — 5-15 minutes — because the cost of warming up the same node you just removed is real.

3. A different-direction cooldown. After you scale up, refuse to scale down for at least 10-15 minutes regardless of the metric. This is the most important knob and the one most often missing. It prevents the classic pattern of “scaled up at 14:02 because of a spike, scaled down at 14:08 because the spike passed, scaled up again at 14:14 because the cache was still cold from the scale-down.”

How to verify

Pull node count and the metric you scale on over a 24-hour window and look at the shape:

# Node count over time (Jelastic API — adjust for your scaler's log)
curl -s "http://prom:9090/api/v1/query_range?\
query=count(up{job=\"app\"})&start=$(date -u -d '24 hours ago' +%s)&\
end=$(date -u +%s)&step=60" | jq '.data.result[0].values[] | .[1]' | uniq -c

# Output should look like:
#    340 "4"      <- 5h40m steady at 4
#    23  "5"
#    287 "4"      <- 4h47m steady at 4
#    34  "5"
# Healthy: long runs at each level, transitions are infrequent.

# Pathological output:
#    8  "4"
#    11 "5"
#    9  "4"
#    13 "5"      <- flapping every ~10-20 minutes

If your node-count time series has more than ~3-5 transitions per hour at steady traffic, you’re flapping. Also check whether each scale-down is followed by a P95 latency spike — histogram_quantile(0.95, ...) aligned with scale events on the same graph. The spike is the warmup penalty.

The fix

A scaler with hysteresis baked in. The settings below are starting points — tune to your workload.

# Hysteresis configuration — per node group
node_group: cp                # application tier
min_nodes: 2
max_nodes: 10

# Asymmetric thresholds (two-rule example: latency + queue)
thresholds:
  p95_latency_seconds:
    scale_up:   1.0
    scale_down: 0.3           # 3.3x band — wide on purpose
  queue_depth:
    scale_up:   500
    scale_down: 50            # 10x band

# Asymmetric cooldowns
cooldown_seconds:
  up_after_up:     60         # successive scale-ups
  down_after_down: 600        # successive scale-downs — long
  down_after_up:   900        # refuse scale-down for 15min after scale-up
  up_after_down:   180        # short — allow re-scale if down was wrong

# Sustained-condition window
# Don't scale on a single 20-second poll; require N consecutive polls
sustained_polls_for_up:   2   # = 40s of bad
sustained_polls_for_down: 8   # = 2m40s of good

The four rules:

  1. Wide thresholds. The band between scale-up and scale-down should be at least 2x. If you’re using P95 latency, “up at 1 s, down at 300 ms” is a reasonable starting point — the user-experience difference between 300 ms and 1 s is the band of “acceptable.”
  2. Long scale-down cooldowns. Five minutes is a floor. Ten to fifteen minutes is normal. If you’re worried that costs you cloudlets, measure how long warmup actually takes and price the warmup latency cost against the cloudlet time saved. Warmup almost always wins for stateful or cache-heavy apps.
  3. Cross-direction cooldowns are mandatory. After a scale-up, lock out scale-down for 10-15 minutes. After a scale-down, lock out scale-up for 2-3 minutes. The asymmetry reflects that scaling-up too soon is recoverable, scaling-down too soon is not.
  4. Sustained-condition windows. Don’t scale on a single high reading. Require N consecutive polls above the threshold before acting. This kills jitter without requiring you to widen the threshold further.

If you’re staring at a node-count graph that looks like an EKG and your team is rolling back the auto-scaler because “it makes things worse,” our Cloud PaaS team tunes the hysteresis off real traffic data and runs it under environment management. Start a scoping call — we’ll pull a week of node-count data and show you where the band should sit.