Load testing with k6
Scripted scenarios in JS, stages (ramp/soak/spike), thresholds as pass/fail gates, open vs closed workload models. k6 thresholds make perf a CI check, not a report.
The mental model
Load testing asks one question — "will it survive launch day?" — and k6 answers it by turning that question into a program that fails a build, not a report nobody reads. The shift k6 represents is cultural before it's technical: performance stops being a quarterly PDF full of graphs and becomes a CI check like lint, with a pass/fail gate called a threshold. If p95 latency crosses your budget or error rate crosses 1%, the build goes red. That's the whole pitch.
The analogy that sticks: load testing is a wind-tunnel test for a car you're about to sell. You don't wait for customers to drive at 200 km/h and crash; you put the car in the tunnel, ramp the wind, and watch where the panels start to peel — the point of failure — *before* shipping. The knee of the latency curve is where the panels peel: the load level at which p95 latency departs from flat and starts climbing toward a cliff. Below the knee, adding load barely moves latency; above it, small load increases cause large latency jumps. Your job is to find that load and run production comfortably below it.
The one idea that trips up almost everyone: open vs closed workload models. A *closed* model has a fixed number of virtual users (VUs) each doing "request, wait for response, request again" — so when the app slows down, the VUs *automatically slow their request rate*, and you accidentally stop applying the load you meant to. This is coordinated omission: your latency numbers look great while the app is dying, because you stopped pushing exactly when it started struggling. An open model (constant arrival rate) keeps sending requests at a fixed rate regardless of how the app responds — like real users who keep clicking whether or not the page loaded. Real traffic is open; testing closed lies to you. Get this wrong and every number you report is optimistic.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision