Grokking DevOps and SRE Interviews
Vote

0% completed

​

What Happens When You Type a URL

Before the First Packet

Name, Connection, and Encryption

Load Balancer and Reverse Proxy

Application and Database

The Response and Status Codes

Where Each Failure Appears

Measuring Each Step

Using This in an Interview

Key Takeaways

Practice Questions

Title image: a browser request passes through DNS, TCP, TLS, a load balancer, a proxy, an application, and a database in 155 ms.
Title image: a browser request passes through DNS, TCP, TLS, a load balancer, a proxy, an application, and a database in 155 ms.

A customer types https://shop.example.com/cart and presses Enter. The first byte of the page arrives 155 milliseconds later, and the time divides as follows:

  • 0 to 20 ms: DNS returns the address.
  • 20 to 50 ms: the TCP handshake completes.
  • 50 to 80 ms: the TLS handshake completes.
  • 80 to 95 ms: the request travels to the load balancer.
  • 95 to 100 ms: the load balancer and the reverse proxy pass it on.
  • 100 to 140 ms: the application runs, including a 25 ms database query.
  • 140 to 155 ms: the response travels back to the browser.

Each line is a separate system, and each one fails in its own way. This lesson follows the request through those systems and shows which tool reveals a failure at each point.

Before the First Packet

The browser first decides whether it needs the network at all. It splits the URL into a scheme (https), a host, and a path (/cart). If the customer typed only shop.example.com, the browser may first try plain HTTP and receive a redirect to HTTPS, which costs another round trip. A site can prevent this with HSTS (HTTP Strict Transport Security), a response header that tells the browser to use HTTPS for that host in the future.

If the browser already holds an open connection to the host, it reuses it. It then skips DNS, TCP, and TLS, and the first byte arrives after 155 minus 80, or 75 ms.

Name, Connection, and Encryption

The first 80 ms only prepare a secure connection. The browser asks a resolver for the address, as How DNS Resolves a Name describes, and here the answer takes 20 ms. It then opens a TCP connection, which costs one 30 ms round trip, as TCP Connections and Ports explains. Finally, a TLS 1.3 handshake adds a second 30 ms round trip, as TLS and Certificates explains.

The address belongs to the load balancer, not to an application server. The TCP and TLS handshakes therefore end at the load balancer.

The full request path with the time of each step: DNS 20, TCP 30, TLS 30, request 15, load balancer and proxy 5, application 15, database 25, and response 15, for 155 ms in total.
The full request path with the time of each step: DNS 20, TCP 30, TLS 30, request 15, load balancer and proxy 5, application 15, database 25, and response 15, for 155 ms in total.

Load Balancer and Reverse Proxy

A load balancer spreads requests across several servers and sends them only to servers that pass its health checks. A health check is a request that the load balancer sends to each server every few seconds to confirm that it can serve traffic. This load balancer also performs TLS termination: it decrypts the request and forwards it inside the private network.

A reverse proxy, such as nginx, receives requests for one or more applications and forwards each one to the right upstream, the server behind the proxy. It chooses an upstream by host and path, applies timeouts, and adds headers. Inside one data center, these two hops take about 5 ms together.

Application and Database

The application spends 40 ms, and 25 ms of that is one database query. It reads the session, asks the database for the cart contents, and builds the response. It takes a connection from its pool, so no new TCP handshake to the database is needed. A slow query adds its time directly to every page that runs it.

The Response and Status Codes

Every HTTP response carries a three-digit status code, and its first digit gives the class.

ClassMeaningExamples
1xxInformational101 Switching Protocols
2xxSuccess200 OK
3xxRedirect301 Moved Permanently, 304 Not Modified
4xxThe client's request is wrong or not allowed400, 401, 403, 404, 429 Too Many Requests
5xxThe server failed500, 502, 503, 504

Three 5xx codes usually come from the proxy or the load balancer, not from the application. A 502 Bad Gateway means that the proxy could not get a valid response, often because the upstream refused the connection or closed it. A 503 Service Unavailable often means that no healthy upstream exists. A 504 Gateway Timeout means that the upstream did not answer within the proxy's timeout. The application log may therefore show nothing at all during a burst of 502 or 504 errors.

Where Each Failure Appears

