Interview Prep/SRE & Reliability/Capacity, Load Testing & Chaos Engineering

Write a minimal k6 test with SLO thresholds.

IntermediateConceptCapacity, Load Testing & Chaos Engineering
Answer
import http from 'k6/http';
import { check } from 'k6';

export const options = {
  vus: 50,
  duration: '5m',
  thresholds: {
    http_req_failed: ['rate<0.001'],                 // 99.9% availability
    http_req_duration: ['p(95)<200', 'p(99)<300'],   // latency in ms
  },
};

export default function () {
  const res = http.get(`${__ENV.BASE_URL}/api/checkout`);
  check(res, { 'status is 200': (r) => r.status === 200 });
}

Run with k6 run -e BASE_URL=https://staging.example.com test.js. If any threshold fails, k6 exits with code 99, which fails the CI job.

All SRE & Reliability questions Roadmap: SRE & incident response

More on Capacity, Load Testing & Chaos Engineering