InsightsCloud
Service quotas and API throttling: finding the limit before production does
How to see AWS quota utilisation as a CloudWatch percentage, alarm before a limit is reached, request increases through code, and configure SDK retries so that throttling slows a client down instead of turning into an outage.
Published November 12, 20267 min read
Cloud limits rarely show up in design reviews and almost always show up during a scale-up, a failover or a big deploy. A new region needs more vCPUs than the account is allowed. A batch job calls one API faster than its rate limit. A retry loop that was harmless at ten requests a minute makes things worse at ten thousand.
There are two kinds of limit, and they fail differently. Quotas cap how much of something you can hold: instances, vCPUs, addresses, rules per group. Hitting one makes a create call fail, and it keeps failing until the limit is raised. Rate limits cap how fast you can call an API. Hitting one returns a throttling error that goes away if you slow down. This article covers both on AWS, but the same split exists on every cloud.
Know which quotas you are close to
Service Quotas is the AWS service that lists the quotas for most services and shows which of them are adjustable. Start by reading them from code instead of the console, so the list can be reviewed and compared over time:
aws service-quotas list-service-quotas \
--service-code ec2 \
--query 'Quotas[?Adjustable].[QuotaName,QuotaCode,Value]' \
--output tableThe quota code (for example L-1216C47A) identifies a quota in every later call. Quotas are per region and per account, and some are global and only reachable in one region, so a multi-region, multi-account organisation has many more numbers to watch than it first appears.
A few quotas are worth checking first because they sit on the path of a scale-up or a failover:
- compute: vCPU quotas per instance family, and the equivalents for managed container platforms
- networking: addresses, network interfaces, security group rules, load balancer targets
- identity and secrets: API rates for token and secret retrieval, which scale with pod count
- observability: log and metric ingestion rates, which spike during incidents when you need them most
Alarm on utilisation, not on the error
An alarm on LimitExceeded tells you after the failure. A usage alarm tells you while there is still time to ask for more.
For services that integrate with Service Quotas, CloudWatch publishes usage in the AWS/Usage namespace and offers a metric math function, SERVICE_QUOTA(), that returns the applied quota for a usage metric. The percentage of the quota in use is then m1/SERVICE_QUOTA(m1)*100. CloudWatch's own walkthrough uses a static threshold of 80 percent on that expression.
resource "aws_cloudwatch_metric_alarm" "ec2_vcpu_quota" {
alarm_name = "ec2-on-demand-vcpu-quota-80pct"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
threshold = 80
alarm_actions = [aws_sns_topic.platform_alerts.arn]
treat_missing_data = "notBreaching"
metric_query {
id = "pct"
expression = "m1/SERVICE_QUOTA(m1)*100"
label = "vCPU quota used (%)"
return_data = true
}
metric_query {
id = "m1"
metric {
namespace = "AWS/Usage"
metric_name = "ResourceCount"
period = 300
stat = "Maximum"
dimensions = {
Service = "EC2"
Type = "Resource"
Resource = "vCPU"
Class = "Standard/OnDemand"
}
}
}
}Do not copy the dimension values blindly. Open Metrics, Usage, By AWS Resource in the CloudWatch console, find the quota you care about and take the dimensions from there. They differ per service and per quota.
Not every quota is covered. The CloudWatch documentation lists the services that integrate their usage metrics with Service Quotas, and it is a short list compared with the number of services that have quotas. Where there is no usage metric, either count the resources yourself on a schedule (the same inventory job you may already run for drift detection) or accept that this quota is a known blind spot and document it.
Raise limits as code, with a reason
For adjustable quotas, a request is a single call. Smaller increases are usually approved automatically, and larger ones go to Support and take time, so request early:
aws service-quotas request-service-quota-increase \
--service-code ec2 \
--quota-code L-1216C47A \
--desired-value 512The CLI route needs permission to create a support case on your behalf, which the managed policy ServiceQuotasFullAccess provides. Requests get no priority treatment, and Support can approve, deny or partially approve them. For an urgent need, such as a failover test next week, contact Support rather than waiting on the automated path.
The Terraform AWS provider can manage a quota as a resource:
resource "aws_servicequotas_service_quota" "vpc_sg_rules" {
service_code = "vpc"
quota_code = "L-0EA8095F"
value = 150
}Per the provider documentation, setting a value higher than the current one submits an increase request, and the resource takes over an existing quota without an import. That is convenient, but it also means apply can open a request that sits in review for days. Treat the plan like any other change that has an external approver: merge it well ahead of the event that needs the headroom. Global quotas can only be managed in a single region (us-east-1 in the commercial partition), so the resource needs a provider configured for it.
Keep a short note next to each increase with the reason and the expected peak. Quotas that nobody can explain get left alone for years, and then nobody knows whether the number is safe to change.
Retries: the other half of throttling
Rate limits are handled by clients, and the default behaviour of the SDK is what decides whether a throttled call becomes a slowdown or an incident. The AWS SDKs retry throttling and transient errors with exponential backoff and full jitter. According to the SDK reference guide, the defaults are:
| Setting | Environment variable | Default |
|---|---|---|
| Retry mode | AWS_RETRY_MODE | standard |
| Max attempts (initial call included) | AWS_MAX_ATTEMPTS | 3 (DynamoDB clients: 4) |
Standard mode adds a retry quota: a token bucket that drains as retries happen and refills as calls succeed. When it is empty, the SDK stops retrying and returns the error, so a client fails fast during a wide disruption instead of piling load on a struggling service. The guide describes the base delay as 1,000 ms for throttling errors and 50 ms for transient errors, with each delay capped at 20 seconds.
There is a second mode. Adaptive mode adds a client-side rate limiter that slows the initial requests too once throttling is detected. The guide recommends it only for clients that target a single resource and expect frequent throttling, such as a batch processor writing to one table, and it does not recommend it as a general default. The limiter is shared by the whole client, so throttling on one resource slows calls to unrelated resources as well. A client that serves many tenants is the wrong place for it.
Two practical points:
- The retry behaviour is changing. The guide states that the updated behaviour it describes requires opting in with
AWS_NEW_RETRIES_2026=trueuntil it becomes the default, and that without it the SDK keeps its earlier retry behaviour, which differs in backoff timing, retry quota costs and service defaults. Support differs per SDK, so check yours before relying on the numbers above. If you load test throttling behaviour, test with the setting your production clients will actually use. - Retries multiply load. Three attempts means a throttled workload can send three times the traffic it intended. If many pods retry at once, a fleet can keep a service throttled well after the original spike has passed. Lower the attempts on non-critical paths, and put a queue or a concurrency limit in front of work that can wait.
Fix the caller, not only the limit
Raising a rate limit is sometimes the answer, but often the better fix is to call less:
- Cache what rarely changes. Credentials, secrets and configuration read on every request can be cached for a short time in the process.
- Batch. Many APIs accept lists. One call for a hundred items counts as one call.
- Spread startup. A hundred pods that all read the same secret at startup hit the limit together. Add jitter to startup work and stagger rollouts.
- Prefer events over polling. A loop that asks every second whether something changed uses the quota that an event subscription would not.
- Separate noisy callers. Give batch jobs their own account or role where the limit is per account, so they cannot throttle the service that takes customer traffic.
A routine that keeps this honest
- Once a quarter, list the adjustable quotas in your busiest accounts and compare them with peak usage from the usage metrics.
- Add a usage alarm at 80 percent for every quota on the scale-up and failover path, created by the account baseline module.
- Before a planned event such as a migration, a launch or a disaster recovery test, work out the capacity it needs and request the increases at least a few days ahead.
- Pin the retry mode and attempts for each service client on purpose, and make long-running batch clients back off instead of retrying in a tight loop.
- After any throttling incident, record which limit was hit, who owns it and what changed.
None of this is difficult. It is just work that nobody schedules until a limit has already stopped a release.