Bottleneck in Scaling Serverless Application on AWS | DVA-C01 Exam Answer

Bottleneck in Scaling Serverless Application on AWS

Prev Question Next Question

Question

You and your colleague are working on a serverless application that involves the registration of 500 users at a time.

You have written two functions to support this where one function handles the storing of information to DynamoDB, and the other sends a confirmation email using SES.One of the functions that sends an email when a new user's information is saved to DynamoDB doesn't scale.

On querying DynamoDB, you realize all 500 user's information is saved successfully.

But CloudWatch shows failed invocations for the second function.

How will you address the bottleneck in the least possible time?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer: C.

Option A is incorrect because setting up ALB and routing traffic through ALB can take time.

Option B is incorrect because refactoring code may consume a long time and may address the bottleneck.

Option C is CORRECT given that 500 users are registering simultaneously, concurrency would be extremely important, and reserving it would guarantee invocations without having to use the unreserved pool of concurrency.

Each account has a default concurrency limit of 900 as concurrent execution for all the available lambda functions, and 100 must be left for unreserved lambdas.

Therefore setting concurrency per function to 500 will meet this requirement.

As a developer, it is extremely important to know the constraints of the operating environment.

Option D is incorrect because polling DynamoDB may result in unnecessary invocations that can overload downstream resources such as SES.

Reference:

https://docs.aws.amazon.com/lambda/latest/dg/per-function-concurrency.html

As mentioned here, Concurrency can be defined per function which reserves capacity for the function.

https://aws.amazon.com/about-aws/whats-new/2017/11/set-concurrency-limits-on-individual-aws-lambda-functions/

In this scenario, we have two serverless functions working together to register 500 users at a time. The first function stores user information to DynamoDB, and the second function sends a confirmation email using SES. However, the second function is not scaling properly, and CloudWatch is showing failed invocations for this function.

To address this bottleneck in the least possible time, we have four potential solutions to choose from:

A. Use AWS ALB with Lambda function to manage traffic: This solution involves using an Application Load Balancer (ALB) to distribute traffic across multiple Lambda functions. While this may help with scaling, it's not clear if this will address the underlying issue with the email-sending function. It's possible that there are still problems with the function's code or configuration that need to be addressed.

B. Refactor code to decouple and create multiple functions to send emails: This solution involves breaking up the email-sending function into smaller, more manageable functions. This can help with scaling and also make it easier to troubleshoot any issues that arise. However, this may require significant changes to the codebase and could take some time to implement.

C. Reserve concurrency for your second Lambda function: This solution involves allocating a fixed number of concurrent executions for the email-sending function. This can help ensure that there are always enough resources available to handle incoming requests, which can help with scaling. However, this may not be the most efficient solution, as it could potentially waste resources when the function is not being used.

D. Get your second function to poll DynamoDB for new records: This solution involves having the email-sending function regularly check DynamoDB for new records to process. This can help ensure that all user information is properly processed and can also help with scaling. However, this may not be the most efficient solution, as it could lead to unnecessary processing if there are no new records to process.

Overall, the most efficient and effective solution will depend on the specific details of the problem and the constraints of the application. However, if we had to choose one solution from these four options, we would likely go with option B: refactoring the code to decouple and create multiple functions to send emails. This solution addresses the underlying issue with the email-sending function and can also help with scaling and troubleshooting in the future.