65+ k6 Interview Questions and Answers (2027)

66 k6 interview questions with answers: VUs, lifecycle, metrics, checks vs thresholds, executors, SharedArray, Prometheus output, CI and scenarios.

Sep 27, 2025 - 15:55
Nov 6, 2026 - 14:04
 0  195
65+ k6 Interview Questions and Answers (2027)

k6 interview questions test whether you understand Grafana k6 as a code-first load testing tool: how a script is structured, how virtual users and iterations work, which built-in metrics matter, how checks differ from thresholds, how executors shape load, and how results reach Grafana and CI. This page answers 66 of them, from first principles to senior design questions.

Answers were checked against the Grafana k6 documentation in November 2026 and assume k6 v1.x. This is the broad k6 question bank on our blog. For production work at engineer level (CI pipelines, the k6 Operator, debugging slow systems), continue with k6 engineer interview questions. For test types such as soak, spike and breakpoint, see k6 load and performance testing questions. All our interview sets are listed in the DevOps interview questions hub.

Key takeaways

  • k6 is an open-source load testing tool written in Go that runs test scripts written in JavaScript, and since v1.0 TypeScript files directly.
  • Code in the init context runs once per VU at startup; the default function runs repeatedly as iterations; setup() and teardown() run once per test.
  • http_req_duration, http_req_failed, iterations, vus and checks are the built-in metrics you will be asked about most.
  • Checks only count passes and failures. Thresholds decide whether the run passes and make k6 exit with code 99 when they fail.
  • Arrival-rate executors model an open system (requests per second); VU-based executors model a closed system (fixed concurrency).

k6 building blocks at a glance

ConceptWhat it isWhere you set it
VUVirtual user: an independent JavaScript runtime that loops over the test functionvus, scenarios
IterationOne run of the default (or scenario) function by one VUImplicit; counted in iterations
CheckBoolean assertion on a response; recorded in the checks ratecheck() from k6
ThresholdPass/fail rule on a metric for the whole runoptions.thresholds
ScenarioNamed workload with its own executor, function, tags and timingoptions.scenarios
ExecutorAlgorithm that schedules VUs and iterationsexecutor key in a scenario
OutputWhere metrics stream during the run--out flag

k6 interview questions for freshers

1. What is k6?

k6 is an open-source load testing tool maintained by Grafana Labs. You write tests as JavaScript (or TypeScript) modules and run them with the k6 binary, which is written in Go. It is used for load, stress, spike and soak testing of APIs, websites and services. The open-source project is licensed under AGPL-3.0.

2. Why do teams choose k6 over GUI-based tools?

Tests are plain code, so they live in Git, go through code review and run in CI like any other script. k6 is a single binary with low resource use per VU, it has built-in pass/fail thresholds that produce an exit code, and it streams metrics to tools such as Prometheus and Grafana.

3. Does k6 run on Node.js?

No. k6 embeds its own JavaScript runtime (Sobek, a fork of goja) inside the Go binary. That means Node.js APIs such as fs or require('http') and most npm packages that depend on Node built-ins do not work. You can bundle pure JavaScript libraries or import remote ES modules.

4. How do you install k6 and check the version?

Install from your package manager (for example brew install k6, the Grafana apt or rpm repository, winget install k6) or use the grafana/k6 Docker image. Run k6 version to confirm.

5. What does a minimal k6 script look like?

It imports modules, optionally exports options, and exports a default function that each VU runs in a loop.

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

export const options = { vus: 10, duration: '30s' };

export default function () {
  const res = http.get('https://test.k6.io');
  check(res, { 'status is 200': (r) => r.status === 200 });
  sleep(1);
}

6. How do you run a script?

k6 run script.js. You can override options on the command line, for example k6 run --vus 20 --duration 1m script.js. Command-line flags take precedence over options in the script.

7. What is a virtual user (VU)?

A VU is a separate JavaScript runtime that executes the test function again and again. VUs run in parallel, but each VU runs its own code sequentially. Ten VUs mean up to ten concurrent iterations, not ten requests per second.

8. What is an iteration?

One complete execution of the default (or scenario) function by a VU. The iterations metric counts them, and the iteration_duration metric records how long each took, including sleeps.

9. What is the init context?

Code outside any exported function. It runs once per VU when the VU is created, and once more when k6 parses options. It is where you import modules, read files with open() and define constants. You cannot make HTTP requests there.

10. What are setup() and teardown()?

