Logo

dev-resources.site

for different kinds of informations.

Load Testing Serverless Application using k6

Published at
9/13/2023
Categories
serverless
aws
loadtesting
k6
Author
serverlessl
Categories
4 categories in total
serverless
open
aws
open
loadtesting
open
k6
open
Author
11 person written this
serverlessl
open
Load Testing Serverless Application using k6

Serverless is ultimately scalable until it is not. You need to do load testing to make sure that your solution scales. The k6 is an amazing tool for that.

One of the main selling points of serverless is that it can scale to almost infinitive. However, building highly scalable systems is still a challenge. Serverless is complex, and it is quite challenging to get the architecture right. It is also very easy to hit service quotes (build in limits) when services stop scaling. They are there for two reasons: for you to not massively overspend in case of a bug or a huge load and that it helps AWS to maintain a level of service availability for all their customers. Some quotas are โ€œhard,โ€ but most important ones are โ€œsoft,โ€ meaning you can open a request to AWS to ask for higher limits. You can see the quotes and request a quota increase in the Service Quotas console.

Serverless is ultimately scalable until it is not. You need to do load testing to make sure that your solution scales. The k6 is an amazing tool for that.

If you need to build a highly scalable serverless system, it is not enough to study all quotas and architecture in detail because you will definitely miss something. You need to do load testing. The best kind of tool/service for load testing is k6. The winning feature is it supports writing tests in JavaScript and even TypeScript. If your system is written in one of these languages, it is handy to also use it to write load tests. The benefit of using a real language for load testing, in opposite to just sending a static payload, like in other similar tools, is that you can generate test data on the fly and easily simulate a real user. I find k6 an essential tool for my serverless development, and I use it for all systems that handle any significant load.

You can execute tests locally, or you can use their cloud service. There are many benefits of cloud service. The most important is that you can pick regions where the tests are executed. The service also produces nice graphical reports. But for most cases, when you want to find the scaling limits and when the system will hit AWS service quotas, the local testing is good enough.

Our Project

I will describe how to write a simple test using TypeScript. I am a big advocate for TypeScript, but writing tests for k6 is not that indispensable because tests are usually simple. I still use TypeScript because all of the systems I build are built with TypeScript, and it also allows me to reuse some of the code, like the one to generate sample data, that I can reuse for load, unit, and integration tests.

For writing k6 tests in TypeScript, there is already a well-written sample. We will go much further and expand it with:

  • Create a monorepo with an application built with the SST framework. We will execute our test on this application.
  • Use esbuild to bundle the code (although webpack is the recommended one by k6).
  • Authenticate user using Cognito.
  • Use of faker-js to generate some sample data. This part of the code is shared between integration and load test.
  • Use the SST Config feature for sharing parameters via the SSM Parameter Store. You can use this approach for regular integration tests and also in-load tests.

You can find the solution here. Before using it, install k6. k6 is not an npm module, it requires a separate install.

Continue reading...

loadtesting Article's
30 articles in total
Favicon
Everything you need to know about load testing concurrent users
Favicon
Scaling Node.js: Handling 1 Million Requests Like a Pro
Favicon
A Critical Performance Issue Led Me to Discover EchoAPI's Load Testing
Favicon
Comparing the K6 Operator vs Testkube for Load Testing
Favicon
Performance Testing with NeoLoad
Favicon
How I created a unique PPT for "Load Testing" KT!
Favicon
Capacity Planning as a Way to Minimize Unforeseen Business Expenses
Favicon
Load testing 3scale
Favicon
Getting Started with Load Testing using Locust
Favicon
JMeter-Dynamic Load Testing of Restful APIs
Favicon
K6 Development: Beyond The Basic Setup
Favicon
Load Testing Serverless Application using k6
Favicon
How to use CSV file for parameterization in JMeter
Favicon
Installing Apache JMeter using Homebrew
Favicon
Thread Group in Jmeter: Understanding its Components and Use Cases
Favicon
Running Load-Test-as-Code Simulations with Gatling
Favicon
Load-Test-as-Code for Non-Coders!
Favicon
How Software Performance Testing Can Help Your Business Succeed this Holiday Season
Favicon
Library for easy implementation of instant load testing
Favicon
My journey with AWS
Favicon
Loadtest Websocket Server
Favicon
How to get started with Load Testing?
Favicon
AWS Lambda vs. Cloudflare Workers vs. AWS Cloudfront Function cold start comparison with Ddosify Cloud
Favicon
Performance Testing via Artillery.io - user guide
Favicon
Load testing with Playwright
Favicon
Performance Testing Report. The importance of Load and Stress Testing your Systems.
Favicon
Load Test your NodeJS app using K6
Favicon
Load Testing withย Locust
Favicon
Vegeta load testing a quick tutorial with GET examples
Favicon
Load Testing Your API with Postman

Featured ones: