Lesson 20 / Unit 5: Capacity Planning
Autoscaling Signals
A scale-in was requested against nodes holding 40 live calls each, because CPU looked idle. Autoscale a voice fleet on active calls per instance instead.
We watched a scale-in get requested against nodes holding 40 live calls each, because the groups were target-tracking average CPU and on those nodes CPU looked low. No calls dropped. A separate guard refused to terminate them, and that guard was the only reason.
Both autoscaling groups on the fleet target-tracked average CPU. That is the obvious choice, and the easiest one to configure. CPU alone was insufficient for this workload. Use call counts with resource limits and draining, then verify the scaling policy under load.
Resource Ceilings
CPU is useful, but it does not cover every limit. Monitor network, transport allocations, worker memory and provider quotas too. The older port counter in this course is not a verified budget; Port Capacity explains the distinction.
Scale-In Risk
A node can have low CPU while holding calls. Removing it immediately still interrupts them. This is a drain-policy problem regardless of which scale-out metric you use.
Use a tested drain sequence and keep enough ready capacity for new arrivals. Scale-in protection helps with ordinary group scale-in; it does not prevent crashes, every replacement mechanism or explicit termination.
Scaling Metric
For a consistent workload, average active calls per ready instance is a useful planning signal. Choose the target from a verified per-node operating cap and scale-out delay.
It does not protect the busiest node by itself. Rooms stay on their assigned node, so retain per-node saturation alarms, admission checks and drain state. Exclude or account for nodes that are counted as in service but not ready to accept work.
The following AWS example sums one call-count sample per node per minute, then divides by the group’s in-service count. Missing or duplicate samples distort it; alert on telemetry gaps separately rather than treating them as real zeros.
Step 1: publish active calls from every instance, every minute
Each instance publishes its current call count once a minute with put-metric-data. Every instance uses the same namespace, metric name, and dimension, so CloudWatch aggregates them into one series for the group:
aws cloudwatch put-metric-data \ --namespace VoiceFleet \ --metric-name ActiveCalls \ --dimensions AutoScalingGroupName=sfu-asg \ --unit Count \ --value "$ACTIVE_CALLS"$ACTIVE_CALLS is whatever count the node already keeps. VoiceFleet and sfu-asg are placeholders for your own names; custom namespaces must not start with AWS/. Publish exactly once per minute per instance: the policy below takes the Sum over one minute, so publishing more often would count the same calls twice.
The instance role needs cloudwatch:PutMetricData. Check whether it already has it before designing around custom metrics. Ours did. That made this a code change. Without it, the same change becomes a permissions negotiation, and that difference is a week of calendar time in most organisations.
Step 2: publish zero when idle
An idle node must publish zero. Skipping the call because there is nothing to report is the easy mistake.
With no datapoint the alarm goes to insufficient data and scaling freezes without a word, which is worse than scaling on the wrong number, because at least the wrong number is visible.
CloudWatch’s own guidance says the same for periodic health metrics: when a period has no data, publish the value zero for that period.
Step 3: turn on the group’s in-service count
The divisor is GroupInServiceInstances in the AWS/AutoScaling namespace. It only exists if group metrics collection is on for the group (Auto Scaling group metrics):
aws autoscaling enable-metrics-collection \ --auto-scaling-group-name sfu-asg \ --metrics GroupInServiceInstances \ --granularity "1Minute"Step 4: target-track calls per instance with metric math
A customized metric specification can combine metrics with an expression, as long as it returns a single time series (target tracking with metric math). Save this as config.json:
{ "CustomizedMetricSpecification": { "Metrics": [ { "Label": "Active calls across the group", "Id": "m1", "MetricStat": { "Metric": { "MetricName": "ActiveCalls", "Namespace": "VoiceFleet", "Dimensions": [{ "Name": "AutoScalingGroupName", "Value": "sfu-asg" }] }, "Stat": "Sum" }, "ReturnData": false }, { "Label": "In-service instances", "Id": "m2", "MetricStat": { "Metric": { "MetricName": "GroupInServiceInstances", "Namespace": "AWS/AutoScaling", "Dimensions": [{ "Name": "AutoScalingGroupName", "Value": "sfu-asg" }] }, "Stat": "Average" }, "ReturnData": false }, { "Label": "Active calls per instance", "Id": "e1", "Expression": "m1 / m2", "ReturnData": true } ] }, "TargetValue": 300}Then attach it:
aws autoscaling put-scaling-policy \ --policy-name calls-per-instance \ --auto-scaling-group-name sfu-asg \ --policy-type TargetTrackingScaling \ --target-tracking-configuration file://config.jsonTargetValue above is a placeholder. Set it below your per-node ceiling (400 is an illustrative operating cap here) by at least the calls that arrive while a new node boots. The capacity model walks through that lead-time arithmetic.
Step 5: keep the guard
Calls per instance tells the group how many nodes it needs. It does not tell the group which node is safe to remove, so keep a guard that never terminates a node holding calls. On AWS, instance scale-in protection is one way to build it: a node sets protection on itself while it carries calls and clears it when it is empty. Draining a node on purpose is covered in zero-downtime deploys.
Next: scaling inbound SIP, where adding nodes does nothing until the carrier knows about them.
Common questions
What metric should a voice fleet autoscale on?
Active calls per in-service instance. Choose a target from measured per-node capacity, and also monitor per-node maxima, readiness and resource saturation.
Why is average CPU a poor autoscaling signal for voice?
It cannot see the RTP port ceiling, which can arrive at the same load as the CPU target and fails without an error. It also reads low on nodes carrying many steady, long-lived calls, so a scale-in can target a node with live calls on it.
Why should an idle node publish zero active calls?
With no datapoint, the target tracking alarm goes to insufficient data and scaling stops acting. Publishing zero keeps the metric continuous, so scale-in works when the fleet is quiet.
We do this work for teams shipping voice agents: Self-Hosted Voice Agent .
Edit this lesson on GitHub ↗Discussion
Questions, corrections and war stories welcome. Sign in with GitHub to comment.