AWS Throttling
In Amazon Web Services’ (AWS) cloud environment, throttling limits the number of actions or requests that can be performed against your service in a certain period of time.
Why is this important for my services?
To provide a fantastic internal and external client experience. This prevents excessive costs or latency to plague your services as you make them available to users. It also removes the need to have a human physically monitoring site traffic on a regular basis and making adjustments ad-hoc. Setting the right throttling settings will allow your developers to focus on other parts of the tool, without the risk of suddenly having an availability issue or skyrocketing costs.
DynamoDB:
DynamoDB implements throttling at the table level.
Each DynamoDB table has a provisioned throughput capacity that defines the number of read and write operations it can handle per second.
if the requested throughput exceeds the provisioned capacity, DynamoDB will return a ProvisionedThroughputExceededException
error. To avoid this, you can either increase the provisioned capacity or implement techniques like exponential backoff and retry logic in your application. You can read more about implementing effective retry logic in our related posts!
Throttling is an important mechanism to ensure the stability and fair usage of AWS services, and understanding its behavior and configuring it appropriately can help you build scalable and reliable serverless backends.
Example of throttling settings in AWS
What could happen if I don’t throttle at the table level in DynamoDB?
Your end users could suffer because of it, you could run into functional issues without considering throttling before you launch your services to wider audiences.
Error Messages
DynamoDB has provisioned throughput capacity limits for read and write operations. If you exceed these limits, DynamoDB will return this error message (ProvisionedThroughputExceededExpectation), indicating that your request has been throttled. This can result in failed requests and degraded performance for your application.
Increased Latency
Without proper throttling, you may experience increased latency as DynamoDB needs to handle a higher volume of requests than it can handle efficiently. This can impact the response time of your application and degrade the overall user experience.
Inefficient Resource Utilization
DynamoDB provisioned capacity allows you to optimize the performance and cost of your applications. If you don't throttle at the table level, you may experience underutilization of your provisioned capacity or end up paying for additional resources that you don't actually need.
Service Degradation or Unavailability
If a particular application or user generates an excessive number of requests without throttling, it can lead to service degradation or even unavailability for other clients or applications utilizing the same DynamoDB table. Throttling helps in preventing this scenario by enforcing fair usage and protecting the overall system stability.
Increased Costs
DynamoDB charges based on provisioned throughput capacity and additional data storage. Without throttling, you may generate a large number of requests that exceed your provisioned capacity, resulting in increased costs due to over-provisioning or additional charges for exceeded capacity.
How to Scope and Implement Throttling
If you’re still reading, you’ve probably realized that you have a need to start implementing some throttling controls within your environment.
The hardest part is getting started. Digital Minion breaks down their steps and best practices below!
Understand Your Application Requirements
Start by understanding the expected usage patterns of your application.
Consider factors such as the anticipated number of users, the volume of read and write operations, and the response time requirements.
This will help you determine the appropriate level of throttling needed.
Estimate Required Throughput
Use the AWS DynamoDB Capacity Estimator or other tools to estimate the required provisioned throughput for your DynamoDB table.
This will help you understand the necessary read and write capacity units to handle your application's workload.
Set Provisioned Capacity
Provision the required read and write capacity units for your DynamoDB table based on the estimation from the previous step.
You can adjust the provisioned capacity later as needed.
Monitor and Analyze Usage
Monitor the DynamoDB metrics such as consumed capacity, throttled requests, and latency.
AWS CloudWatch provides metrics and alarms that can help you understand the usage patterns and identify potential bottlenecks or overutilization.
Adjust Provisioned Capacity
Continuously monitor the usage metrics and adjust the provisioned capacity as needed. If you observe frequent throttling or performance degradation, you may need to increase the capacity.
On the other hand, if you consistently have excess capacity, you can consider decreasing it to optimize costs.
Fine-Tune Throughput Settings
If you have specific workloads that require different levels of throughput, you can utilize DynamoDB's adaptive capacity or on-demand capacity modes.
Adaptive capacity automatically adjusts the throughput based on traffic patterns, while on-demand capacity allows you to pay per request without managing provisioned capacity.