exit lab
Backend Engineering
Level 2·http·concept·beginner

Client–Server and HTTP Request Lifecycle

Trace a browser or API request through DNS, TLS, a reverse proxy, Spring Security, application layers, PostgreSQL, and the response path.

35 minutes HTTP semantics per RFC 9110; TLS 1.3; Spring Boot 3.5 servlet stack Updated 2026-07-16
HTTPTLSNginxSpring BootPostgreSQL

Learning objectives

  • Name every major hop in a production HTTP request
  • Separate transport, proxy, security, application, and database failures

What it is

A request lifecycle is the ordered work that begins when a client resolves a host and ends when it receives, interprets, and possibly caches an HTTP response. The application controller is only one stage in that path.

Why it matters

Production failures often sit outside business code. DNS errors, TLS negotiation, proxy timeouts, security filters, exhausted application pools, slow SQL, serialization, and client cancellation can produce similar symptoms unless you know the boundaries.

How it works

End-to-end request path

Client
DNS
TCP + TLS
Reverse proxy
Spring filter chain
Controller
Service + transaction
MyBatis
PostgreSQL
HTTP response
Text alternative: The client resolves DNS, establishes TCP and TLS, sends HTTP through a reverse proxy and Spring filters, then the controller calls a transactional service, MyBatis, and PostgreSQL before the response returns through the same network path.
  1. 1

    Resolve and connect

    DNS maps the host name to an address; TCP creates an ordered byte stream; TLS authenticates the server and protects the connection.

  2. 2

    Route and protect

    The reverse proxy terminates or forwards TLS, applies size and timeout policy, and sends the request to a healthy application instance. Servlet filters run before the controller, including Spring Security.

  3. 3

    Execute application work

    Spring maps input, validates it, invokes a service, opens the intended transaction, runs parameterized SQL through MyBatis, and serializes the result.

  4. 4

    Return and observe

    Status, headers, and body travel back through the proxy. Logs, metrics, and trace context should identify the same request without exposing credentials.

Simple example

request-and-response.http
GET /v1/tasks/42 HTTP/1.1
Host: api.example.com
Accept: application/json
Traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store

{"id":42,"title":"Review settlement","status":"OPEN"}

HTTP defines the message semantics. It does not guarantee that the database committed only once; that is an application and data-consistency responsibility.

Backend example

Spring servlet path

HTTP request
Correlation filter
SecurityFilterChain
DispatcherServlet
Controller
Validation
Service
@Transactional
Mapper
Database
Response
Text alternative: An HTTP request crosses a correlation filter and Spring Security before DispatcherServlet selects a controller. Valid input reaches a service transaction, mapper, and database, then the result is serialized into the response.
TaskController.java
@RestController
@RequestMapping("/v1/tasks")
final class TaskController {
    private final TaskQueryService taskQueryService;

    TaskController(TaskQueryService taskQueryService) {
        this.taskQueryService = taskQueryService;
    }

    @GetMapping("/{id}")
    TaskResponse findById(@PathVariable long id) {
        return taskQueryService.findById(id);
    }
}

Production example

SymptomLikely boundaryFirst evidence
Name cannot be resolvedDNSResolver result and authoritative records
TLS handshake failureTLS/proxyCertificate chain, SNI, protocol logs
413 responseProxy or server limitConfigured request-size limits
401/403Security filter/authorizationSanitized security decision and principal context
Requests queue while CPU is lowThread or connection poolActive/idle/wait metrics and thread dump
Slow only for one query shapeDatabase plan/lockEXPLAIN plan, lock wait, statement timing

Common mistakes

  • Calling the controller the start of the request
  • Trusting inbound X-Forwarded-* headers from the public internet
  • Logging Authorization or Cookie values
  • Using retries without an idempotency and deadline policy
  • Treating a client timeout as proof that server-side work rolled back

Best practices

  • Use one correlation or trace context across trusted boundaries
  • Configure connect, read, write, queue, and database timeouts explicitly
  • Return protocol-correct status and media types
  • Keep reverse-proxy and application limits aligned
  • Measure latency at each boundary, not only end to end

Trade-offs

ChoiceBenefitCost
TLS at proxyCentral certificate and routing policyInternal hop still needs a trust decision
TLS passthroughEnd-to-end application terminationLess proxy visibility and harder certificate operations
Keep-aliveAvoid repeated connection setupConsumes connection state and needs idle limits

Interview questions

  • What happens after a user enters an HTTPS URL?
  • Where do Spring Security filters run relative to a controller?
  • Why can a client receive a timeout while the database change still commits?
  • What is the difference between a forward proxy and reverse proxy?

Hands-on task

  1. 1

    Trace

    Call a local Spring endpoint with curl -v and record DNS, connection, request, response, and timing evidence.

  2. 2

    Instrument

    Add a correlation filter and structured request-completion log that excludes credentials and request bodies.

  3. 3

    Fail

    Introduce a slow query and compare client, proxy, application, and database timeouts.

References

  • IETF: RFC 9110 — HTTP Semantics — https://www.rfc-editor.org/rfc/rfc9110
  • IETF: RFC 8446 — The Transport Layer Security Protocol Version 1.3 — https://www.rfc-editor.org/rfc/rfc8446
  • Spring: Annotated Controllers — https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller.html
  • NGINX: NGINX Reverse Proxy Guide — https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

Retrieval check

Before you continue

  • Explain the main idea in your own words without rereading the page.
  • Name one production problem this knowledge helps prevent.
  • Describe where you would apply it in a Spring Boot project.

Source metadata

Primary references checked on 2026-07-16. Version scope is stated at the top of this page.