Client Server and the HTTP Request Journey

Client Server and API Design · 35 min

System Design · Module 2 · Lesson 1 of 4 · 35 min

Client Server and the HTTP Request Journey

Follow one browser request through name resolution, connection setup, TLS and HTTP, and identify which stages can be reused.

Measure the request as a sequence of stages; a slow page does not by itself identify a slow application server.

01 The idea

The problem this lesson solves

The browser obtains an address, possibly from a local or recursive DNS cache.

Prerequisite: earlier lessons introduce the vocabulary and shared examples used here. Follow the module order.

DNSThe naming system used to obtain records such as an address for a hostname.
TLSA protocol that authenticates peers according to its configuration and protects data in transit.
Connection reuseSending another request over an already established transport and security session.

02 Worked example

Follow one worked example

Client Server and the HTTP Request Journey worked diagram01BrowserURL + request02DNS / TLSLocate + protect03HTTP serverHandle operation04BrowserRead responseClient Server and the HTTP Request Journey compact diagram01BrowserURL + request02DNS / TLSLocate + protect03HTTP serverHandle operation04BrowserRead response
Browser: URL + request • DNS / TLS: Locate + protect • HTTP server: Handle operation • Browser: Read response.

Trace the example in order. Follow the same identities, units and state transitions through the diagram and the events below.

1
Resolve the hostThe browser obtains an address, possibly from a local or recursive DNS cache.
2
Establish protectionFor this TCP-based teaching path, connect and establish TLS for the hostname.
3
Send the operationSend GET /guide with the relevant HTTP headers over the established connection.
4
Read the responseObserve the status and content, then reuse the connection if allowed and useful.

Measure the request as a sequence of stages; a slow page does not by itself identify a slow application server.

03 The method

Mechanisms decisions and a guided tutorial

Work through the explanation in order, then apply it in the tutorial. Each comparison names a cost as well as a benefit.

Choice or conceptPurposeBoundary or cost
DNSFind a record for the hostCaching and resolver path
TCP / QUICTransport connectionLoss and connection reuse
TLSProtected authenticated channelCertificate and handshake behavior
HTTPRequest and response semanticsApplication and dependency work

The journey before the application sees a request

DNS resolves a hostname to an address, usually through caches and a recursive resolver. A typical HTTPS connection over TCP then establishes TCP and TLS before sending HTTP data. Existing connections can be reused, and HTTP/3 uses QUIC over UDP instead, so do not claim every request always performs all these steps. DNS locates the service; TLS authenticates the server and encrypts transport; HTTP describes the operation. A slow page can be slow at any of these stages.

One address, several boundaries

A URL contains a scheme, host and path. For https://example.com/guide, the browser needs an address for example.com, a secure connection to the intended server, and an HTTP request for /guide. DNS answers the naming question; it does not send the HTTP page. TLS protects the connection; it does not decide which user may edit a document.

A proxy or CDN may terminate the browser connection and start another upstream connection. Record which machine each timing belongs to. An idle origin can coexist with a slow client path, and a fast connection setup can coexist with a slow database query after the request arrives.

Read a timing waterfall

Assume a cold teaching request needs 20 ms for DNS, 40 ms for TCP, 40 ms for TLS and 60 ms for application processing plus the modeled response wait. The serialized total is 160 ms. A later request on the same connection may avoid the first three stages and pay roughly the modeled 60 ms. These are assumptions, not universal timing numbers.

Real browsers overlap some work, reuse connections, resume TLS sessions and may use HTTP/3 over QUIC. Use developer tools to see what actually happened. Compare cold and warm requests without claiming that every page load always repeats DNS, TCP and a complete TLS handshake.

Debug from observations

Start with the observed symptom and separate name-resolution delay, connection failure, certificate failure, time waiting for the response and body transfer. A large response can download slowly after the server has already produced it. A response can also be small but wait behind a slow dependency.

Keep the HTTP contract independent of the transport lifecycle. An established TCP connection does not mean the next HTTP operation will succeed. The server can receive and commit a write while the connection later breaks, which is the retry ambiguity studied in a later lesson.

Guided tutorial

1. Inspect a URL

Separate scheme, hostname, port and path for two example URLs.

2. Record a cold request

Use browser Network tools with a new connection and identify timing stages.

