Prompt
How do I tell if a slowdown is from code, database, or API?
Latest observation
Oct 20, 2026
OpenAI APIWeb search: off
A good way to tell is to measure each boundary separately and look for where the time accumulates.
Quick mental model
A request is usually slowed by one of these:
- Code / app logic: CPU work, loops, serialization, locking, memory pressure
- Database: slow queries, missing indexes, contention, too many round trips
- External API: network latency, slow downstream service, retries, rate limits
A practical checklist
1) Split the request into timings
Add timing around each major step:
- request start → app logic start
- app logic before DB → after DB
- before external API → after external API
- response build → response sent
If you see:
- Most time before any DB/API call → likely code
- Most time inside DB calls → likely database
- Most time inside HTTP/API calls → likely external API
2) Compare app time vs dependency time
Look at:
- Total request time
- Time spent in DB
- Time spent in outbound API calls
- CPU usage
Interpretation:
- High request time, low DB/API time, high CPU → code problem
- High request time, high DB time → database problem
- High request time, high external call time → API problem
3) Check whether it scales with traffic
- If slowdown gets worse with more traffic and CPU is high, it may be app code or DB contention.
- If slowdown happens only on certain queries or endpoints, it may be a specific DB query or API call.
- If latency is spiky and correlated with network errors/retries, it may be the API.
4) Look at failure patterns
- Code: timeouts, memory spikes, GC pauses, thread pool exhaustion
- Database: slow query logs, lock waits, deadlocks, high rows scanned
- API: 429s, 5xxs, retries, connection timeouts, DNS/network issues
5) Use tracing if possible
Distributed tracing makes this much easier. A trace will show:
- time in your service
- time in DB
- time in each outbound API call
Tools:
- OpenTelemetry
- Datadog APM
- New Relic
- Jaeger / Zipkin
Fast isolation tests
If you need a quick answer:
- Disable or mock the external API: if latency disappears, it’s API-related
- Run the DB query directly: if it’s slow standalone, it’s DB-related
- Profile the app without DB/API calls: if still slow, it’s code-related
Rule of thumb
- Slow before any dependency call = code
- Slow during SQL = database
- Slow during HTTP calls = external API
If you want, I can give you a simple step-by-step debugging flowchart or a sample logging/tracing setup to pinpoint this in your stack.
Brands