Skip to main content
InterviewHubPRO
Section Overview
Q22

Question 22 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

44%
Software Testing & QA (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

Load Testing with k6: Virtual Users (VUs), Stages, and Thresholds.

senior LevelCode ExampleTestingSystem Design

In Simple Words: k6 is a modern, developer-centric load testing tool written in Go with JavaScript test scripts:

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

export const options = {
  stages: [
    { duration: '1m', target: 50 },  // Ramp-up to 50 users
    { duration: '3m', target: 50 },  // Stay at 50 users (soak)
    { duration: '30s', target: 0 },  // Ramp-down
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'], // 95% of requests must complete under 500ms
    http_req_failed: ['rate<0.01'],    // Error rate must be under 1%
  },
};

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