Prompt
How do I find out where a request is breaking in production?
Latest observation
To find where a request is breaking in production, use a combination of request tracing, structured logs, and correlation IDs. The goal is to follow one request end-to-end and pinpoint the exact hop where it fails.
Practical approach
1) Give every request a unique ID
Assign a request ID / correlation ID at the edge of your system and pass it through:
- load balancer / gateway
- backend services
- queues/jobs
- database or external API calls if possible
Then log that ID everywhere.
Example:
- incoming request:
req_id=abc123 - service A logs:
req_id=abc123 step=auth - service B logs:
req_id=abc123 step=payment - service C logs:
req_id=abc123 error=timeout
This lets you search logs for a single request and see where it stops.
2) Use distributed tracing
If your app is microservices-based, implement tracing with tools like:
- OpenTelemetry
- Jaeger
- Zipkin
- Datadog APM
- New Relic
- Honeycomb
A trace shows:
- which services were called
- how long each call took
- where an error or timeout happened
This is often the fastest way to identify the breaking point.
3) Add structured logs at each boundary
Log key transitions, not just errors:
- request received
- auth completed
- validation passed
- outbound API call started/finished
- DB query started/finished
- response sent
Include fields like:
- request ID
- user/account ID
- endpoint
- downstream service name
- status code
- latency
- error type
Avoid plain text-only logs if possible; JSON logs are much easier to query.
4) Check the failure mode
Look at what kind of breakage it is:
- 4xx: validation/auth/routing issue
- 5xx: app/server failure
- timeout: dependency too slow, deadlock, network issue
- partial/incorrect response: bug in business logic, stale cache, bad data
- retry storms: downstream failure causing cascading issues
The status and timing help narrow down the layer.
5) Compare “working” vs “broken” requests
Take a known good request and a broken one:
- same endpoint
- same region/environment
- similar input
Compare:
- request headers
- payload size/content
- downstream calls
- response times
- error logs
- feature flags / config
Often the difference reveals the issue quickly.
6) Inspect infrastructure and dependency metrics
If the app looks fine, check:
- CPU/memory saturation
- pod restarts / OOM kills
- DB connection pool exhaustion
- queue lag
- external API latency/error rate
- load balancer 5xx metrics
- network errors
Sometimes the request breaks because the service is healthy but a dependency is not.
7) Reproduce with a single request if possible
Use:
- exact payload from logs
curlor Postman- same auth token or a test equivalent
- same headers
If it’s production-only:
- run against a staging environment with production-like data/config
- use feature flags to isolate behavior
- replay captured traffic if your tooling supports it
8) Add temporary “breadcrumb” logging if needed
If tracing/logs aren’t enough, temporarily add logs around suspected code paths:
- before and after each major step
- include timing
- include dependency results
Example:
step=fetch_user startstep=fetch_user done duration_ms=42step=charge_card failed err=timeout
Be careful to remove or reduce these after diagnosis.
A simple debugging workflow
- Start with the request ID
- Find the first service that received it
- Follow logs/traces through each hop
- Identify the last successful step
- Check the next dependency or code path
- Verify with metrics and a reproduction attempt
If you don’t have tracing yet
The fastest immediate improvement is:
- generate a request ID at ingress
- log it in every service
- use JSON structured logs
- add timestamps and latency per major step
That alone usually makes production failures much easier to locate.
If you want, I can also give you:
- a step-by-step production debugging checklist
- a sample logging format
- or examples for Node.js / Python / Java / Go.