Skip to content
EngPlain

Article

How to Debug Slow API Responses Without Guessing

Most “the API is slow” tickets waste hours because teams jump into code first. Start with timing, then isolate the layer, then fix the real bottleneck.

Share

Lead with the symptom, not the stack. “Slow API” can mean DNS, TLS, auth, query, serialization, or the client waiting on three chained calls. If you change code before you measure, you’ll “fix” the wrong thing.

Measure first

Capture three numbers for the same request:

  • Total time from client send to response received

  • Server time inside your handler

  • Downstream time (DB, cache, third-party APIs)

If client time is high but server time is low, look at network, payload size, or client-side waiting. If server time is high, stay on the backend.

Isolate the layer

Walk the request path once:

  1. Edge / reverse proxy

  2. App framework middleware

  3. Business logic

  4. Database / cache

  5. External services

Add timing logs or spans around each step. One slow span usually explains the whole request.

Common fixes that actually help

  • Add an index for the exact filter + sort your query uses

  • Stop N+1 queries (batch or join)

  • Cache stable reads with a clear TTL and invalidation rule

  • Shrink payloads — don’t return fields the UI never shows

  • Make independent downstream calls in parallel, not in series

What to avoid

Don’t rewrite the service. Don’t add microservices. Don’t “optimize later” without a baseline. Ship one change, remeasure the same endpoint, keep the before/after numbers in the PR.

Bottom line: timing first, isolate second, fix third. Guessing feels fast until it costs a week.

EngPlain