Load testing a serverless application is a key factor for building production grade applications. With load tests, you can easily synthesize a production environment by understanding and applying the same traffic patterns that you expect from your existing applications running in production.
This testing strategy helps you to adapt your serverless architecture, way in advance, to handle traffic spikes avoiding any surprises.
Lambda functions scale at a faster rate; however, your application will have a database component which also has to scale accordingly to serve your end customers without any problems. Throttling can happen at the API Gateway, or Lambda function, or at the database level. Understanding those choke points and architecting around them becomes feasible when you provide and execute load tests.
Take this simple API as an example:
Writing a load test for this application will eventually execute an end-to-end tests at a higher scale.
Artillery is a tool which can be easily used to run load tests. The configuration to run load test in Artillery would look like below:
## load-test.yml
config:
phases:
- duration: 60
arrivalRate: 100
processor: "./loadTestData.js"
scenarios:
- name: "Create Products"
flow:
- post:
url: "/ticket"
beforeRequest: generateRandomTicketData
json:
userId: "{{ userId }}"
description: "{{ description }}"
Assuming that you have installed Artillery in your local setup, now you can run the load test by calling:
artillery run load-test.yml --target $API_URL
Once tests are complete, you can assess and monitor metrics like:
You are not limited to using just Artillery. Here are some of the other load testing tools that can be used:
You can learn more about running load tests from serverless-test-samples.