HTTP Request Lifecycle
A practical explanation of the HTTP request lifecycle, including DNS, TCP, TLS, HTTP requests and responses, server processing, caching, and browser rendering.
Every time you open a website, load an image, submit a form, call an API, or download a file, your application participates in an HTTP request lifecycle. What looks like a simple request in the browser can involve several networking steps before the server even receives the HTTP message.
A typical HTTPS request can involve URL parsing, DNS resolution, establishing a network connection, TLS negotiation, sending an HTTP request, server-side processing, receiving an HTTP response, and finally processing that response in the browser or application.
Understanding this lifecycle helps explain common web-development concepts such as DNS failures, connection errors, TLS certificates, HTTP status codes, headers, cookies, caching, redirects, API latency, and browser rendering.
HTTP Request Lifecycle at a Glance
- The client determines the URL and HTTP request it needs to make.
- The hostname is resolved to an IP address through DNS when necessary.
- The client establishes a network connection to the server.
- For HTTPS, the client and server perform a TLS handshake.
- The client sends the HTTP request containing the method, target, headers, and optionally a body.
- The server receives and processes the request.
- The server sends an HTTP response containing a status code, headers, and optionally a body.
- The client processes the response and may follow redirects, use a cache, parse data, or render content.
These stages are conceptually useful, but modern protocols can combine or optimize some of them. HTTP/2 and HTTP/3, connection reuse, DNS caching, TLS session resumption, CDNs, and browser caches can significantly change what happens on an individual request.
1. The Client Starts With a URL
The lifecycle begins when a browser, mobile application, frontend application, command-line client, or another program needs to access a resource.
https://api.example.com/users/42?include=ordersThe URL contains several pieces of information that influence how the request is made.
| Part | Example | Purpose |
|---|---|---|
| Scheme | https | Determines the protocol and security requirements |
| Hostname | api.example.com | Identifies the destination host |
| Port | 443 | Identifies the network service port |
| Path | /users/42 | Identifies the requested resource or endpoint |
| Query | include=orders | Provides additional request parameters |
For standard HTTP and HTTPS URLs, the default ports are typically 80 and 443 respectively. An explicit port can also be specified in the URL.
2. The Client Checks Local Caches and Existing Connections
Before performing every networking step from scratch, a browser or HTTP client can reuse information and resources it already has. DNS results may be cached, a response may already exist in the HTTP cache, and an existing connection to the destination may be reusable.
This means the simplified lifecycle is not always executed in exactly the same way. A cached response can sometimes be returned without contacting the server at all. An existing HTTP/2 or HTTP/3 connection can also eliminate the need to establish a new connection for another request.
3. DNS Resolution
If the client needs an IP address for the hostname, it performs DNS resolution. DNS translates a domain name such as api.example.com into an IP address that can be used for network communication.
api.example.com
β
DNS lookup
β
203.0.113.25The lookup can involve several layers of caching. A browser, operating system, local network, resolver, or DNS provider may already have a cached answer.
DNS Records Used by Web Applications
| Record | Typical purpose |
|---|---|
| A | Maps a hostname to an IPv4 address |
| AAAA | Maps a hostname to an IPv6 address |
| CNAME | Provides an alias to another hostname |
| NS | Identifies authoritative name servers for a domain |
| TXT | Stores text data used by various services |
The exact DNS resolution process can be more complex than a single lookup. Recursive resolvers may contact authoritative DNS servers and other infrastructure before returning an answer to the client.
What Happens if DNS Fails?
If the hostname cannot be resolved, the client cannot normally establish a connection using that hostname. The HTTP request therefore never reaches the HTTP server.
This distinction is useful when debugging. A DNS failure is different from an HTTP 404 or 500 response because the server may never receive the request in the first place.
4. Establishing the Network Connection
Once the client knows the destination IP address, it needs a transport connection appropriate for the protocol being used.
Traditional HTTP/1.1 and HTTP/2 commonly run over TCP. HTTPS over those versions therefore involves establishing a TCP connection before the TLS handshake.
TCP Connection Establishment
TCP establishes a reliable connection using a handshake between the client and server. The process allows both sides to establish the connection and synchronize their communication state.
Client β SYN
Server β SYN-ACK
Client β ACKThis is commonly known as the TCP three-way handshake. It happens before application data is exchanged over a new TCP connection.
The exact networking path can involve routers, firewalls, load balancers, proxies, CDNs, and other infrastructure. The client is not necessarily connecting directly to the machine that ultimately executes the application code.
HTTP/3 and QUIC
HTTP/3 uses QUIC rather than TCP. QUIC runs over UDP and incorporates connection establishment and cryptographic negotiation into its own protocol design.
Because of this, the lifecycle of an HTTP/3 request is not identical to the traditional TCP-plus-TLS sequence. The important point is that the application still needs an appropriate secure transport connection before exchanging HTTP messages.
5. TLS Handshake for HTTPS
When the URL uses HTTPS, the connection is protected with TLS. Before normal encrypted HTTP data can be exchanged, the client and server negotiate cryptographic parameters and establish shared session keys.
The TLS handshake also allows the client to authenticate the server using its certificate chain. The browser or client checks whether the certificate is valid for the requested hostname and whether it chains to a trusted certificate authority.
Client
β
TLS negotiation
β
Certificate validation
β
Key establishment
β
Encrypted communicationTLS Versions
Modern HTTPS connections commonly use TLS 1.2 or TLS 1.3. TLS 1.3 reduces the number of round trips required for a new connection compared with older versions and removes several older cryptographic mechanisms.
The exact TLS version and cipher suite depend on what the client and server support and what their configuration permits.
What Happens if TLS Fails?
If certificate validation or TLS negotiation fails, the client normally stops before sending the application HTTP request. Problems can include expired certificates, hostname mismatches, unsupported protocol versions, certificate-chain problems, or incompatible cryptographic settings.
6. The Client Builds the HTTP Request
Once the necessary connection is available, the client constructs the HTTP request. A request contains a method, target, headers, and optionally a body.
GET /api/users/42 HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer <token>
User-Agent: ExampleClient/1.0The request method communicates the intended operation. Common methods include GET, POST, PUT, PATCH, and DELETE.
HTTP Request Components
| Component | Example | Purpose |
|---|---|---|
| Method | GET | Describes the intended operation |
| Target | /api/users/42 | Identifies the requested resource |
| Header | Accept: application/json | Provides metadata or preferences |
| Body | JSON document | Carries request data when needed |
7. Query Parameters
Query parameters are part of the request target and are commonly used for filtering, searching, sorting, pagination, and other request options.
GET /api/products?category=keyboard&page=2&limit=20 HTTP/1.1
Host: api.example.comThe server can parse these parameters and use them while processing the request. Query parameters are not inherently private, so sensitive information such as passwords or authentication secrets should not normally be placed in URLs.
8. HTTP Request Headers
Headers provide metadata about the request and tell the server additional information about the client's capabilities, preferences, authentication, caching state, and the request body.
Accept: application/json
Content-Type: application/json
Authorization: Bearer <token>
User-Agent: ExampleClient/1.0Common headers include Accept, Content-Type, Authorization, Cookie, User-Agent, Host, Cache-Control, If-None-Match, and many others.
9. The Request Body
Methods such as POST, PUT, and PATCH commonly include a request body. The body contains the data submitted to the server.
POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 42
{
"name": "Alex",
"role": "developer"
}Content-Type tells the server how to interpret the body. JSON is common for APIs, but HTTP can carry many other representations.
10. The Request Travels Through the Network
After the client sends the request, the network infrastructure carries it toward the destination. The request may pass through multiple systems before reaching the application that processes it.
- Local network equipment
- Internet service provider infrastructure
- Routers
- Firewalls
- Reverse proxies
- CDNs
- Load balancers
- Web servers
- Application servers
A CDN or reverse proxy may terminate TLS, serve a cached response, route the request to a backend, or perform security checks before the request reaches the application.
11. The Server Receives the Request
Eventually, an HTTP-capable server or intermediary receives the request. The server parses the method, target, headers, and body before deciding how to handle it.
The first server receiving the request is not necessarily the application itself. A reverse proxy such as a load balancer or web server can receive the request first and then forward it to another service.
12. Authentication and Authorization
The server may need to determine who is making the request and whether that identity has permission to perform the requested operation.
Authorization: Bearer eyJ...Authentication answers the question of who the client is. Authorization determines whether that identity is allowed to perform the requested operation.
Depending on the application, authentication can also involve cookies, sessions, API keys, OAuth access tokens, or other mechanisms.
13. Server-Side Processing
After parsing and validating the request, the application executes the logic associated with the endpoint. This can be very simple or involve many internal operations.
Request
β
Routing
β
Validation
β
Authentication
β
Authorization
β
Business logic
β
Database or external services
β
ResponseFor example, a GET request for a user profile might cause the application to validate the user ID, query a database, transform the returned record, and serialize the result as JSON.
Database Queries During a Request
Many API requests involve a database. The application might execute one or several queries before it can construct a response.
SELECT id, name, email
FROM users
WHERE id = 42;Database latency can therefore become part of the total request duration. Slow queries, missing indexes, connection-pool contention, and excessive database round trips can all affect API performance.
External API Calls
A server may also call another service before returning a response. For example, an order API might contact a payment service, inventory service, or shipping provider.
This means a single browser request can indirectly depend on several network requests inside the backend. Failures in those dependencies can affect the final HTTP response.
14. Server Validation
The server should validate incoming data before using it. Validation can include checking required fields, data types, formats, ranges, permissions, and business rules.
{
"email": "invalid-value",
"age": -10
}If the request does not satisfy the API's validation rules, the server can return an appropriate client-error response rather than processing invalid data.
15. The Server Creates an HTTP Response
After processing the request, the server creates an HTTP response. Like a request, a response contains metadata and can contain a body.
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=60
{
"id": 42,
"name": "Alex",
"role": "developer"
}HTTP Response Components
| Component | Example | Purpose |
|---|---|---|
| Status code | 200 | Describes the result of the request |
| Status text | OK | Human-readable reason phrase in HTTP/1.1 representations |
| Headers | Content-Type: application/json | Provides response metadata |
| Body | JSON document | Contains the response representation when applicable |
16. HTTP Status Codes
The status code is one of the most important parts of the response because it tells the client the general outcome of the request.
| Class | Meaning |
|---|---|
| 1xx | Informational |
| 2xx | Successful |
| 3xx | Redirection |
| 4xx | Client error |
| 5xx | Server error |
Common examples include 200 OK, 201 Created, 204 No Content, 301/308 redirects, 304 Not Modified, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests, and 500 Internal Server Error.
17. Response Headers
Response headers provide information about the response and tell the client how to handle it.
Content-Type: application/json
Content-Length: 87
Cache-Control: max-age=60
ETag: "abc123"
Set-Cookie: session=exampleHeaders can control caching, identify the response format, set cookies, describe content encoding, communicate security policies, and provide other metadata.
18. The Response Travels Back to the Client
The server's response travels through the network back toward the client. Intermediaries can participate in this process just as they did with the request.
A reverse proxy or CDN can potentially modify, cache, compress, or otherwise process the response before it reaches the browser.
19. Response Decompression and Processing
HTTP responses can be compressed to reduce the amount of data transferred over the network. The client can decompress the response before processing the actual content.
Content-Encoding: gzip
Content-Type: application/jsonOther content encodings can be used depending on the client and server configuration. Compression can reduce transfer size, although compression itself also requires processing time.
20. Redirects
If the server returns a redirect response such as 301, 302, 303, 307, or 308, the client may make another request to the location provided by the server.
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/new-pathA redirect therefore adds another step to the overall request process. Multiple redirects can increase latency and make debugging more difficult.
301 vs 302 vs 307 vs 308
| Status | Typical meaning |
|---|---|
| 301 | Permanent redirect |
| 302 | Temporary redirect |
| 307 | Temporary redirect while preserving the request method |
| 308 | Permanent redirect while preserving the request method |
The distinction between redirect codes can matter for methods such as POST because some redirect statuses have historically allowed clients to change the method when following a redirect, while 307 and 308 explicitly preserve it.
21. Browser Caching
After receiving a response, the browser can store it according to HTTP caching rules. A later request may be satisfied directly from the cache or may use conditional validation to determine whether the cached representation is still current.
Cache-Control: max-age=3600
ETag: "resource-version-42"Caching can significantly reduce network traffic and improve perceived performance. However, incorrect cache-control settings can cause clients to use stale data longer than intended.
22. Conditional Requests
A client can use validators such as ETag to ask whether its cached representation is still current.
GET /api/users/42
If-None-Match: "user-42-v3"If the representation has not changed, the server can respond with 304 Not Modified instead of sending the full representation again.
23. Cookies and Sessions
HTTP itself is stateless, but applications can maintain state using mechanisms such as cookies and server-side sessions.
Set-Cookie: session=abc123; Secure; HttpOnlyThe browser can store the cookie and send it with subsequent requests when the cookie's rules allow it.
Cookie: session=abc123This mechanism allows a server to associate multiple HTTP requests with the same authenticated session or other application state.
24. The Browser Processes the Response
For a browser request, receiving the HTTP response is not necessarily the end of the lifecycle. The browser determines how to interpret the response based on its content type and the context in which the request was made.
For an HTML document, the browser parses HTML and may discover additional resources such as stylesheets, JavaScript files, fonts, images, and other assets. Each of those resources can trigger additional HTTP requests.
<link rel="stylesheet" href="/styles.css">
<script src="/app.js"></script>
<img src="/logo.png" alt="Logo">A single page load can therefore produce many HTTP requests rather than just one request for the HTML document.
25. JavaScript API Requests
Modern frontend applications frequently make HTTP requests from JavaScript after the initial page has loaded or while rendering application data.
const response = await fetch("/api/users/42");
if (!response.ok) {
throw new Error("Request failed");
}
const user = await response.json();The browser performs the networking work and exposes the response to JavaScript through the Fetch API. Libraries such as Axios provide additional abstractions around HTTP requests.
26. CORS and Browser Security
When JavaScript running on one origin requests a resource from another origin, the browser applies the same-origin policy and related CORS rules.
The server can explicitly allow cross-origin access using response headers such as Access-Control-Allow-Origin.
Access-Control-Allow-Origin: https://app.example.comSome cross-origin requests also trigger a CORS preflight request using OPTIONS before the actual request. This means one frontend operation can result in multiple HTTP exchanges.
27. HTTP/1.1, HTTP/2, and HTTP/3
The HTTP request lifecycle depends partly on the HTTP version being used. HTTP/1.1, HTTP/2, and HTTP/3 all implement HTTP semantics, but their transport and connection behavior differ.
| Version | Important characteristic |
|---|---|
| HTTP/1.1 | Text-based message format and commonly one request at a time per connection |
| HTTP/2 | Binary framing and multiplexing multiple streams over a connection |
| HTTP/3 | HTTP over QUIC, with multiplexed streams and UDP-based transport |
HTTP/2 allows multiple requests and responses to share a connection through multiplexed streams. This reduces the need for multiple independent TCP connections.
HTTP/3 uses QUIC and avoids some limitations associated with TCP connection-level head-of-line blocking. The application-level HTTP semantics remain familiar even though the underlying transport is different.
28. Connection Reuse
Creating a new connection has a cost. Browsers and HTTP clients therefore try to reuse connections when possible.
With HTTP/1.1, persistent connections allow multiple requests to use the same TCP connection. HTTP/2 goes further by multiplexing streams over a shared connection.
Connection reuse can remove repeated DNS, TCP, and TLS overhead for subsequent requests to the same destination when the relevant connection remains available.
29. Measuring HTTP Request Time
The total time visible to the client can be divided into several phases. Browser developer tools often expose timings that help identify where latency is occurring.
| Phase | What it represents |
|---|---|
| Queueing | Time before the request is actually dispatched |
| DNS | Hostname resolution |
| Connection | Transport connection establishment |
| TLS | HTTPS security negotiation |
| Request sent | Time required to transmit request data |
| Waiting / TTFB | Time until the first response byte is received |
| Download | Time required to receive the response body |
Not every request has a non-zero value for every phase. For example, a reused connection can eliminate the need for a new TCP or TLS handshake.
30. What Is TTFB?
Time to First Byte, or TTFB, measures the time between starting a request and receiving the first byte of the response. It can include network latency, connection setup, server processing, and other stages depending on how the measurement is defined.
A high TTFB does not automatically mean that the application server is slow. DNS, network distance, connection establishment, proxies, CDNs, and server processing can all contribute.
31. Common HTTP Request Failures
| Problem | Possible stage |
|---|---|
| DNS resolution failure | DNS |
| Connection refused | Network connection |
| TLS certificate error | TLS |
| 401 Unauthorized | HTTP/application authentication |
| 404 Not Found | HTTP routing/resource lookup |
| 429 Too Many Requests | Application/rate limiting |
| 500 Internal Server Error | Server/application processing |
| 504 Gateway Timeout | Gateway/proxy waiting for an upstream service |
The status code alone does not always identify the root cause. For example, a 504 response indicates that a gateway or proxy did not receive an appropriate response from an upstream service in time, but the underlying issue could be in that upstream application or one of its dependencies.
32. A Complete Example
Suppose a browser requests the following API endpoint:
GET https://api.example.com/products/42- The browser parses the HTTPS URL.
- It checks whether DNS information, a connection, or a cached response can be reused.
- If necessary, DNS resolves api.example.com to an IP address.
- The client establishes the required network connection.
- TLS negotiation establishes encrypted communication for HTTPS.
- The browser sends a GET request with headers such as Host and Accept.
- A proxy, CDN, load balancer, or web server may receive the request first.
- The application authenticates and validates the request if necessary.
- The application retrieves product data from a database or another service.
- The server creates a 200 OK response containing JSON.
- The response travels back through the network.
- The browser receives and parses the response.
- JavaScript can read the JSON and update the page.
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": 42,
"name": "Mechanical Keyboard",
"price": 99.99
}33. How to Debug a Slow HTTP Request
When a request is slow, avoid immediately assuming that the backend is responsible. Break the lifecycle into stages and determine where the time is being spent.
- Check whether the response came from a browser or CDN cache.
- Check DNS timing and whether the hostname resolves quickly.
- Check whether a new connection was required.
- Check TLS negotiation time for HTTPS requests.
- Check request queueing and upload time.
- Inspect TTFB to understand how long the client waited for the response to begin.
- Check response download time and payload size.
- Inspect redirects and determine whether unnecessary hops exist.
- Check whether the backend performs slow database queries or external API calls.
- Look for retries, preflight requests, or other additional network requests.
34. Tools for Inspecting the Lifecycle
Different tools help investigate different stages of the HTTP lifecycle.
| Tool type | Useful for |
|---|---|
| HTTP request builder | Testing methods, URLs, headers, query parameters, and bodies |
| HTTP header viewer | Inspecting request and response headers |
| DNS lookup | Checking DNS records and hostname resolution |
| TLS version checker | Inspecting supported TLS versions and HTTPS configuration |
| HTTP response formatter | Making response headers and bodies easier to inspect |
Browser developer tools are also particularly useful because the Network panel can show request headers, response headers, status codes, timing information, transferred data, redirects, initiators, and cached resources.
35. HTTP Request Lifecycle vs API Request Lifecycle
The terms HTTP request lifecycle and API request lifecycle are sometimes used interchangeably, but they can describe different levels of abstraction.
The HTTP lifecycle focuses on network communication: request construction, transport, HTTP processing, and response delivery. An API lifecycle often includes additional application-level operations such as authentication, validation, business logic, database access, serialization, and error handling.
For a frontend developer, both perspectives are useful. Network-level problems and application-level problems can produce very different symptoms even though they appear as one request in the browser.
Frequently Asked Questions
What happens first in an HTTP request?
The client first determines the destination and request it needs to make. Depending on cached state, it may then resolve DNS, establish or reuse a network connection, perform TLS negotiation for HTTPS, and send the HTTP request.
Does DNS happen for every HTTP request?
Not necessarily. DNS results can be cached by the browser, operating system, or other resolvers. Existing connections can also be reused, so a later request may not require a new DNS lookup.
What happens before an HTTPS request is sent?
For a new connection using traditional TCP-based HTTPS, the client establishes a TCP connection and then performs a TLS handshake before sending encrypted HTTP data. Modern protocols such as HTTP/3 use QUIC and have different connection mechanics.
What is the difference between HTTP and HTTPS in the request lifecycle?
HTTPS adds TLS protection to HTTP communication. The HTTP request and response semantics remain, but the data is transmitted through an encrypted connection and the client authenticates the server using its certificate.
Why can one page generate many HTTP requests?
An HTML page can reference stylesheets, JavaScript files, images, fonts, APIs, and other resources. The browser may request each of those resources separately, although caching and connection reuse can reduce the work required.
What is TTFB?
TTFB stands for Time to First Byte. It measures how long it takes from the start of a request until the first response byte is received. Depending on the measurement, it can include connection setup, network latency, server processing, and other stages.
Can a CDN receive an HTTP request before my server?
Yes. A CDN or reverse proxy can sit between the client and the origin server. It may serve a cached response directly or forward the request to the origin after performing routing, security, or other processing.
Where should I look when an API request is slow?
Inspect the request timing in browser developer tools or another HTTP client. Check DNS, connection and TLS timing, request queueing, TTFB, response download time, redirects, payload size, and server-side operations such as database queries and external service calls.
Conclusion
An HTTP request is more than a simple message sent from a browser to a server. Depending on the connection state and protocol, the lifecycle can involve DNS resolution, network connection establishment, TLS negotiation, request construction, proxies or CDNs, server-side processing, response generation, caching, redirects, and browser processing.
Understanding each stage makes web development and debugging much easier. A DNS failure happens before HTTP processing, a TLS error happens before normal encrypted HTTP communication, a 404 is an HTTP-level response, and a slow TTFB can point toward network or server-side latency.
When diagnosing performance or connectivity problems, break the request into its individual stages instead of treating the entire request as one operation. That approach makes it easier to identify where the delay or failure actually occurs.