Imagine a product launch two weeks out. Marketing has an email going to a large list, a partner is announcing the integration on the same morning, and the React app and NestJS API have only ever served a few hundred people at once. Nobody knows whether launch morning looks like a normal Tuesday or ten times that, or which part gives out first.
That's the job of a load test: find where the system bends and breaks while there's still time to fix it, instead of learning it from users.
A useful pre-launch load test does six things:
- Starts from a target rate based on expected traffic, not from "let's hit it hard."
- Uses the right mix of test types, from a quick smoke test to a long soak.
- Applies load at a fixed arrival rate, so a slow server can't quietly reduce the pressure.
- Watches the database pool and the Node event loop, not just response times.
- Stays within what you're allowed to test, especially your identity provider.
- Ends in decisions: thresholds, alerts, and capacity changes.
Start from numbers, not from "let's hit it hard"
A load test needs a target, and the target should come from expected traffic. Work it out from a few estimates:
- How many people you expect in the busiest window, such as the first hour after the email goes out.
- What they do: how many API requests a typical visit makes, including the ones the React app fires on page load.
- How concentrated it is: traffic rarely spreads evenly, so plan for a peak several times the hourly average.
From those you get requests per second. Little's Law connects the numbers you'll see during the test: the average number of requests in the system equals the arrival rate multiplied by the average time each request spends there. If requests arrive at 200 per second and each takes 0.25 seconds on average, about 50 are in flight at any moment. If responses slow to one second, the same arrival rate means about 200 in flight, which is how a slowdown turns into a pile-up.
Treat these as averages. Little's Law describes the average, so multiplying a peak rate by a worst-case latency gives you a rough upper bound, not a precise concurrency figure. Add headroom above your estimate; you're guessing at launch traffic, and the test should cover being wrong.
Pick the right test types
The k6 documentation on test types describes six, and each answers a different question:
- Smoke test: validates that your script works and that the system performs adequately under minimal load. Run it first, every time.
- Average-load test: shows how the system behaves under expected normal conditions. This is your launch estimate.
- Stress test: shows how the system performs at its limits, when load exceeds the expected average.
- Spike test: checks behavior during sudden, short, massive increases, like the minute after an email lands.
- Soak test: checks reliability over extended periods. It finds slow problems like memory leaks, connection pool issues, and storage filling up.
- Breakpoint test: increases load gradually until the system reaches its capacity limit.
Two details from the k6 guides are worth knowing. A soak test should run much longer than your other tests. The soak testing guide lists typical durations of 3, 4, 8, 12, 24, and 48 to 72 hours. A five-minute run won't show a slow leak. Breakpoint tests don't suit an environment that autoscales. The breakpoint testing guide warns that an elastic environment may keep growing, so you find only the limit of your cloud bill.
Virtual users or arrival rate?
This choice changes what your results mean, and it's easy to miss.
Most tutorials start with a fixed number of virtual users (VUs), each looping through requests. That's a closed model: a VU waits for a response before sending the next request. The k6 page on open and closed models explains the catch. When the server slows down, a closed-model test waits, iterations take longer, and the test sends fewer requests. The slowdown reduces the load that caused it, and the results look better than reality. k6 calls this coordinated omission.
Real users don't wait for each other. The same page says that with arrival-rate executors, the target system's response times no longer influence the load. In k6, the executors constant-arrival-rate and ramping-arrival-rate start new iterations at a set rate, whatever the server is doing.
Two practical notes:
- Give k6 enough VUs to keep up. The VU allocation guide sizes them from the median iteration duration multiplied by the rate, plus extra for variance, which is Little's Law again.
- Watch the dropped-iterations metric. If k6 can't start iterations on schedule, it counts them in
dropped_iterations. A rising number means the test didn't deliver the load you asked for.
A closed model still has a place when you're modeling whole user sessions, but for "can the API handle this rate," use arrival rate.
What to watch while it runs
Response time alone won't tell you why the system is struggling. Watch these signals together.
Percentiles, not averages. Google's SRE book, in its chapter on monitoring distributed systems, gives an example: a service with an average latency of 100 ms at 1,000 requests per second could easily have 1% of requests taking five seconds. Track p95 and p99, plus the error rate.
The Node event loop. NestJS runs on a single JavaScript thread per process. Node's perf_hooks module provides monitorEventLoopDelay(), a histogram of event-loop delay, and eventLoopUtilization(), which reports how busy the loop is. Rising delay means work is blocking the thread: heavy JSON serialization, synchronous code, or CPU-bound hashing.
The libuv threadpool. Some operations, such as crypto.pbkdf2 and crypto.scrypt, run on libuv's threadpool, which has four threads by default according to the Node CLI documentation. The same page notes that setting UV_THREADPOOL_SIZE from inside your application isn't guaranteed to work, so set it in the environment before Node starts. A login endpoint that hashes passwords can queue up behind those four threads under load.
The database connection pool. This is the signal most guides skip. In node-postgres, the pool has a default max of 10 connections, and connectionTimeoutMillis defaults to 0, meaning no timeout. When all connections are busy, new requests wait in a queue until one is released. So with default settings, pool exhaustion doesn't show up as errors. It shows up as rising latency. Watch pool.waitingCount, which reports how many requests are queued for a connection.
The database itself. PostgreSQL's pg_stat_activity view shows one row per server process and its state. Many connections stuck in "idle in transaction" usually point to application code holding transactions open.
The containers. Memory growth over a soak test, CPU limits, and restarts all belong on the same dashboard.
Replicas times pool size versus the database limit
Scaling the API out can break the database. Every API instance has its own pool, so the database sees the total.
PostgreSQL's connection settings default max_connections to about 100. Managed tiers can be much lower. On Azure Database for PostgreSQL flexible server, the limits page lists the B1ms tier at 50 connections, with 35 available to users once reserved connections are taken out. As of November 2026, the same page says Burstable servers don't have access to the built-in PgBouncer connection pooler. When the limit is exceeded, clients get "FATAL: sorry, too many clients already."
Do the multiplication before the test, not during it. Four API replicas with the default pool of 10 need 40 connections, which already exceeds 35. Add a worker process and a migration job, and an autoscaling event during a spike can push the database over its limit at exactly the wrong moment. Either size the pools so the total fits, put a connection pooler in front of the database, or move to a tier with more connections.
Auth and test data
Most API routes need a logged-in user, which raises two problems: getting tokens, and not overloading your identity provider.
Don't load test the identity provider unless it allows it. Identity providers have their own rules and limits, current as of November 2026:
- Auth0: the load testing policy allows performance and load testing only with Auth0's prior written approval, and only for Enterprise customers. It requires at least two weeks' notice and allows one test per year, with up to two repeats.
- Microsoft Entra External ID: the service limits cap requests at 20 per second per IP and 200 per second per tenant. A single sign-in takes several requests, so that's far below what a load test generates.
- Firebase Authentication: the limits page caps new account creation at 100 per hour per IP address.
Get tokens once, then reuse them. k6's test lifecycle has a setup() stage that runs once before the load starts. Sign in a pool of test users there, or before the test, and give each VU a token from that pool. Your test then measures your API, not your login flow. If token lifetimes are shorter than the test, plan a refresh. Another option is to have your API accept tokens from a separate test-only issuer in the staging environment, so the identity provider isn't involved at all. If you do that, make sure that configuration can never reach production.
Use realistic data. A query that's fast against 200 rows can be slow against two million. Seed the test database with data volumes close to what you expect after launch, give each VU different records so caches don't flatter the results, and clean up what the test creates.
Where to test, and what you're allowed to hit
Test in an environment that resembles production. Microsoft's Well-Architected guidance on performance testing recommends a production-like environment. If staging is smaller, results don't scale up neatly. A database with fewer cores hits its limits sooner, and connection limits differ by tier. Write down what differs, and treat staging results as a lower bound.
Turn off autoscaling for the first runs. Autoscaling hides where a single instance tops out. Test at a fixed size first to find per-instance capacity, then test with autoscaling on to see how quickly it reacts to a spike.
Know your cloud provider's rules. Microsoft's penetration testing rules of engagement encourage simulating high traffic against your own application to test surge capacity, within your own tenant. They prohibit denial-of-service testing and network-intensive automated testing that generates excessive traffic, and Microsoft may interrupt tests in progress. Keep your load proportionate to your own target rate, aimed at your own resources. The page read in November 2026 didn't require advance notice for load testing, but read the current version before you start. On AWS, the DDoS simulation testing policy requires DDoS simulations to go through an approved partner.
Be careful with third-party APIs. The k6 guide to load testing websites says not to load test servers you don't own. Microsoft's Well-Architected guidance suggests including real third-party calls, because mocks hide real latency. Both have a point. A reasonable middle ground is to use the provider's sandbox at a rate it permits, or mock the dependency with realistic delays and measure the real one separately. Don't send load-test traffic to a payment provider, email service, or partner API without their permission.
Tools: k6, real browsers, and Azure Load Testing
k6 for API load. k6 scripts are JavaScript, which suits a TypeScript team, and they run from a laptop, a CI runner, or Grafana's hosted service.
A few real browsers for the front end. Protocol-level load doesn't render your React app. The k6 browser module drives real browsers, and the websites guide recommends putting most of the load at the protocol level and adding a small number of browser VUs to measure what users actually see.
Lighthouse is not a load test. Lighthouse audits a single page load for performance, accessibility, and more. It's useful, but it tells you nothing about how your API behaves with a thousand people using it.
Azure Load Testing runs JMeter and Locust, not k6. Azure Load Testing is a managed service for generating large loads. As of November 2026, its overview says it supports Apache JMeter and Locust and no other frameworks. If your team standardizes on k6 scripts, you'd need to rewrite them or run k6 elsewhere. Azure Load Testing is billed per virtual user hour, and its service limits cover engine instances and test duration, so check them against your plan.
Turn results into decisions
A load test that ends with "it seemed fine" hasn't done its job. Make the results act on something.
Make pass and fail explicit. k6 thresholds set pass or fail criteria, such as p95 latency under a target and an error rate under 1%. A failed threshold gives k6 a non-zero exit code, which fails a CI job. Checks are different: they record whether responses look right, but on their own they don't change the exit status. The abortOnFail option stops a test early once a threshold fails, which keeps a stress test from running on after the answer is clear.
Run a smoke test in CI. A short, low-load run on each merge catches a script that no longer works and an obvious performance regression. Keep the heavy tests for scheduled runs or before releases.
Alert on the same signals in production. The p95 latency, error rate, event-loop delay, and pool waiting count you watched during the test are the same signals to alert on after launch.
Make capacity decisions:
- Size pools so replicas times pool size fits the database limit.
- Decide on instance counts or autoscaling rules based on per-instance capacity.
- Fix the bottleneck you found, such as a slow query, a missing index, or a blocking call, then test again.
- Decide what happens beyond capacity. Rejecting some requests quickly is often better than letting all of them time out.
Pre-launch checklist
- Estimate peak traffic and convert it into a target request rate, with headroom.
- Run a smoke test first, then average-load, stress, spike, and a soak of several hours.
- Use arrival-rate executors for API capacity, and watch
dropped_iterations. - Track p95 and p99 latency and the error rate, not averages.
- Watch event-loop delay, the threadpool on CPU-heavy routes, and the pool waiting count.
- Multiply replicas by pool size and compare the result with the database connection limit.
- Keep load off your identity provider: get tokens once, or use a test-only issuer in staging.
- Seed realistic data volumes and clean up afterward.
- Test in a production-like environment, with autoscaling off for the first runs.
- Follow your cloud provider's rules, and don't load test third-party services without permission.
- Set thresholds as pass or fail, and run a smoke test in CI.
- Turn findings into alerts, capacity changes, and fixes, then test again.



