Dev Learning Lab

The labs on this site need JavaScript to run. The same content is written out below.

Learn › Networking › The big picture

From URL to response

What happens when you type a URL in the address bar and press Enter

Why it exists — To open one address, you need to turn the name into an IP address, make a connection, encrypt so that no one can snoop, send the request to the right server, and actually produce the result. A web request is processed in a structure where DNS, TCP, TLS, a reverse proxy, and an application server each take one of these jobs, so that moving servers, changing certificates, or adding servers does not require changing the other stages.

Where it's used today — It is used to break down at which stage time is spent when a page is slow. The Network tab of the browser's developer tools and curl's timing measurements show separately the DNS lookup, the connection, TLS, and the time to the first byte. When placing servers, this separation of stages is followed too, as in leaving static files to nginx or a CDN and requests whose result must be computed to the application server.

While a browser opens a single URL, a DNS lookup, a TCP connection, a TLS handshake, an HTTP request, a reverse proxy, an application server, and a database take part one after another. Some steps can be skipped thanks to a cache or connection reuse.

Checked against real execution · Ran the steps and round trips of all 16 combinations with nginx 1.27, Spring Boot 4.1.1, MySQL, dnsmasq, and curl, and checked (curl plays the browser, and nginx proxy_cache stands in for the CDN)

Concepts in this lab

DNS
The system that translates a domain name (example.com) into the IP address that computers use to communicate. When you enter an address in a browser, the browser first asks this system for the IP address of that name and then connects to that IP address. Lookup results are cached for a certain time.
Web server and application server
Why it exists — If one application server takes on static file delivery and TLS handling in addition to running code, then every time you scale the application server to several machines or replace it, these settings also have to be adjusted on each server. If you put a web server in front, the shared work can be handled there, and the application server can concentrate on running code.
Where it's used today — A Spring Boot web application runs on embedded Tomcat by default, so it is itself an application server. In the cloud, a setup in which a load balancer or CDN takes TLS handling and static file delivery instead of a web server is also common.
A web server is a program that receives HTTP requests and either responds with static files such as images and HTML or forwards the requests to another server (Nginx, Apache). An application server (web application server) is a program that runs program code and builds a result for each request (Tomcat). A common setup puts a web server in front and passes requests on to the application server.
Reverse proxy
Why it exists — If slow clients connect straight to an application server, the request processing threads stay tied up with those connections while the clients slowly upload a large request body or slowly take a response. A reverse proxy such as Nginx, in its default configuration, buffers requests and responses and exchanges data quickly with the backend server, so the backend server's threads are not tied up for long by slow connections.
Where it's used today — It is used to split static file requests and /api requests by path and send them to different servers, or to reject too-large uploads at the front with Nginx's client_max_body_size. In Kubernetes, an Ingress controller takes this role.
A server that receives client requests on behalf of internal servers, forwards them to those servers, and returns their responses to the client. The client does not know the actual servers directly. Its roles include distributing requests across several servers, handling TLS, caching, and protecting the internal servers.
CDN
A network that keeps copies of content on servers placed in many regions around the world and has a server close to the user respond. Static files such as images, video, and scripts are delivered faster, and fewer requests go to the origin server.
HTTPS and TLS
HTTPS is HTTP communication encrypted with TLS. TLS keeps third parties from seeing the content (confidentiality), keeps it from being changed on the way (integrity), and uses a certificate to check that the server you connected to is the real one (authentication). SSL is the protocol that came before TLS. It is now deprecated and only TLS is actually used, but the name SSL is still used alongside it by habit.
Three-way handshake
Why it exists — If data is sent right away without confirming the connection, it is sent without knowing whether the other side is ready to receive, or where to start counting the numbers attached to each piece. The three-way handshake lets both sides confirm each other's starting numbers in three exchanges, which sets the basis for counting missing pieces and order afterward.
Where it's used today — Developers do not call it directly, but the connection timeout is the limit on how long to wait for this process to finish. If a firewall silently drops the SYN, there is no reply and the wait lasts until this timeout, and if no program is waiting on the other side's port, Connection refused appears right away.
The three-step process used to establish a TCP connection. The client sends a connection request (SYN), the server sends its acceptance together with its own connection request (SYN+ACK), and the client acknowledges it (ACK). After both sides have confirmed that they can send to and receive from each other, data transfer starts.

