Performance tests

Performance testing for APIs and microservices

API performance testing measures how the interfaces through which your systems communicate behave under load, without a browser or page rendering. It helps separate backend behaviour from the user interface and narrow the search for problems such as slow database queries, an exhausted connection pool, or an overloaded integration.

Common problem: the interface hides the cause of a slowdown

A test through the user interface is useful for verifying the complete customer journey, but it combines several layers at once. The browser adds rendering, script loading, and network requests, so the result alone may not show whether the slowdown originated in the API or while the page was being assembled.

With microservices, one service may call several others, and a slowdown in the chain appears externally as a “slow website”. Measuring selected APIs together with tracing and system metrics helps determine which part of the chain to investigate first.

How to measure performance directly at the API

We can first load-test selected API interfaces separately to measure their behaviour without browser overhead. It then makes sense to prepare a realistic mix of calls that reflects actual traffic. A separate measurement shows which call slows under a given load. The cause needs to be confirmed with application and infrastructure data.

We measure response times in percentiles (p95 and p99), along with the error rate and throughput. If server, database, and individual-service metrics are available, we compare them on one timeline. This makes it possible to narrow the search for a bottleneck to a particular endpoint, query, connection pool, or dependent service.

Depending on the risk, we choose a load, stress, or spike test: expected traffic presents a different question from a sudden surge. Scenarios in k6 or Locust can live in the repository, and selected checks of an appropriate size can also run in CI. Larger measurements usually run in a controlled environment and time window. These are the same APIs that we cover with functional tests, but here we measure their behaviour under load.

Describe load through calls, data and arrival rate

Virtual user count is not requests per second. One scenario may make several calls, wait for responses and pause between steps. The same user count may therefore send fewer requests when responses slow down. K6 distinguishes open and closed load models. Choose according to whether you model waiting users or new operations arriving independently of earlier completion.

A model mix may require 30 API requests per second: 80% catalogue reads and 20% order-draft creation. That means 24 reads and 6 writes per second, rather than 30 customers. Give each draft its own identifier and controlled data. Report authentication, token refresh and helper calls separately so their inclusion in the mix is clear.

Make the data representative of operation: catalogue size, response item count, distribution of search values and read/write ratio. Repeating one small cached response does not establish performance for varied queries. Do not introduce production personal data merely for realism.

Locust is available in Python. Its wait times regulate task frequency, rather than requests directly. A task with two calls is not one request. Waiting configuration also does not itself add users when a task takes too long. Compare planned load with actual calls in every tool.

Criteria must combine performance with correctness

For the model, agree before execution on p95 up to 400 ms for each of the two endpoints and no more than 1% failed requests in the steady measurement window. These illustrative limits do not replace your product requirements.

Area What to assess
Delivered load Planned 24 reads and 6 writes per second against actual calls.
Response time Each endpoint’s p95 separately, with sample count and time window.
Errors Timeouts, error responses and incorrect content under the agreed definition.
Write correctness Draft identifier, correct items and state, without unintended duplicates.
Recovery Reduction in queued work and response-time recovery after load decreases.

A fast HTTP 200 response with invalid data must not count as a correct operation. K6 checks evaluate conditions but do not themselves guarantee a failed run exit status. CI requires appropriate thresholds or another explicit failure rule. Verify it against a prepared incorrect result, rather than only a green report.

State what each metric measures too. K6 http_req_duration includes sending, waiting and receiving, but excludes initial DNS and connection setup. It is not the same as time until a page is displayed. Do not sum or average endpoint p95 values as the complete process’s p95.

Check the generator and the service chain

If the generator cannot start planned operations, results at lower load do not establish planned capacity. In k6, watch unstarted iterations in dropped_iterations. Configuration or longer operations in the tested system may cause them. Check the generator’s CPU, memory and network too. A dropped iteration is not an HTTP request rejected by the server.

Increase load in agreed steps and retain the metric timeline. Distributed tracing connects service operations when context propagation and the relevant instrumentation are in place. One slow trace supports a hypothesis, rather than establishing all requests’ behaviour. A missing span does not mean a dependency was never called.

After identifying a suspect query, pool or integration, change one condition. Repeat the same scenario with the same data, mix, configuration and measurement window. Compare performance, errors and correctness. Speed gained because the service stopped performing a required write is not a repair.

Before execution, approve the environment, external integrations, permitted writes and stop conditions. Draft-creation tests must not silently trigger payments, messages or reservations outside the agreed scope. Afterwards, locate and clean up only that run’s data. State conclusions for the verified configuration, without automatically extending them to production with different limits or dependencies.

What API measurement gives you

Next step

Select the API interfaces that matter to a key process or already show slow responses. Add the expected load, response-time and error-rate limits, and available system metrics. This information can be used to prepare a measurement that answers a specific capacity question.

Related topics

You might also be interested in

You want to know the capacity of the system in advance

Load and stress tests will show the behavior and capacity of the system in agreed conditions before the expected peak.