Skip to main content

How do you write a k6 load test script?

  • k6
  • scripting
  • load test design

Answer it first, then compare. Nothing here is saved or scored.

Model answer

Basic structure: define `options` (stages for ramp-up/down, thresholds for pass/fail), export a `default function` with HTTP requests and checks. Example: `export const options = { stages: [{ duration: "2m", target: 100 }, { duration: "5m", target: 100 }, { duration: "2m", target: 0 }], thresholds: { http_req_duration: ["p(95)<500"] } }`. Use `check()` for assertions, `group()` for logical grouping, and `sleep()` for think time between requests.

What interviewers listen for

  • Workload modelling
    You design the load shape from product traffic, not from tool defaults.
  • Percentile literacy
    You read p50/p95/p99 separately and explain why each matters.
  • Bottleneck triage
    You correlate metrics across application, database, and infrastructure layers.
  • Capacity instincts
    You can translate a soak test into a sizing or scaling recommendation.

See all 35 performance questions

Written by , Senior QA Automation Engineer, 50+ QA candidate interviews conductedLast updated July 2026