Lesson 3 of 4 Scaling Compute, Caching and Global Deployment

Identifying and Remediating Scaling Issues

Workloads usually stop scaling at a specific bottleneck: a quota, a connection limit, a hot key, a saturated dependency or a misconfigured policy. This lesson explains a method for finding the bottleneck from metrics, the most common limits on AWS, and how to remediate each, so that you can diagnose scenarios in which adding capacity did not help.

Learning outcomes

After completing this lesson, you will be able to:

  • Apply a systematic method to locate a scaling bottleneck using utilisation, saturation and error metrics.
  • Identify common AWS limits that block scaling, including service quotas, IP addresses and connections.
  • Explain how throttling and concurrency limits manifest in Lambda, DynamoDB, API Gateway and AWS APIs.
  • Describe remediations and the monitoring that detects limits before they are reached.
  • Explain how AWS Compute Optimizer identifies under-provisioned and over-provisioned resources.

Finding the Bottleneck

A useful method is to examine, for each resource on the request path, its utilisation (how busy it is), saturation (how much work is queued) and errors. The bottleneck is the first component that is saturated or erroring while components before it wait. For example, if application instances show low CPU but high request latency, and the database shows a maximum number of connections, the database connection limit is the bottleneck, and adding instances makes it worse. Distributed tracing with AWS X-Ray shows which downstream call contributes most to latency, and CloudWatch metrics at each tier show utilisation and errors.

Common Limits and Their Symptoms

The following limits frequently stop scaling. Each is explained, and a summary table follows.

Auto Scaling maximum and launch failures

A group at its maximum does not scale. Launches can also fail because of insufficient capacity for an instance type in an AZ, vCPU quotas for On-Demand or Spot instances, or a missing permission in the launch template; the group's activity history shows the error. Diversifying instance types and raising quotas fix these.

Subnet IP address exhaustion

Each instance, ECS task in awsvpc mode, Lambda function network interface, EKS pod with the VPC CNI and load balancer node uses IP addresses from its subnets. Small subnets run out, and launches fail with insufficient IP address errors. Remedies include larger subnets, adding a secondary CIDR to the VPC, prefix delegation for EKS, and monitoring with VPC IP Address Manager.

Database connections

Relational databases support a limited number of connections, and serverless or highly scaled application tiers can open more than the database allows. Amazon RDS Proxy pools and shares connections, which is the standard remedy for Lambda functions connecting to RDS or Aurora.

Lambda concurrency

Each account has a Regional concurrency quota (1,000 by default, raisable), shared by all functions. When it is reached, invocations are throttled: synchronous callers receive errors, and asynchronous events are retried. One function can starve others, which reserved concurrency prevents. Concurrency also scales up at a limited rate for each function, so sudden spikes can see throttling even below the quota; provisioned concurrency pre-warms capacity for predictable spikes.

API throttling

API Gateway has account-level and stage or method throttling limits and returns HTTP 429 when exceeded; usage plans set per-client limits. AWS service APIs throttle control-plane calls, which affects automation that makes many calls; backoff with jitter, batching and caching describe results. DynamoDB throttling and hot partitions are covered in the DynamoDB lesson.

Downstream dependencies

A third-party API or an internal service with fixed capacity limits the whole workload. Queues decouple producers from such dependencies, and circuit breakers and timeouts prevent a slow dependency from exhausting threads and connections upstream.

LimitSymptomRemediation
Auto Scaling maximumCapacity flat at max during high loadRaise maximum; review policy
EC2 vCPU quota or capacityLaunch failures in activity historyQuota increase; more instance types and AZs
Subnet IPsInsufficient free addresses errorsLarger subnets, secondary CIDR, prefix delegation
Database connectionsToo many connections errorsRDS Proxy, connection pooling
Lambda concurrencyThrottles metric, 429 or TooManyRequestsExceptionQuota increase, reserved or provisioned concurrency
API Gateway throttlingHTTP 429 responsesRaise limits, usage plans, caching
DynamoDB capacity or hot keyThrottled requestsCapacity, auto scaling, on-demand, key design, DAX

The following diagram illustrates the database connection limit and its standard remedy.

