AWS Lambda: How to manage function Concurrency limits & throttling

Tags: aws, lamda
Published: 2021-04-01 12:14:19

##What is AWS Lambda?##

The Amazon Web Services Lambda is a cloud service which response to all the actions within your application, it inspects all the actions taken in your application and responds by deploying the user-defined codes. Your AWS account can respond to 1000 requests from your application user at the same time, which means your account has 1000 default concurrent executions. You can set a limit of concurrency for all your [lambda functions](https://www.sndkcorp.com/cloud-services/amazon-ec2) which will allow you to reserve a certain number of your account’s total concurrency level for that specific function and this limit will help you specify the number of functions that can be invoked at a time.

![Aws lambda -sndkcorp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxgjbddhb64y40tiimni.jpg)
 
##Working of Lambda Function and Lambda Throttling##

Each request triggers an [AWS lambda](https://www.sndkcorp.com/) to launch and process to carry out a certain function and every AWS user gets 1000 unserved concurrency limit for an account when this limit is reached then lambda will not invoke any functions and throttle it instead.

* Throttling is simply an intentional rejection of a request by lambda and to not carry out that function.
* All the lambda functions of an account can use the pool of 1000 unreserved concurrent executions.
* If one or more lambda functions receive 1000 request separately or in total, then all the lambda executions will be run through the common pool of unreserved concurrent executions and any future request of [lambda functions](https://www.sndkcorp.com/blog/aws-serverless-architecture) would be declined and you can no longer entertain any further requests. Here, it becomes necessary to prevent further requests from being unnecessary throttled.

###How to Prevent Lambda Function Throttling?###

* Lambda function throttling can be prevented by a few techniques, it can be done by requesting a higher limit of concurrent executions for your AWS account. You can increase your account’s concurrency limit at no cost, this can prevent your application from lambda function throttling but cannot eliminate it.
* Elimination of lambda function throttling can only be done by increasing your account’s limit to a very high number of concurrent executions which can cost you a lot. It can also be done by reserving some executions per function, you can reserve a certain amount of your account’s total concurrency limit for a specific function.
* This will allow your reserved lambda executions to be untouched by other functions and will be only used by that particular function, preventing throttling of requests due to exceeding your account’s limit.

###Other reasons for setting a concurrency limit###

* **Cost and Security**: Someone can accidentally or intentionally make a huge number of function requests to your system, which can result in costing you more or invasions in your systems and data loss.
* **Performance**: A large number of functions being performed at the same time can affect your performance and slow down your application.
* **Creating an Off switch**: This helps you in shutting down your systems and allowing zero traffic through your processes.

##Conclusion##

The [AWS Lambda](https://aws.amazon.com/lambda/) inspects all the actions taking place in your application and responds through your user-defined codes, all the requests made by your application users are entertained by this lambda function. Your account has a limit of 1000 concurrent executions can entertain 1000 requests at a time and perform those functions, due to this limit the exceeding number of requests get automatically declined by your lambda which is known as lambda function throttling. To prevent this throttling, either you can increase your account’s concurrent limit or you can reserve a certain number of total concurrent executions of your account for a specific function. Reserving certain concurrency for a function will help you from throttling of that lambda function as it can use the untouched executions and carry out that function.