setup() runs once before the load starts, for example to log in and get a token or create test data. Whatever it returns is passed as an argument to the default function and to teardown(), which runs once at the end for clean-up. The returned data must be JSON-serialisable and is a copy per VU, so changes made by one VU are not shared.

11. What does sleep() do and why use it?

sleep(seconds) pauses the VU. It models think time between user actions. Without it, a VU-based test fires requests back to back, which may not reflect real traffic and may just measure how fast one loop can spin.

12. What is a check?

A check is an assertion on a value, usually a response. check() takes the value and an object of named functions that return true or false. Results feed the checks metric, a rate of passes. A failing check does not stop the iteration or fail the test.

13. What is a threshold?

A threshold is a pass/fail criterion on a metric, such as "95th percentile of request duration under 500 ms". If any threshold fails, k6 marks the run failed and exits with code 99, which makes CI jobs fail.

export const options = {
  thresholds: {
    http_req_duration: ['p(95)<500'],
    http_req_failed: ['rate<0.01'],
  },
};

14. Which built-in HTTP metrics should you know?

http_reqs (count), http_req_duration (trend), http_req_failed (rate), and the timing breakdown http_req_blocked, http_req_connecting, http_req_tls_handshaking, http_req_sending, http_req_waiting and http_req_receiving. http_req_duration equals sending plus waiting plus receiving.

15. What is http_req_waiting?

The time from sending the request to receiving the first byte of the response, often called time to first byte. High waiting time usually points at the server or something behind it, not the network.

16. What are the four metric types in k6?

Counter (sums values), Gauge (keeps the latest value plus min and max), Rate (percentage of non-zero values) and Trend (statistics such as average, median, min, max and percentiles). Built-in and custom metrics all use one of these types.

17. What does the end-of-test summary show?

Aggregated results for each metric: counts, rates and trend statistics, plus check and threshold results. By default trends show avg, min, med, max, p(90) and p(95). You can change the statistics with --summary-trend-stats.

18. What are stages?

A shortcut for ramping VUs up and down over time. Each stage has a duration and a target number of VUs. Under the hood k6 uses the ramping-vus executor.

export const options = {
  stages: [
    { duration: '2m', target: 50 },
    { duration: '5m', target: 50 },
    { duration: '1m', target: 0 },
  ],
};

19. How do you pass environment variables to a script?

Use -e NAME=value on the command line (or a real environment variable) and read it with __ENV.NAME. This keeps hostnames and credentials out of the script.

20. What are __VU and __ITER?

Global variables holding the current VU number (starting at 1) and the current iteration number for that VU (starting at 0). The k6/execution module gives richer information, such as exec.vu.idInTest and exec.scenario.iterationInTest.

21. How do you send a POST request with a JSON body?

Pass a string body and set the content type header.

const payload = JSON.stringify({ user: 'demo', pass: 'demo' });
const params = { headers: { 'Content-Type': 'application/json' } };
const res = http.post(`${__ENV.BASE_URL}/login`, payload, params);

22. Which protocols does k6 support out of the box?

HTTP/1.1 and HTTP/2, WebSockets, and gRPC through k6/net/grpc. The k6/browser module drives a Chromium browser for front-end tests. Other protocols, such as Kafka or SQL databases, are available through xk6 extensions.

23. What is a group?

group(name, fn) organises code into named sections, for example "login" or "checkout". k6 tags metrics inside with the group name and records a group_duration metric, which helps when one iteration covers a whole user journey.

24. How does k6 compare with JMeter and Locust?

Aspectk6Apache JMeterLocust
Test definitionJavaScript/TypeScript codeXML test plans, usually built in a GUIPython code
EngineGo binaryJava (JVM)Python
Pass/fail in CIBuilt-in thresholds and exit codePlugins or post-processingCustom code or exit-code settings
Distributed runsk6 Operator or Grafana Cloud k6Controller and remote agentsMaster and workers

k6 interview questions for 2 to 5 years of experience

25. Explain the k6 test lifecycle in order.

k6 runs the init context to parse options, runs setup() once, initialises VUs (running init code for each), runs the VU code for the configured duration or iterations, then runs teardown() once and prints the summary (or calls handleSummary()). See the test lifecycle docs.

26. What executors does k6 provide?

Seven: shared-iterations, per-vu-iterations, constant-vus, ramping-vus, constant-arrival-rate, ramping-arrival-rate and externally-controlled. The first four are VU or iteration based; the arrival-rate pair start iterations at a set rate.

