Load Testing AI Apps: How We Handle 500+ Concurrent Users

By , Founder & CTOUpdated 6 min read

Short answer

We load-tested our AI platform with k6 from 10 to 500 concurrent users. Three failures appeared — WebSocket connection exhaustion, Redis connection timeouts and LLM API rate limits — and we fixed them with connection pooling, a load balancer, backpressure queues and automatic failover between model providers. AI apps need load tests that cover the full streaming journey and the model provider's rate limits, not just HTTP endpoints.

Key takeaways

  • Load-test the full user journey, including streaming and model calls, not just HTTP endpoints.
  • Measure tail latency (p95/p99), time to first token, dropped connections and provider throttling, not averages.
  • Connection pools and backpressure are the usual fixes for failures under concurrency.
  • Multi-provider LLM failover protects you from rate limits at peak load.

When we say we've tested at 500+ concurrent users, we don't mean we ran a quick Locust script and called it done. We mean we systematically broke the system, identified every failure point, and fixed them before shipping.

Here's what that actually looked like, plus what makes load testing AI applications different from testing an ordinary web app, and a checklist you can use for your own.

Why is load testing AI apps different?

A typical web request is short: the browser asks, the server answers in milliseconds, the connection closes. AI applications break most of those assumptions:

  • Connections are long-lived. Streaming responses over WebSockets or server-sent events hold a connection open for seconds. Concurrency is limited by open connections, not just requests per second.
  • Latency is dominated by the model. A model call can take seconds, and its latency varies with output length and provider load. Averages hide the slow tail that users actually notice.
  • The bottleneck may not be yours. LLM providers limit requests and tokens per minute. Your infrastructure can be fine while the provider throttles you.
  • Every test call costs money. Running hundreds of virtual users against a real model API is a real bill, so test runs need to be planned, not run casually.
  • Inputs are heavy. Voice, images and documents mean large payloads, and transcription or parsing adds its own latency before the model even starts.

A load test that only hits a health-check endpoint, or sends tiny text prompts, will tell you very little about how the real product behaves at peak.

The Architecture

Our Base Infrastructure runs on a microservices pattern. An API gateway handles authentication and routing. Behind it sit three core services: a transcription service (Whisper/Deepgram), an AI orchestration service (model-agnostic, routes to Claude or OpenAI based on task type), and a streaming service that manages WebSocket connections and SSE streams.

State lives in PostgreSQL. Session data lives in Redis with TTLs. Inter-service communication goes through a Redis Streams message queue for async operations and direct HTTP for synchronous ones.

The Load Test

We used k6 for load testing. The test scenario: a user connects via WebSocket, sends a voice message (simulated as a binary payload), receives a streaming text response, and disconnects. We ramped from 10 to 500 concurrent virtual users over 5 minutes, held at 500 for 10 minutes, then ramped down.

A simplified k6 script for this kind of scenario looks like this. The message format depends on your own protocol; here the server sends {"type":"done"} when the streamed response is complete:

import ws from "k6/ws";
import { check } from "k6";
import { Trend } from "k6/metrics";

const audio = open("./sample-voice-message.wav", "b"); // binary payload
const roundTrip = new Trend("round_trip_ms", true);

export const options = {
  scenarios: {
    voice: {
      executor: "ramping-vus",
      startVUs: 10,
      stages: [
        { duration: "5m", target: 500 }, // ramp up
        { duration: "10m", target: 500 }, // hold at peak
        { duration: "2m", target: 0 }, // ramp down
      ],
    },
  },
  thresholds: {
    round_trip_ms: ["p(99)<2400"],
    checks: ["rate>0.99"],
  },
};

export default function () {
  const res = ws.connect(__ENV.WS_URL, {}, (socket) => {
    let sentAt = 0;
    socket.on("open", () => {
      sentAt = Date.now();
      socket.sendBinary(audio);
    });
    socket.on("message", (msg) => {
      if (JSON.parse(msg).type === "done") {
        roundTrip.add(Date.now() - sentAt);
        socket.close();
      }
    });
    socket.setTimeout(() => socket.close(), 30000); // never hang a VU forever
  });
  check(res, { "connected (101)": (r) => r && r.status === 101 });
}

Thresholds turn the test into a pass/fail gate: if p99 round-trip time or the success rate misses the target, the run fails, which makes it usable in CI before a release.

Failure mode 1: WebSocket connection pool exhaustion. At around 300 concurrent users, the streaming service started refusing connections. Root cause: the default Node.js HTTP server backlog was too small. Fix: explicit connection pool configuration and a load balancer in front of the streaming service.