Each step produces a different symptom, so the symptom tells you where to start.

StepWhat the user or client seesTool that shows it
DNSCould not resolve host, or a "site not found" pagedig
TCPConnection refused or timed outnc -vz, ss -tlnp on the target
TLSA certificate warning or handshake erroropenssl s_client
Load balancer503Target health status and load balancer metrics
Reverse proxy502 or 504The proxy's error log
Application500Application logs and traces (records of the time each part of a request took)
DatabaseA slow page, then 504 or 500Slow query log and database metrics

Measuring Each Step

curl can report the time at which each step finished. The values are cumulative seconds from the start of the request.

curl -s -o /dev/null -w 'dns %{time_namelookup}\ntcp %{time_connect}\ntls %{time_appconnect}\nfirst byte %{time_starttransfer}\ntotal %{time_total}\n' https://shop.example.com/cart
dns 0.020000 tcp 0.050000 tls 0.080000 first byte 0.155000 total 0.170000

Subtract each value from the next to get the time of a step. TCP took 50 minus 20, or 30 ms, and TLS took 80 minus 50, or 30 ms. The wait for the first byte took 155 minus 80, or 75 ms. One round trip of 30 ms was network travel, so the servers spent 45 ms: 5 in the load balancer and proxy, 15 in the application, and 25 in the database. The last 15 ms delivered the rest of the page.

If a slow page shows a large gap between tls and first byte, the time is in the servers. If dns itself is large, the time is in name resolution.

Using This in an Interview

"What happens when you type a URL?" tests breadth, so cover every step briefly and then add detail wherever the interviewer asks.

"The browser resolves the name through DNS, opens a TCP connection, and completes a TLS handshake with the load balancer. The load balancer sends the request to a healthy server, a reverse proxy forwards it to the application, and the application queries the database. On a new connection, about half of a 155 ms response can be connection setup. When it fails, the symptom shows the step: a DNS error, a refused connection, a certificate warning, or a 5xx code from the proxy or the application."

Expect two follow-up questions:

  • "Users see 504 errors, but the application logs show no errors. Where do you look?" At the proxy's error log and the application's latency, because the proxy stopped waiting when its timeout ended. A slow database query is a common cause.
  • "Why is the first page load slower than later ones?" The first load waits for DNS, TCP, and TLS, here 80 ms, and later requests reuse the connection.

Key Takeaways

  • A web request passes through DNS, TCP, TLS, a load balancer, a proxy, the application, and often a database.
  • Connection setup can take more than half of a fast response, so connection reuse matters.
  • 502, 503, and 504 usually come from the proxy or the load balancer.
  • The symptom points to the step, and each step has its own tool.
  • curl -w timings show which step took the time.

This lesson ends the systems knowledge that troubleshooting depends on. The next lesson, A Method for Troubleshooting, turns that knowledge into a repeatable way to investigate an unknown failure.

Practice Questions

1. A curl -w result shows tls 0.090 and first byte 1.390, and the round trip is 30 ms. Where did most of the time go?

<details><summary>Show answer</summary>

The servers spent about 1,270 ms. The wait for the first byte was 1,390 minus 90, or 1,300 ms. Subtracting one 30 ms round trip leaves 1,270 ms inside the load balancer, the proxy, the application, or the database. Check the application's traces and the slow query log next.

</details>

2. During a deployment, the proxy returns 502 errors for a few seconds while each application server restarts. Why?

<details><summary>Show answer</summary>

The proxy tried to connect while nothing listened on the application port. The restarting server refused the connection, so the proxy could not get a valid response and returned 502. Remove each server from the proxy or load balancer before it stops, and add it back after its health check passes.

</details>

3. Clients see Could not resolve host. Should you check the reverse proxy's error log?

<details><summary>Show answer</summary>

No, because the HTTP request never left the client. The failure is in name resolution, before any connection opens. Check the record with dig, then check the client's resolver.

</details>

Reading Progress

0%


Vote for new content

On This Page

Before the First Packet

Name, Connection, and Encryption

Load Balancer and Reverse Proxy

Application and Database

The Response and Status Codes

Where Each Failure Appears

Measuring Each Step

Using This in an Interview

Key Takeaways

Practice Questions