27. What is the difference between shared-iterations and per-vu-iterations?

With shared-iterations, a total number of iterations is shared among all VUs, so faster VUs do more. With per-vu-iterations, each VU runs exactly the given number. Use the second when every VU must perform the same work, for example one login per test account.

28. What is the difference between open and closed load models?

In a closed model, a fixed number of VUs each start a new iteration only after the last one finishes, so a slower system receives fewer requests. In an open model, new iterations start at a set rate regardless of response time, which matches public traffic. Arrival-rate executors implement the open model.

29. How do you configure a constant request rate?

export const options = {
  scenarios: {
    steady: {
      executor: 'constant-arrival-rate',
      rate: 200,
      timeUnit: '1s',
      duration: '10m',
      preAllocatedVUs: 100,
      maxVUs: 400,
    },
  },
};

This starts 200 iterations per second. If one iteration makes one request, that is about 200 requests per second.

30. What does the dropped_iterations metric mean?

An arrival-rate executor wanted to start an iteration but had no free VU, usually because responses slowed down and maxVUs was reached. Dropped iterations mean the test did not deliver the planned load, so add a threshold on it or raise the VU limits.

31. How do you run several workloads in one test?

Define multiple entries under options.scenarios. Each can use its own executor, exec function, startTime, env and tags. For example, browse traffic and checkout traffic can run in parallel at different rates.

32. How do you set a threshold for one endpoint only?

Tag requests and filter the threshold by tag.

http.get(`${base}/api/orders`, { tags: { name: 'orders' } });

export const options = {
  thresholds: { 'http_req_duration{name:orders}': ['p(99)<800'] },
};

33. How do you stop a test early when a threshold fails?

Use the object form with abortOnFail: true, and optionally delayAbortEval so early noise does not abort the run.

thresholds: {
  http_req_failed: [{ threshold: 'rate<0.05', abortOnFail: true, delayAbortEval: '1m' }],
},

34. How do you load test data once and share it across VUs?

Use SharedArray from k6/data. The function runs once, and the result is shared read-only between VUs instead of each VU holding its own copy, which saves memory with large files.

import { SharedArray } from 'k6/data';
const users = new SharedArray('users', () => JSON.parse(open('./users.json')));

35. How do you parameterise requests so each VU uses different data?

Index into the shared data with an execution counter, for example users[exec.scenario.iterationInTest % users.length] for unique rows per iteration, or users[exec.vu.idInTest - 1] for one row per VU.

36. How do you create a custom metric?

Import the type from k6/metrics, create it in the init context and add values in VU code.

import { Trend, Counter } from 'k6/metrics';
const searchTime = new Trend('search_time', true);
const ordersCreated = new Counter('orders_created');
// in VU code
searchTime.add(res.timings.duration);
ordersCreated.add(1);

The second argument to Trend marks values as time, so the summary shows milliseconds.

37. Why should you set the name tag for dynamic URLs?

Each distinct URL creates a separate time series. URLs with IDs such as /users/123 can create thousands of series and bloat outputs. Setting tags: { name: '/users/{id}' } or using the http.url template tag groups them under one name.

38. How does k6 decide that a request failed?

By default, responses with status codes from 200 to 399 count as expected, and others set http_req_failed. You can change this with http.setResponseCallback(http.expectedStatuses(...)), for example to treat a 404 as expected for a negative test.

39. How do you correlate dynamic values such as tokens?

Extract the value from one response and use it in the next request: res.json('token') for JSON, res.html().find(...) for HTML forms, then put it in headers. Logging in once in setup() is fine if all VUs can share one token.

40. What does http.batch() do?

It sends several requests in parallel from one VU, similar to a browser loading page resources. Requests are issued concurrently up to the batch and batchPerHost limits.

41. How do you export results in machine-readable form?

Use --out json=results.json or --out csv=results.csv for raw data points, or handleSummary() to write the end-of-test summary as JSON, JUnit-style XML or HTML. --summary-export is an older option for a JSON summary.

42. How do you send k6 metrics to Prometheus?

Use the Prometheus remote write output: k6 run -o experimental-prometheus-rw script.js with K6_PROMETHEUS_RW_SERVER_URL set. Prometheus must have the remote write receiver enabled. Then build or import Grafana dashboards on top. Details are in the Prometheus remote write output docs, and our post on using Prometheus and Grafana together covers the dashboards side.