Failure mode 2: Redis connection timeouts. At peak load, session reads were timing out. Root cause: a single Redis connection being shared across async handlers. Fix: a proper connection pool with min/max bounds and timeout configuration.

Failure mode 3: AI API rate limits. At 500 concurrent users, we hit OpenAI's rate limits. Fix: a request queue with backpressure, exponential backoff, and automatic failover to Claude when OpenAI is throttled.

How do backpressure and provider failover work?

The third failure is the one most specific to AI systems, and the fix has three parts that work together:

  • A queue in front of the model. Instead of every user request calling the provider directly, requests go into a queue drained at a rate the provider accepts. When the queue grows past a limit, new requests get a fast, honest "busy, retrying" response instead of timing out.
  • Exponential backoff with jitter. When the provider returns a rate-limit error, retry after an increasing delay, with some randomness so hundreds of clients don't all retry at the same instant.
  • Failover to a second provider. When one provider is throttled, route eligible requests to another. This only works if the model sits behind an abstraction and prompts have been tested on both models; failover to a model that behaves differently is a quality incident, not a fix.

Keeping the model behind an abstraction is a theme across everything we build. Our guide to choosing between Claude, GPT and Gemini covers how to pick models per task, and how to reduce LLM API costs covers routing and caching, which also reduce load on the provider.

The Results

After these fixes: 500 concurrent users, p99 latency under 2.4 seconds for a full round trip (voice-in to text-out), zero connection drops, zero dropped messages. Horizontal scaling via Kubernetes adds capacity linearly when needed.

We publish these numbers because they're the only credible evidence that a system works. Architecture diagrams don't prove anything. Load test results do.

Which metrics should you watch during the test?

Track these per run and compare them between runs:

MetricWhy it matters
Round-trip latency, p50 / p95 / p99Users feel the tail, not the average
Time to first tokenFor streaming, it decides whether the app feels responsive
Connection errors and dropsThe first sign of exhausted pools, backlogs or file-descriptor limits
Provider throttling (HTTP 429)Shows when the model provider, not your stack, is the limit
Queue depth and wait timeShows whether backpressure is absorbing spikes or hiding a growing backlog
CPU, memory and connections per servicePoints to which service to scale or tune
Cost per request at peakLoad changes routing, retries and cache hit rates, which all change cost

Collect them with the same tracing and metrics you use in production, so a load test is also a test of your monitoring. Our post on LLM observability covers what to instrument.

A load-testing checklist for AI applications

  • Script the real user journey, including uploads, streaming and disconnects, with realistic payload sizes.
  • Ramp gradually and hold at peak long enough to expose leaks and slow build-ups, not just the first spike.
  • Run against a stubbed model with realistic delays to test your own infrastructure cheaply and repeatably.
  • Run at least once against the real provider before launch, with a budget, to find true latency and rate limits.
  • Set thresholds on tail latency and error rate so the test passes or fails, and run it before major releases.
  • Test failure paths: kill a service, throttle the provider, and check the system degrades gracefully.
  • Record and publish what you tested, so the results mean something to the people relying on them.

Load testing is one part of the engineering underneath reliable AI products. We make the broader case in why engineering depth beats prompt cleverness, and it's built into our AI platform and infrastructure work. If you're preparing an AI product for real traffic, talk to us.

Frequently asked questions

How do you load test an LLM application?

Script the real user journey — connect, send input, receive the streamed response, disconnect — with a tool like k6, ramp concurrency gradually, and hold at peak while measuring latency percentiles, errors and dropped connections.

What breaks first when an AI app scales?

In our testing it was connection handling: WebSocket backlogs, shared database or Redis connections, and then provider rate limits on the LLM API.

How do you handle LLM API rate limits?

Queue requests with backpressure, retry with exponential backoff, and fail over to a second provider when one is throttled.

Why publish load test results?

Numbers from a real test are better evidence that a system works than architecture diagrams, and they show buyers exactly what was tested.

Should you call the real LLM API during a load test?

Do both. A stubbed model that returns canned, realistically delayed responses tests your own infrastructure cheaply and repeatably. A run against the real provider is the only way to find its rate limits and true latency, so budget for it and run it before launch.

Which metrics matter most in an AI load test?

Tail latency (p95 and p99) for the full round trip, time to first token for streaming responses, error and dropped-connection rates, provider 429 or throttling responses, and cost per request at peak.

Written by

Ved Patel · Founder & CTO, KeyVed

Full-stack engineer with 8+ years building distributed systems. Led engineering at two fintech startups before founding KeyVed. Obsessed with production-grade AI infrastructure.

Meet the team →

Want to see how we build these systems for clients?

Let's talk →

Keep reading