Database connections as a scaling limit. Each concurrent Lambda execution environment, or each application instance, opens its own connections, so scaling out the application can exceed the database's connection limit and cause too many connections errors. Amazon RDS Proxy pools and shares connections, so many clients use a smaller number of database connections; reserved concurrency can also cap the load the database receives.
More application capacity can make a connection bottleneck worse.
Match the pairs

Remove the scaling limit

Exam skills 3.2.1

Match each scaling symptom with its remediation.

Log in to try this activity Interactive activities are free with an account.

Monitoring Limits Before They Are Reached

Scaling incidents caused by quotas are avoidable. Service Quotas shows applied quotas and, for many quotas, current usage through CloudWatch usage metrics in the AWS/Usage namespace; CloudWatch alarms on usage as a percentage of the quota (using the SERVICE_QUOTA metric math function) warn before a limit is reached. Service Quotas can also request increases automatically through templates for new accounts in an organisation. Trusted Advisor service limit checks provide a similar view. Load tests, described in the testing module, reveal limits before customers do, and quotas in recovery Regions must match the primary Region.

Scenario questions

See limits coming

Exam skills 3.2.1 · 4.2.2

Practise monitoring quotas and sizing.

Log in to try this activity Interactive activities are free with an account.

Right-Sizing with AWS Compute Optimizer

Some scaling issues are sizing issues: an instance type with too little memory makes a group scale out on memory pressure, and a Lambda function with too little memory runs slowly because CPU is allocated in proportion to memory. AWS Compute Optimizer analyses CloudWatch utilisation history, 14 days by default or up to 93 days with the paid enhanced infrastructure metrics option, and recommends better configurations for EC2 instances, EC2 Auto Scaling groups, EBS volumes, Lambda functions, ECS services on Fargate and RDS and Aurora DB instances.

Each resource is classified with a finding such as under-provisioned, over-provisioned or optimised, with up to three recommended options and the projected utilisation and price of each. An under-provisioned finding identifies resources that are a performance risk; an over-provisioned finding identifies waste. EC2 memory utilisation is not a default CloudWatch metric, so memory-based recommendations need the CloudWatch agent publishing memory metrics. Compute Optimizer can be enabled for every account in an organisation from the management account or a delegated administrator, and its recommendations can be exported to S3 for analysis.

Compute Optimizer recommends; it does not change resources. Applying a recommendation is a change like any other: update the launch template or function configuration in IaC, deploy it through the pipeline and watch the metrics. Trusted Advisor's cost optimisation checks offer a broader but shallower view of idle and underused resources.

Worked example

Adding Capacity Made It Worse

A Lambda-based API that writes to Aurora PostgreSQL slows down during a campaign. The team raises the function's memory and the account concurrency quota, and errors increase. Logs show remaining connection slots are reserved errors from the database.

The bottleneck is database connections: each concurrent Lambda execution environment opens its own connection, and more concurrency means more connections. The remediation is RDS Proxy between the functions and Aurora, which multiplexes many function connections over a smaller pool, plus reserved concurrency on the function to cap the load the database receives, and an alarm on DatabaseConnections. Read-heavy queries are moved to an Aurora replica through the reader endpoint.

Check yourself

ECS tasks in awsvpc mode fail to start during scale-out with an error about insufficient free IP addresses. What is the cause and remedy?

Show answer

Each task needs an IP address from its subnet, and the subnets are exhausted. Add larger subnets or a secondary VPC CIDR with new subnets for the service, and monitor IP usage.

Exam Tips

Remember for the exam

  • Find the first saturated or erroring component on the request path; adding capacity before the bottleneck can make things worse.
  • Common limits: Auto Scaling maximum, vCPU quotas, subnet IPs, database connections, Lambda concurrency (1,000 default), API Gateway and AWS API throttling.
  • RDS Proxy solves connection exhaustion from Lambda and highly scaled tiers.
  • Alarm on Service Quotas usage metrics (AWS/Usage, SERVICE_QUOTA metric math) before quotas are reached.
  • Compute Optimizer flags under- and over-provisioned EC2, Auto Scaling groups, EBS, Lambda, ECS on Fargate and RDS; memory findings need the CloudWatch agent.