43. What is the k6 web dashboard?

A built-in dashboard that shows metrics live in a browser while the test runs. Enable it with K6_WEB_DASHBOARD=true; it can also export an HTML report at the end with K6_WEB_DASHBOARD_EXPORT.

44. How do you run k6 in a CI pipeline?

Run the binary or the grafana/k6 image as a job step after deployment to a test environment. Thresholds turn a performance regression into a failing exit code, so the pipeline stops. Archive the summary file as an artifact. Our CI/CD quality gates post shows where such checks fit.

load_test:
  image:
    name: grafana/k6:latest
    entrypoint: [""]
  script:
    - k6 run --summary-export=summary.json tests/smoke.js
  artifacts:
    paths: [summary.json]

45. How do you write a k6 test in TypeScript?

Since k6 v1.0 you can run a .ts file directly, for example k6 run script.ts; k6 strips the types itself. Install the @types/k6 package for editor autocompletion. Type checking is not done by k6, so run tsc --noEmit separately if you want it.

46. How do you handle cookies?

k6 keeps a cookie jar per VU and handles Set-Cookie automatically within an iteration; the jar is reset between iterations. Use http.cookieJar() to read or set cookies manually, or pass cookies in request params.

Senior k6 interview questions

47. How do you size VUs for an arrival-rate test?

Use Little's Law: required concurrency is arrival rate multiplied by iteration duration. At 200 iterations per second and 0.5 seconds per iteration, you need about 100 VUs. Set preAllocatedVUs near that and maxVUs with headroom for slowdowns, then watch dropped_iterations.

48. How do you make sure the load generator is not the bottleneck?

Watch CPU, memory and network on the k6 machine. Above roughly 80 percent CPU, timings become unreliable. Reduce per-VU overhead (discardResponseBodies: true when bodies are not needed, fewer checks on large payloads, SharedArray), and split load across machines if needed.

49. How do you run a distributed k6 test on Kubernetes?

Install the k6 Operator and create a TestRun custom resource that points to the script (for example in a ConfigMap) with a parallelism value. The operator starts runner pods and splits the execution between them using execution segments. See running distributed tests.

50. What are execution segments?

A way to split one test into parts so several k6 instances can each run a fraction, using --execution-segment and --execution-segment-sequence. The k6 Operator uses them. Each instance aggregates its own metrics, so you need a shared output such as Prometheus or Grafana Cloud k6 to see the combined picture.

51. Why are percentiles from several k6 instances hard to combine?

You cannot average p95 values from separate instances and get the true p95 of the whole run. You need the raw data points or histograms in a central store, then compute percentiles there. This matters when you set thresholds on distributed runs.

52. What is xk6?

xk6 is the tool for building a custom k6 binary that includes extensions written in Go. Extensions add JavaScript modules (for example for Kafka or SQL) or new outputs. You build with xk6 build --with <module> and must then use that binary or image in CI.

53. How would you design a load testing strategy for a microservices platform?

Start with smoke tests in every pipeline, add average-load tests per critical journey before release, and run stress, spike and soak tests on a schedule against a production-like environment. Tie thresholds to SLOs, tag scenarios by journey, correlate k6 metrics with service traces and dashboards, and keep scripts versioned alongside the services they test.

54. How do you test a front end and the API in one run?

Combine a k6/browser scenario with a few VUs to measure user-facing metrics such as Web Vitals, and a protocol-level HTTP scenario that generates the bulk of the load. Browser VUs are much heavier than HTTP VUs, so keep their count small. See the k6 browser docs.

55. How do you keep test scripts maintainable across many teams?

Put shared code (auth helpers, request wrappers, standard thresholds and tags) in modules, keep environment details in variables, give each scenario a clear name tag, review scripts like production code, and version a small library of journeys rather than copying scripts per team.

56. How do you decide threshold values?

Derive them from SLOs and current production baselines, not guesses. Start with error rate and p95 or p99 latency per critical endpoint, add checks rate and dropped_iterations, then tighten as you gather history. Thresholds that never fail or always fail stop being useful.

Scenario-based k6 interview questions

57. p95 latency jumps only when VUs exceed 300. What do you check?

First confirm the generator is healthy. Then compare http_req_waiting with http_req_connecting and http_req_blocked: rising waiting time points at the server; rising blocked or connecting time points at connection limits or exhausted ports. Correlate with server CPU, thread pools, database connections and autoscaling events at that load.