3. Compare a repeat

Reload or issue a second request and note which stages disappear or shrink.

4. Write a diagnosis

Explain one case where the browser is slow while origin CPU remains low.

curl -I https://example.com
# Optional timing observation; values vary with your network:
curl -o /dev/null -s -w "dns=%{time_namelookup} connect=%{time_connect} start=%{time_starttransfer} total=%{time_total}\n" https://example.com
# curl time_* values are cumulative from request start; do not sum them.
# For example, time_connect - time_namelookup approximates the
# post-DNS connection interval for the observed path.

04 Cheat sheet

Review the decisions

Use this table to explain the mechanism and its limit without memorizing a product name.

Choice or conceptRememberCheck
DNSFind a record for the hostCaching and resolver path
TCP / QUICTransport connectionLoss and connection reuse
TLSProtected authenticated channelCertificate and handshake behavior
HTTPRequest and response semanticsApplication and dependency work
DNSThe naming system used to obtain records such as an address for a hostname.
TLSA protocol that authenticates peers according to its configuration and protects data in transit.
Connection reuseSending another request over an already established transport and security session.

05 Where & why

Check the primary references

Use official references for protocol and implementation details. The questions here are teaching prompts.

Primary reference
HTTP method semantics

Read HTTP method semantics

Primary reference
HTTP status codes

Read HTTP status codes

State the implementation version and the workload assumptions when defending your own design.

06 Interview questions

Explain the reasoning out loud

Answer before opening the explanation. The questions progress from vocabulary to decisions and failure behavior.

What does DNS mean?
The naming system used to obtain records such as an address for a hostname.
What does TLS mean?
A protocol that authenticates peers according to its configuration and protects data in transit.
What does Connection reuse mean?
Sending another request over an already established transport and security session.
Does DNS return the web page?
No. It supplies naming records that help locate a service. HTTP retrieves the representation or performs the requested operation.
Does every HTTPS request create a new TCP connection?
No. Connections can be reused, and HTTP/3 uses QUIC instead of TCP. Inspect the actual path rather than assuming one handshake per request.
What does TLS fail to solve?
It does not decide application permissions or make business operations atomic. Authentication and authorization still need an application contract.
Why can origin CPU be low while a page is slow?
The delay may be in DNS, the network, a proxy, response transfer or a blocked downstream dependency. Measure stages before scaling CPU.
Is time to first byte the same as total load time?
No. It ends when the response begins arriving. Transferring and processing the remaining content takes additional time.

07 Practice problems

Practice a new case

Solve the new cases before revealing hints. Complete worked solutions follow the set.

Parse a URL

Easy
Identify the host and path in https://example.com:8443/api/notes.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
The colon separates an explicit port.

Assign a protocol

Easy
Assign name lookup, encrypted transport and a GET operation to their main mechanisms.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Separate location, protection and semantics.

Cold timing

Medium
Sum assumed DNS=15 ms, TCP=30 ms, TLS=30 ms and response wait=75 ms for a serialized model.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Keep the stage boundaries consistent.

Warm timing

Medium
For the previous model, estimate the remaining cost when DNS and the established connection are reused.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Remove only stages actually reused.

Find the bottleneck

Medium
A 1 KB response has 2 seconds to first byte and 5 ms transfer time; suggest the first investigation.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Compare wait time with payload transfer.

Draw both legs

Hard
Describe a browser → CDN → origin request when the CDN must contact the origin.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
There are two connection paths.

Worked solutions

1. Parse a URL

Host is example.com, port is 8443 and path is /api/notes. The scheme is HTTPS.

2. Assign a protocol

DNS performs name lookup; TLS protects the connection; HTTP describes the GET and its response.

3. Cold timing

The modeled total is 150 ms. It does not include unmodeled response-body transfer or browser processing.

4. Warm timing

The modeled response wait remains 75 ms. Actual network and application costs still need measurement.

5. Find the bottleneck

Investigate server/proxy/dependency waiting and request queues. Increasing bandwidth is unlikely to remove a delay dominated by the response wait.

6. Draw both legs

The browser resolves and connects to the CDN; the CDN forwards over its own upstream connection. Distinguish client-to-edge timing, edge cache lookup, upstream connection behavior and origin processing.