Skip to content

Load Testing

In one line

Load testing simulates real user traffic to check if the system handles expected load — response times, throughput, error rates.

In simple words

Load testing answers: "Can our system handle the traffic we expect?" It simulates realistic user load and measures performance metrics.

What load testing measures:

  1. Response time — how fast the system responds under load
  2. Throughput — requests per second the system can handle
  3. Error rate — percentage of failed requests under load
  4. Resource usage — CPU, memory, database connections, etc.

Types of load tests:

  1. Baseline — normal expected traffic
  2. Peak — highest expected traffic (Black Friday, product launch)
  3. Volume — large amounts of data, not necessarily high concurrency
  4. Endurance — sustained load over a long period (see Soak Testing)

Process:

  1. Define test scenarios (user journeys, not just API calls)
  2. Gradually increase load to target level
  3. Monitor system metrics during the test
  4. Identify bottlenecks (database, CPU, memory, network)
  5. Optimize and re-test

Tools: k6, JMeter, Locust, Artillery, Gatling.

Example

javascript
// k6 load test script
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '2m', target: 100 },  // ramp up to 100 users
    { duration: '5m', target: 100 },  // stay at 100 users
    { duration: '2m', target: 200 },  // ramp up to 200 users
    { duration: '5m', target: 200 },  // stay at 200 users
    { duration: '2m', target: 0 },    // ramp down to 0
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'], // 95% of requests < 500ms
    http_req_failed: ['rate<0.01'],   // < 1% errors
  },
};

export default function () {
  const res = http.get('https://api.example.com/products');
  check(res, {
    'status is 200': (r) => r.status === 200,
    'has products': (r) => r.json().length > 0,
  });
  sleep(1); // think time between requests
}

k6 gradually ramps up users, sends requests, and checks thresholds. If 95th percentile response time exceeds 500ms or error rate exceeds 1%, the test fails.

Common confusions

  • Confused with: stress testing

    The difference: Load testing simulates expected traffic to verify the system handles it — it tests normal/peak conditions. Stress testing pushes beyond expected limits to find the breaking point — it tests failure conditions. Load testing asks 'can we handle our traffic?'; stress testing asks '@when do we break?'

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary