Load tests before deploy
Functional tests tell you the code is correct. Load tests tell you the code is fast enough. You do not need a full performance engineering setup for this to pay off: a small script that hits your hottest endpoint a few hundred times per second is enough to catch the majority of performance regressions before deploy.
load/books.js
javascript
import http from 'k6/http';
import { check } from 'k6';
export const options = {
stages: [
{ duration: '30s', target: 50 },
{ duration: '1m', target: 50 },
{ duration: '30s', target: 0 },
],
thresholds: {
'http_req_duration': ['p(95)<300'], // 95% under 300ms
'http_req_failed': ['rate<0.01'], // less than 1% errors
},
};
export default function () {
const res = http.get('http://localhost:3000/api/v1/books?limit=20');
check(res, { 'status 200': (r) => r.status === 200 });
}A minimal k6 script. Ramp up, hold, ramp down.
The thresholds turn the load test into a pass-or-fail gate. p95 under 300ms and error rate under one percent are reasonable defaults for a healthy catalog endpoint. Tune them to what matters in your system. Wire the script into your CI pipeline for the hot endpoints and you will catch performance regressions before users do.
Quiz: Quiz
Loading practice…