Back to Blog Uncategorized

The Importance of Load Testing

September 3, 2024

How Load Testing with K6 Helped Us Optimize an Application—From Infrastructure to Code

Over the past six months, we’ve been preparing an application for a high-scale production environment for one of our international defense customers. Unusually, we didn’t have a strict deadline for this project, which allowed us to carefully review and optimize every part of the system.

 

The Use Case

This application is built using five microservices, all running on Kubernetes, one of the main platforms that help manage and deploy apps. These microservices communicate through Kafka, a messaging system, and store data in Postgres, a type of database.

 

What Is Load Testing?

Load testing is like giving your website or app a stress test to see how much traffic it can handle before it slows down or crashes. It simulates lots of users visiting your website at the same time, helping you ensure your site stays fast and reliable, even when many people are using it.

 

The K6 Tool

For our project, we used a tool called K6 for load testing. K6 is a simple tool that runs a script written in JavaScript. In this script, you tell K6 how many users to simulate and how long the test should last. For example, you could simulate 1,000 users over two minutes. K6 then sends lots of requests to your app, mimicking real user traffic. There’s also a version called K6 Cloud that lets you test how your app performs for users in different parts of the world.

 

Getting Started

We began by testing in our development environment, which had only a small amount of data. These tests helped us fine-tune how our services were set up, like adjusting Kafka settings and deciding how many resources (CPU and memory) each service needed.

 

Moving to Production

After successful testing in development, we moved to our production environment, which had all the real data. But when we ran the same tests, we hit some issues:

  1. Kubernetes Problems: The Kubernetes setup had some underlying issues, causing some services to fail randomly. We had to rebuild the cluster to make it more reliable.
  2. Database Configuration: We realized our Postgres database settings needed improvements to handle the load.
  3. Application Adjustments: The production environment had much more data, which exposed bugs and performance issues that were not clear during development testing.

 

Key Takeaways

  1. K6 Load Tests: These tests are vital—not just for checking if your app can handle high traffic, but also for evaluating the entire environment, including the infrastructure, database, and application code.
  2. Test in Production: Always run load tests in the production environment to catch issues that only appear with real data.
  3. Use Real Data: Testing with the full dataset, rather than a sample, is crucial for identifying all potential problems.

 

Author: David Abrams