# Scaling Cooldown Too Short

> Flags VM scale sets whose shortest autoscale rule cooldown is under 120 seconds and recommends raising it to 300 seconds.

Source: https://zop.dev/integrations/azure/recommendations/scaling-cooldown-too-short

---

## What the cooldown protects against

Each rule in an Azure autoscale setting has a `cooldown`, an ISO 8601 duration such as `PT5M`.
The [autoscale settings reference](https://learn.microsoft.com/en-us/azure/azure-monitor/autoscale/autoscale-understanding-settings)
defines it as the time that must pass after a scale operation before that rule may start
another. Autoscale checks each rule's cooldown independently.

New instances take time to boot, join the load balancer and pull their share of traffic. A
cooldown shorter than that lets a rule act on metrics that do not yet reflect its last action.
The result is [flapping](https://learn.microsoft.com/en-us/azure/azure-monitor/autoscale/autoscale-flapping):
a series of opposing scale events, instances launched and removed in quick succession, and
unstable capacity underneath the application.

## Reading the cooldowns on a scale set

```bash
az monitor autoscale show --resource-group my-rg --name my-autoscale \
  --query "profiles[].rules[].scaleAction.cooldown" -o tsv
```

Anything shorter than `PT2M` falls under this rule. `az monitor autoscale list --resource-group my-rg`
finds the setting name if you do not know it.

## The 120-second floor

ZopNight reads the autoscale setting attached to the scale set, takes the shortest cooldown
across all of its rules, and converts it to seconds. The rule fires when the scale set is
provisioned successfully or running and that shortest cooldown is above zero and below 120
seconds. The finding reports the exact value it saw and recommends 300 seconds.

## Scale sets that are not flagged

A scale set with no autoscale setting, or whose cooldown could not be read, is skipped; the
missing setting is covered by
<a href="https://zop.dev/integrations/azure/recommendations/vmss-autoscale-setting-not-configured">VMSS Autoscale Setting Not Configured</a>.
Cooldowns of 120 seconds or more pass. Thresholds that sit too close together are a different
flapping cause, reviewed by
<a href="https://zop.dev/integrations/azure/recommendations/scaling-target-too-high">Scaling Target Too High</a>
and <a href="https://zop.dev/integrations/azure/recommendations/scaling-target-too-low">Scaling Target Too Low</a>.

## Stability first; no saving is priced

ZopNight prices no saving for this finding. Flapping does cost money, in instance time spent
booting and draining, but how much depends on your churn and is not estimated. Microsoft notes
that autoscale checks for potential flapping only before scale-in, never before scale-out, so a
too-short scale-out cooldown gets no platform safety net.

## Lengthening the cooldown

1. Open the scale set's autoscale setting in the portal, or export its JSON.
2. Set each rule's `scaleAction.cooldown` to `PT5M` (300 seconds), or longer if instances take
   more than five minutes to become useful.
3. Keep scale-out and scale-in rules on the same metric with a margin between thresholds, as
   Microsoft's best practices advise.
4. Watch the setting's run history and the activity log for `Flapping` entries over the next few
   days.