Try these

Running with the default settings

  1. The browser splits the URL https://shop.example/orders into the scheme (https), the host (shop.example), and the path. Because the scheme is https, the browser will connect to port 443.
  2. The browser does not know the IP address of shop.example. It asks a DNS server and gets the IP address back. This takes one round trip to the DNS server. The result is kept in the cache for a set time (the TTL).
  3. The browser opens a TCP connection to port 443 of that IP address (the three-way handshake). This takes one round trip to the server.
  4. In the TLS handshake, the browser verifies the certificate of the server and the two sides agree on the encryption keys. This takes one more round trip (with TLS 1.3).
  5. The browser sends the HTTP request over the encrypted connection. The request line and the headers (Host, Cookie, User-Agent, and so on) go to the server. This takes the time of one way to the server (half a round trip).
  6. nginx is the first to receive the request. It decrypts the TLS traffic, looks at the path, and decides where the request will be handled.
  7. nginx passes the request to Tomcat behind it (port 8080). Tomcat assigns a thread from its thread pool, runs the request through the filters, and hands it to the Spring DispatcherServlet.
  8. DispatcherServlet finds the controller that handles /orders and runs it. The controller calls a service, and the service calls a repository.
  9. The application borrows a connection from the connection pool, runs the SQL, receives the result, and then returns the connection to the pool.
  10. The application turns the query result into JSON or HTML and builds the response. The response travels back through Tomcat and nginx.
  11. The response travels one way, from the server to the browser, and arrives. If it is HTML, the browser parses it, finds the URLs of the CSS, scripts, and images in it, and repeats the same process for each of them.

Result of this run

Code

# nginx (reverse proxy)
server {
    listen 443 ssl;
    server_name shop.example;
    ssl_certificate     /etc/nginx/certs/shop.example.crt;   # certificate
    ssl_certificate_key /etc/nginx/certs/shop.example.key;   # private key

    location /static/ {                  # serve static files directly
        root /var/www;
    }
    location / {                         # pass everything else to the application server
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
}

Assumptions of this model

The steps of all 16 combinations were run with real software, and it was confirmed that whether each step happened, the number of round trips, and where the response was produced all match the model. The setup put a DNS server (dnsmasq 2.92), nginx 1.27.5 with the configuration on the screen, and Spring Boot 4.1.1 (embedded Tomcat 11.0.24, HikariCP, MySQL 8.4) on one Docker network, and curl 8.22 played the part of the browser. This was not run with a real browser. The round trips were counted by adding a 100ms delay to the packets leaving the curl side (tc netem) and dividing the times that curl measured by 100ms. The round trip of the request and response was counted after subtracting the time the server spent, and the whole run was done twice with the same values both times. A first request took 4 round trips in total, one each for the DNS lookup, the TCP connection, the TLS handshake (TLS 1.3), and the request and response, and a request over a reused connection took 1. The times themselves depend on the distance and the network, so they are not shown on the screen. Whether a query really went to the DNS server was confirmed in the dnsmasq log. The DNS cache is the one in curl (kept for 60 seconds), and it was confirmed that no query goes out when the connection is still open, even after the cache entry has expired. On the server side, the logs of each server confirmed that nginx decrypted the TLS traffic and answered /static/ directly without passing it on, and that the other requests passed through a Tomcat thread on port 8080, the filter, DispatcherServlet, the controller, the service, and the repository in turn and ran the SQL on a connection borrowed from the connection pool. The nginx configuration on the screen is for Spring Boot on the same machine (127.0.0.1:8080), and in the run the requests were passed to port 8080 of another container. The CDN was not a commercial service but the proxy_cache of nginx, and it was also confirmed that DNS returned the address of that server and that it answered with its copy, so no request reached the origin server. That a CDN is close to the user and so has shorter round trips was not measured by running. That the TLS 1.2 handshake takes one more round trip, and that browsers also cut round trips further with TLS session resumption or HTTP/3, were not run in this lab.

Next lab: Layers and encapsulation

Concepts in this lab

What this lab shows

Settings

Code


      
    

Diagram

Run comparison

Try these