Skip to content
← All insights
SQL6 min read

When a slow API is really a database problem

The endpoint gets blamed first. Often the useful evidence is in the query plan, connection pool or data model.

Trace the whole request

Measure where the time is spent before changing application code. One slow query, an exhausted connection pool or repeated calls inside a loop can all look like a slow API from the outside.

Fix the cause, not only the query

An index may solve today’s symptom. It may also hide a data-access pattern that will fail again as the dataset grows. Look at the query, the schema and why the application asks for the data in that shape.

  • Capture representative query timings
  • Read the execution plan
  • Check connection and transaction behaviour
  • Test with realistic data volume
Inspect the plan before adding an indexsql
EXPLAIN (ANALYZE, BUFFERS)
SELECT id, created_at, total
FROM orders
WHERE customer_id = 42
ORDER BY created_at DESC
LIMIT 25;

CREATE INDEX CONCURRENTLY idx_orders_customer_created
  ON orders (customer_id, created_at DESC);