Prompt
How do I load test APIs with concurrent users
Latest observation
Oct 20, 2026
OpenAI APIWeb search: off
To load test APIs with concurrent users, you want to simulate many clients hitting your endpoints at the same time and measure how the system behaves under increasing load.
1) Define what you want to measure
Typical goals:
- Throughput: requests per second
- Latency: p50, p95, p99 response times
- Error rate: 4xx/5xx, timeouts
- Resource usage: CPU, memory, DB connections, queue depth
2) Choose a load testing tool
Common options:
- k6 — modern, scriptable, easy to use
- JMeter — GUI-based, widely used
- Locust — Python-based, flexible
- Gatling — Scala-based, strong performance
- Postman/Newman — okay for basic collection runs, not ideal for real load
3) Create a test scenario
Decide:
- Which endpoints to call
- Request mix and user flows
- Authentication/session handling
- Payload sizes and data variation
- Think time between requests
Example scenario:
- 70%
GET /products - 20%
POST /cart - 10%
POST /checkout
4) Start with a baseline and ramp up gradually
A good pattern:
- Warm-up: low traffic for 1–5 minutes
- Ramp-up: increase users over time
- Steady state: hold a fixed load
- Stress test: push beyond expected peak
- Spike test: sudden jump in traffic
Example ramp:
- 10 users for 2 min
- 50 users for 5 min
- 100 users for 10 min
- 200 users until failure
5) Concurrency vs. arrival rate
There are two common ways to model load:
- Concurrent users: N virtual users running in parallel
- Requests per second: a fixed rate of incoming traffic
Use whichever matches your real-world traffic better. For APIs, arrival-rate testing can be more realistic if you know expected RPS.
6) Example with k6
Here’s a simple k6 script that simulates concurrent users:
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '1m', target: 10 },
{ duration: '3m', target: 50 },
{ duration: '5m', target: 100 },
{ duration: '2m', target: 0 },
],
};
export default function () {
const res = http.get('https://api.example.com/products');
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
Run it:
k6 run script.js
7) Example with Locust
from locust import HttpUser, task, between
class ApiUser(HttpUser):
wait_time = between(1, 3)
@task
def get_products(self):
self.client.get("/products")
Run:
locust -f locustfile.py
8) Monitor the backend while testing
Use:
- Application logs
- APM tools like Datadog, New Relic, Grafana/Prometheus
- DB metrics
- Cache metrics
- Queue metrics
This helps you find the bottleneck:
- Database saturation
- Thread pool exhaustion
- Slow external services
- Memory leaks
- Lock contention
9) Validate test realism
Make sure your test includes:
- Realistic headers and auth tokens
- Correct data shape
- Correlated requests where needed
- Rate limits and retry behavior
- Unique test data for writes
10) Interpret results
Look for:
- Latency growing sharply as load increases
- Error rate spikes
- Saturation points
- Whether the system meets your SLA/SLO
11) Best practices
- Test in a staging environment close to production
- Avoid using production data unless approved
- Isolate test traffic from real users
- Ensure the load generator itself is not the bottleneck
- Use multiple load generators if needed
If you want, I can give you:
- a k6 script for your specific API,
- a Locust example, or
- a step-by-step load test plan for your environment.