Prompt
I need help figuring out whether my slowdowns are caused by the app, database, or third-party services
Latest observation
Yes — the fastest way to figure this out is to isolate each layer and compare timing at the boundaries. Here’s a practical approach you can use.
1) First, define the symptom
Ask:
- Is the slowdown everywhere or only on certain pages/actions?
- Is it consistently slow or only at peak times?
- Is it high latency, timeouts, or bad throughput?
- Did it start after a deploy, schema change, config change, or vendor outage?
2) Break the request into 3 buckets
For any slow user-facing action, measure:
A. App time
Time spent in your application code:
- auth/session handling
- serialization/deserialization
- business logic
- template rendering / API response formatting
- queue waits if applicable
B. Database time
Time spent waiting on DB:
- query execution
- connection acquisition
- lock waits / deadlocks
- slow indexes / table scans
- too many queries / N+1 patterns
C. Third-party time
Time spent waiting on external dependencies:
- payment APIs
- auth providers
- email/SMS vendors
- object storage/CDN
- analytics or feature flag services
3) Add timing at each boundary
If you already have logs or APM, use them. If not, instrument the request path so each external call gets its own timer.
Example breakdown:
- request total: 1200 ms
- app logic: 80 ms
- DB: 150 ms
- external API: 900 ms
- remaining overhead: 70 ms
If one layer dominates, you’ve found the likely culprit.
Best signal
If the sum of measured subspans is close to total time, your instrumentation is good. If there’s a big gap, you may be missing:
- queueing
- thread pool exhaustion
- connection pool waits
- GC pauses
- network overhead
- cold starts
4) Use APM/tracing if available
Tools like:
- OpenTelemetry
- Datadog APM
- New Relic
- Dynatrace
- Honeycomb
These show distributed traces and make it easy to see:
- which span is slow
- whether the DB or vendor is the bottleneck
- whether slowness is isolated to certain endpoints or tenants
If you have microservices, distributed tracing is especially important.
5) Check DB-specific indicators
If the app seems slow but traces point to DB, check:
- slow query log
EXPLAIN/EXPLAIN ANALYZE- lock contention
- CPU, IOPS, memory pressure
- connection pool saturation
- number of queries per request
- missing indexes
- large result sets
- replication lag if reads go to replicas
Common signs it’s the DB:
- app waits on DB most of the time
- identical endpoint slows down as data grows
- DB CPU or locks spike during slowdown
- queries are fast in isolation but slow under load
6) Check third-party indicators
If vendor calls dominate, look for:
- vendor latency dashboards/status pages
- timeout rates
- retries causing amplified delay
- circuit breaker behavior
- network/DNS issues
- regional mismatches
Common signs it’s a third party:
- only endpoints depending on that service are slow
- internal-only actions are normal
- vendor latency aligns with your incidents
- retries make one slow call become much slower
7) Compare with a control test
A very effective test:
- Run the app endpoint with DB mocked/stubbed
- Run the same path with third-party calls disabled/mocked
- Compare response times
If the endpoint becomes fast when one dependency is stubbed, that dependency is likely the cause.
8) Look for thread/connection pool exhaustion
Sometimes the root cause isn’t “slow DB” or “slow vendor,” but resource starvation:
- DB connection pool empty
- web server worker threads exhausted
- async job queue backed up
- rate limiting upstream
- too few HTTP client connections
Symptoms:
- requests wait before even reaching the DB/vendor
- latency rises sharply under load
- CPU may be low while latency is high
9) Simple decision tree
If traces show:
- App code is slow → profile the hot functions, look for CPU, locks, serialization, GC
- DB spans are slow → inspect queries, indexes, locks, pool saturation
- External spans are slow → vendor/network/retry issues
- Everything is waiting, but nothing is “slow” individually → queueing, pool exhaustion, or saturation
10) What I can help you do next
If you want, send me any of the following and I can help you pinpoint the issue:
- one slow request trace
- application logs with timings
- database query timings
- a list of external calls made during a request
- stack/tech details:
- language/framework
- database
- APM/tracing tools
- whether it’s monolith or microservices
If you want, I can also give you a step-by-step debugging checklist or a logging/tracing template you can add to your app right away.