The most common bottlenecks in web applications and APIs
Updated:
The system has slowed, customers are waiting longer, and the team needs to decide whether a more powerful server, an application change, or a database change will help. Without measurement, it is easy to invest in a solution that only reduces the symptom.
Underprovisioned infrastructure is one possible cause. A slowdown can also originate in a database query, an insufficient number of connections, an external-service call, or another specific point that begins to constrain the entire system under higher load.
Common problems: where systems tend to slow down
Slow SQL queries. A query that is fast with a small volume of data may take much longer with a larger table. When many identical queries run concurrently, they can load the database and slow the application.
Missing or unsuitable indexes. The database may scan a large part of a table for some queries even though an appropriate index would speed up the search. An index is not a free fix: it consumes space and can slow down writes. A proposed change therefore needs to be verified with the query execution plan and measurement after the change.
N+1 queries. The application loads a list of orders with one query and then sends another query for the details of each order. With twenty items on a page, it executes twenty-one queries. Under load, their combined effect can put significant pressure on the database even though each individual query looks fast.
An exhausted database connection pool. The application has a limited number of database connections. When all of them are occupied, further requests wait in a queue even if some system metrics do not yet show high utilisation. The cause may be an unsuitable pool size, long-running queries, or connections that are not released in time.
Underprovisioned infrastructure. CPU, memory, the network, or storage may be the true bottleneck. A scaling decision should be based on measurement that shows which resource is reaching its limit and how this relates to worse response times or a higher error rate.
How to find the actual cause
We view load-test response-time percentiles, error rates and throughput alongside server metrics on a shared timeline.
A shared timeline helps reveal relationships. If the number of requests waiting for a database connection increases at the same time as p95, there is a reasonable hypothesis that the problem lies in this area. Timing alone does not prove the cause, however. It needs to be confirmed with logs, configuration, profiling, or a repeated test after a targeted change.
We select scenarios around important customer journeys. The home page may load different parts of the system than search, the cart, or payment. The selected scenario therefore directly affects which bottlenecks appear in the test.
We gradually increase the load, monitor the agreed limits, and record the point at which response times or the error rate worsen. System metrics then help identify the resource that should be investigated first.
Start with a particular slow operation
Separate search, sign-in, order creation and background jobs. Aggregate p95 may change because the operation mix changed. Record the application version, time, input data and achieved load. Otherwise two curves may describe different problems.
A distributed trace shows the request’s path through individual operations. It helps distinguish application, database and external-service time. Do not add nested or parallel durations as independent portions of the total wait. Inspect their timeline and what each measured section includes.
A missing trace does not prove the problem never occurred. Verify instrumentation coverage and trace sampling rules. Browser and server measurements may cover different intervals. If the server responds quickly but the customer waits, investigate the network and page processing too rather than automatically blaming the database.
Symptoms determine the next check
This table helps choose a next step. It is a diagnostic aid, rather than proof of a particular fault:
| Symptom | What to investigate | What not to conclude yet |
|---|---|---|
| Time is spent in a SQL operation | Plan, row count, repeated queries and waiting | Every slow query needs a new index |
| Connection waiting increases | Pool occupancy, holding time and unreleased connections | A larger pool always improves performance |
| An external call takes longer | Dependency response, network, limits and retries | The supplier is definitely responsible |
| Resource utilisation and response time rise | Application profile and the particular resource’s limit | A larger server is the only repair |
For a suspected cause, choose comparable successful and slow requests. Different data or downstream-call counts may explain more than a server-wide average. Check concurrent batches and configuration changes too. The bottleneck need not stay the same across every run.
Read a query plan in its context
PostgreSQL distinguishes a plan estimate from actual execution with EXPLAIN ANALYZE. Plan cost is not time in milliseconds. ANALYZE executes the statement and adds measurement overhead. For a statement that modifies data, it is therefore not harmless plan inspection.
Prepare diagnosis with the database owner in a controlled environment. Use appropriate data volume and distribution, representative filters and current statistics. A small-table result may not explain a slow production query. Record the cache state and whether waiting occurs under both standalone and concurrent execution.
Verify a new index against the relevant reads and writes. For N+1, track database-call count and total time per operation. Reducing queries must preserve correct data and must not merely shift the cost into loading an unnecessarily large result.
Larger pools and retries may shift pressure
HikariCP notes that appropriate pool size depends on deployment. Consider every application instance and other database clients. Our example: four instances with a maximum of 20 connections may together request up to 80 connections. That is a configured total, rather than actual occupancy or a recommended size.
If a slow operation holds connections, expanding the pool may permit more concurrent work on an already overloaded database. First check holding time, release and whole-service limits. After each change, monitor queues and errors too, rather than connection-allocation waiting alone.
AWS explains how retries amplify overload. Set a finite attempt count, appropriate waiting and protection against duplicate writes. A shorter timeout without changing retries may create more attempts rather than a faster service.
A repair must help with comparable work
Repeat the same journey with comparable data, load profile, configuration and cache state. Record different conditions in the comparison. A faster run with fewer orders or earlier request rejection alone does not establish improved capacity.
Track response times, completed operations, error rates and correct outcomes. Check other important journeys affected by the change. As load falls, verify recovery to a usable service state and pending-job processing. Make any new bottleneck visible in the report.
A recommendation may also be a temporary measure before a permanent repair. Define its limits, owner, rollback condition and next measurement. The team can then see what actually improved and which hypothesis still needs evidence.
What an identified bottleneck gives you
You receive measured symptoms, a likely cause, and a plan for verifying it. Recommendations can be ranked by risk, expected benefit, and effort.
A targeted change to a query, index, or configuration may be less expensive than scaling the infrastructure, but the appropriate solution depends on the confirmed cause and operational requirements. If, for example, an N+1 query causes the problem, a larger server may only move the capacity limit without removing the inefficient behaviour.
After the recommendation has been implemented, the test can be repeated to verify whether the capacity limit has moved.
Next step
Record the scenario in which the system slows down, the time of the problem, and the available application, database, and infrastructure metrics. This information will help prepare a targeted test and distinguish likely causes from a coincidental timing match.