← Back to Blog

Load Testing with k6.io: Beginner's Guide

Load testing is an essential skill for every engineer building scalable systems. I use k6.io for all projects at Badr Interactive because it's lightweight, scriptable, and easily integrated into CI/CD.

Why k6?

  • Scriptable — Test scenarios written in JavaScript
  • CLI-native — Runs from terminal and CI/CD pipelines
  • Low resource — Generates thousands of VUs from a single machine
  • CI/CD Integration — Works with Jenkins, GitLab CI, GitHub Actions

Basic Script Example

import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '2m', target: 100 },  // Ramp-up
    { duration: '5m', target: 100 },  // Stable
    { duration: '2m', target: 0 },    // Ramp-down
  ],
  thresholds: {
    http_req_duration: ['p(95)<2000'], // 95% request < 2s
    http_req_failed: ['rate<0.01'],     // Error rate < 1%
  },
};

export default function () {
  const res = http.get('https://api.example.com/users');
  check(res, {
    'status is 200': (r) => r.status === 200,
  });
  sleep(1);
}

Result Interpretation

I always focus on these metrics:

  • p95 response time — Response time for 95% of requests
  • Error rate — Percentage of failed requests
  • Throughput — Requests per second the system can handle

CI/CD Integration

In Jenkins, I integrated k6 with threshold checks — if thresholds fail, the pipeline automatically rejects the build. This prevents performance regression before reaching production.

Regular load testing saves infrastructure costs and prevents downtime in production.