58. The test passed in CI but users report slowness in production. What might be wrong?

The test may not match real traffic: too few endpoints, unrealistic think time, a closed model hiding queueing, cached or tiny test data, or an environment smaller than production. Compare production request mix and rates with the script, switch to arrival-rate executors and use production-like data volumes.

59. http_req_failed is 0 but the checks rate is 70 percent. Why?

The server returned 2xx or 3xx codes but the content was wrong, for example an error page with status 200 or an empty result list. That is exactly why checks on body content matter. Inspect failing check names and log a sample of bodies.

60. Many dropped_iterations appear halfway through an arrival-rate test. What do you do?

Responses slowed down, so iterations took longer and k6 ran out of VUs. Report that the system could not sustain the rate, check when latency started rising, and if you need the full rate for diagnosis, raise maxVUs and make sure the generator has capacity.

61. Each VU must log in once and reuse its session. How?

Log in on the first iteration of each VU (for example when exec.vu.iterationInScenario === 0), store the token in a module-level variable, and reuse it. Variables at module scope persist for the life of that VU. If one shared token is acceptable, log in once in setup().

62. The test needs to hit 50,000 requests per second. How do you plan it?

Estimate VUs with Little's Law, measure what one generator can sustain with a short trial, then distribute across machines with the k6 Operator or Grafana Cloud k6. Make sure the target's network path, rate limits and WAF rules allow it, and send metrics to a central store to aggregate percentiles correctly.

63. A script with a 300 MB data file runs out of memory. What is the fix?

Each VU loaded its own copy. Move the file into a SharedArray so it is parsed once, trim it to the fields you need, or split it per scenario. Also consider discardResponseBodies if response bodies are large.

64. You need to test a gRPC service. Outline the script.

Import Client from k6/net/grpc, load the proto file in the init context with client.load() (or use server reflection), connect in the VU code with client.connect(), call client.invoke('package.Service/Method', payload), check that status equals grpc.StatusOK, and close the connection when done.

65. Results vary widely between identical runs. How do you make them repeatable?

Fix the load model with arrival-rate executors, use the same data and environment size, warm up caches with a ramp before measuring, avoid shared environments with other tests, run from the same region, and compare several runs rather than a single one.

66. A product owner asks, "Can we handle Black Friday?" How do you answer with k6?

Get the expected peak rate and journey mix from analytics, script those journeys, run a ramping arrival-rate test to the target plus a safety margin, and hold it as a soak at peak. Report whether thresholds tied to SLOs held, where the first bottleneck appeared and what capacity remains, rather than a simple yes or no.

How to prepare for a k6 interview

  • Write one script that uses setup(), a SharedArray, checks, tags and two scenarios with different executors.
  • Add thresholds, make one fail on purpose and confirm the exit code is 99.
  • Stream results to Prometheus and build a Grafana panel for p95 by endpoint.
  • Be ready to explain open versus closed models with a small Little's Law calculation.
  • Read the release notes for the version the employer uses; k6 v1.0 changed several module paths and options.

To practise load testing alongside monitoring, our Prometheus and Grafana training covers the dashboards and alerting that k6 results feed into, in the Kharadi, Pune classroom or live online.

Frequently asked questions

Is k6 free to use?

Yes. k6 is open source under the AGPL-3.0 license and the binary is free. Grafana Cloud k6 is a separate hosted service with its own plans.

Which language are k6 tests written in?

JavaScript ES modules, and since k6 v1.0 TypeScript files can be run directly. The engine itself is written in Go and does not use Node.js.

What is the difference between a check and a threshold in k6?

A check records whether an individual response met a condition and never fails the test by itself. A threshold is a pass/fail rule on a metric for the whole run, and failing it makes k6 exit with code 99.

Which k6 executor should I use?

Use constant-arrival-rate or ramping-arrival-rate to model requests per second from many independent users. Use constant-vus or ramping-vus to model a fixed number of concurrent users.

Can k6 test databases or message queues?

Not with the built-in modules. Extensions built with xk6 add support for systems such as Kafka and SQL databases.

How do I see k6 results in Grafana?

Stream metrics with the experimental-prometheus-rw output to Prometheus, or to InfluxDB, and use a k6 dashboard in Grafana. The built-in web dashboard is a quicker option for a single run.

How many k6 questions are on this page?

66 numbered questions: 24 for freshers, 22 for two to five years of experience, 10 senior questions and 10 scenarios.

Official references

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.