API latency learning path Level 2 This level · 1 of 7
Medium java backend

Set a baseline (k6, JMeter or Locust; p50, p95, p99 and throughput)

The 30 second answer

Before changing anything, I run a load test with a tool like k6, JMeter or Locust and record p50, p95, p99 and throughput at a known request rate. Averages hide the slow tail that real users feel, so percentiles are the baseline. Every later optimization is compared against this same test, so I can prove the change actually helped and did not just move the problem.

Could you say this in an interview?

Load-test tools replay traffic and report percentiles. An average hides the tail: a few very slow requests barely move the mean, but those users feel it. The Google SRE book recommends percentiles because latency distributions are skewed.

// k6: fail the test if p95 > 300 ms or p99 > 600 ms
export const options = { thresholds: { http_req_duration: ['p(95)<300', 'p(99)<600'] } };

Alternate interview scenarios

"How do you implement performance testing?"

Performance testing means I define a load, I measure latency and error rate against a baseline, and I change one thing at a time. I use a tool such as k6, JMeter or Locust, and I record p50/p95/p99 and throughput, not only the average.

// k6 sketch
import http from 'k6/http';
export const options = { vus: 20, duration: '1m' };
export default function () {
  http.get('https://api.example.com/orders/42');
}

I run the same test against a baseline and against the change. A single laptop test against a shared database is not enough to claim a production number; I say what I measured and on what hardware.

Sources (5)
  1. k6 thresholdsgrafana.com
  2. Apache JMeter user manualjmeter.apache.org
  3. Locust docsdocs.locust.io
  4. Google SRE book, Service Level Objectivessre.google
  5. Gil Tene, "How NOT to Measure Latency"infoq.com
Previous
Next