teluzia.Cloud Engineer · Day 149
CHAPTER 22 · TROUBLESHOOTING AND BEHAVIOURAL INTERVIEWS

HTTP 5xx and slow applications

4–5 hours including independent practice3 topics
LET’S MAKE THIS SIMPLE

What you’re learning today

HTTP 5xx attribution is today's starting point. A proxy records 504 after its upstream timeout while the app records a database call still running. Match request IDs to locate the delay; the proxy's response code identifies where timeout was enforced. You will connect this with latency decomposition and safe mitigation. The lesson's artifact brings these decisions together: Build a latency breakdown for five requests and a proxy/application error matrix; choose mitigation and a measurable recovery test.

Think of it this way

Latency is a trip broken into legs; improving a short walk cannot fix a long delay at the final connection.

TOPIC 01 / 03Step by step

HTTP 5xx attribution

A 502, 503 or 504 can originate at a proxy or application. Correlate request IDs and upstream timings; identify which component produced the response before restarting services. A proxy records 504 after its upstream timeout while the app records a database call still running. Match request IDs to locate the delay; the proxy's response code identifies where timeout was enforced.

WORKED EXAMPLE
A proxy records 504 after its upstream timeout while the app records a database call still running. Match request IDs to locate the delay; the proxy's response code identifies where timeout was enforced.

An upstream is the service a proxy calls; a gateway error reports failure at that intermediary; a correlation ID connects records across components. Imagine a load balancer returns 502 while the application has no matching request. Check target health, connection behavior and the intended port/protocol before blaming business logic. If the application does have the request, compare its response and duration with the proxy's recorded outcome. Different 5xx codes suggest different paths but are not complete diagnoses; proxies and applications can map errors differently. Preserve headers and timestamps where safe. Detailed tracing improves attribution, while logging every payload introduces privacy and cost concerns. Gather enough metadata to identify the response-producing component and failed dependency without collecting sensitive content unrelated to the investigation.

Why this matters

Match request IDs to locate the delay; the proxy's response code identifies where timeout was enforced.

A common trap

A 504 must always have been generated by application code.

MAKE IT VISIBLE

Follow a request through the system

FOLLOW THE SIGNAL

What happens after you press Enter?

Explore a common HTTPS request path. Select a stage, then inject a simulated failure to see what you would investigate.

STAGE 1

Find the destination

The browser resolves a hostname to an address using DNS. A cached answer may avoid a new lookup. If resolution fails, the request never reaches the server.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

HTTP 5xx attribution

A 502, 503 or 504 can originate at a proxy or application. Correlate request IDs and upstream timings; identify which component produced the response before restarting services. A proxy records 504 after its upstream timeout while the app records a database call still running. Match request IDs to locate the delay; the proxy's response code identifies where timeout was enforced.

WORKED EXAMPLE
A proxy records 504 after its upstream timeout while the app records a database call still running. Match request IDs to locate the delay; the proxy's response code identifies where timeout was enforced.

An upstream is the service a proxy calls; a gateway error reports failure at that intermediary; a correlation ID connects records across components. Imagine a load balancer returns 502 while the application has no matching request. Check target health, connection behavior and the intended port/protocol before blaming business logic. If the application does have the request, compare its response and duration with the proxy's recorded outcome. Different 5xx codes suggest different paths but are not complete diagnoses; proxies and applications can map errors differently. Preserve headers and timestamps where safe. Detailed tracing improves attribution, while logging every payload introduces privacy and cost concerns. Gather enough metadata to identify the response-producing component and failed dependency without collecting sensitive content unrelated to the investigation.

Why this matters

Match request IDs to locate the delay; the proxy's response code identifies where timeout was enforced.

A common trap

A 504 must always have been generated by application code.

Latency decomposition

Split DNS, connection, TLS, application and dependency time. Tail latency and saturation show problems hidden by averages; compare affected and unaffected requests with the same conditions. A request spends 20 ms DNS, 40 ms connection/TLS, 30 ms application and 900 ms database time. Optimizing DNS cannot meaningfully repair the dominant database delay.

WORKED EXAMPLE
A request spends 20 ms DNS, 40 ms connection/TLS, 30 ms application and 900 ms database time. Optimizing DNS cannot meaningfully repair the dominant database delay.

A latency budget allocates allowed time across stages; tail latency describes the slow end of a distribution; saturation limits service rate. Imagine median latency stays low while p99 grows during a worker pool limit. Average timing can hide a minority of queued requests. Compare connection establishment, queue waiting, application execution and dependency time for the same request class. Use matched traffic conditions before attributing a change to a release. A timeout is an enforced upper bound, not the actual required processing time; increasing it can hide accumulating work. Optimizing the dominant stage has more effect than tuning a small one. Choose a change with a predicted timing benefit, then confirm both the distribution and errors so faster failures are not mistaken for improved service latency.

Why this matters

Optimizing DNS cannot meaningfully repair the dominant database delay.

A common trap

Average request time proves the slowest requests are acceptable.

Safe mitigation

Reduce load, roll back a relevant change or isolate a failing dependency when evidence supports it. Preserve logs and verify user requests; repeated restarts can erase diagnostic evidence. A recent release doubles database calls per request. Rolling it back is a supported mitigation if the comparison confirms the change; verify real checkout requests and database load afterward.

WORKED EXAMPLE
A recent release doubles database calls per request. Rolling it back is a supported mitigation if the comparison confirms the change; verify real checkout requests and database load afterward.

A mitigation reduces current impact; a durable fix removes or controls the contributing condition; a rollback restores a known earlier version. Imagine a dependency is slow and callers hold connections until the pool exhausts. Reduce concurrency or apply the established fallback if evidence supports it, rather than merely increasing every timeout. Preserve the current error context and identify any requests that need safe retry. A rollback is useful when a relevant change explains the failure, but it can be unsafe if schema changes are incompatible. Speed matters during impact, yet uncontrolled changes make diagnosis and recovery harder. Define success using representative business requests and stable signals, record residual risk and create a separate prevention task instead of treating restored health as proof the underlying issue cannot recur.

Why this matters

Rolling it back is a supported mitigation if the comparison confirms the change; verify real checkout requests and database load afterward.

A common trap

Restarting repeatedly always preserves the strongest diagnostic evidence.

KEEP THESE WITH YOU

Today’s takeaways

HTTP 5xx attribution: A 502, 503 or 504 can originate at a proxy or application.

Latency decomposition: Split DNS, connection, TLS, application and dependency time.

Safe mitigation: Reduce load, roll back a relevant change or isolate a failing dependency when evidence supports it.

CLOSE THE LOOP

Ready to complete this day?

Verify the practical steps and pass the knowledge check (at least two thirds correct).

Lab steps verifiedKnowledge check passed