Leer en español · Lire en français · Auf Deutsch lesen
Section 0.4 of 0.8 · Beginner · 18 min read
Networks, the internet and the web: IP, DNS, HTTP and the client-server model
Video lesson
5 min · narrated, with captionsListen only (audio)
Read the transcript
Almost no modern software runs alone. A food delivery app on your phone talks to the company's servers, which talk to restaurants and a payment provider. Sending data over the internet is a lot like sending post. In this lesson we follow the parcels.
The internet is a network of networks: millions of separately owned networks that agree to carry each other's traffic, using common rules called protocols. Data doesn't travel as one stream. It's cut into small packets, each labelled with where it came from and where it's going. Devices called routers pass the packets on, hop by hop, like sorting offices. Packets from the same message may take different routes, and the receiving computer puts them back together.
Every device on the internet is reached through an IP address, short for Internet Protocol. It's like the street address of an office building. But a computer runs many programs at once, so a port number says which program should receive the packet: the room number. TCP gives two programs a reliable connection: lost packets are sent again, and everything arrives in order, like recorded delivery. UDP just sends packets, with no guarantees, like postcards. That suits video calls and games, where a late fragment of sound is worse than a missing one.
People remember names like shop dot example. Networks route by numbers. The Domain Name System, or DNS, is the internet's address book that translates one into the other. Your device asks a recursive resolver, usually run by your internet provider or a public service, to do the legwork. The resolver asks a root server, which doesn't know the answer, but knows who looks after the top level domain. The top level domain server points it to the domain's own authoritative server. And the authoritative server replies with the actual address. The resolver passes it back to your device. Answers are remembered, or cached, for a time set by the domain owner, so most lookups take just a few milliseconds.
Once two programs can reach each other, they need a shared language. On the web that's HTTP. The client sends a request, naming a method, a path, some headers and sometimes some data. The method says what to do: get fetches something, post submits something new, such as an order, put replaces something, and delete removes it. The server sends back one response, with a status code saying how it went. Codes in the two hundreds mean success. Codes in the four hundreds mean the request was wrong, such as four oh four, not found. Codes in the five hundreds mean the server failed, and retrying later may work.
Plain HTTP is readable by anyone on the path, such as someone on the same café Wi-Fi. HTTPS sends it through a protected channel created by TLS, which keeps it private and detects tampering. It also proves you're really talking to the right site, using a certificate, which works like a passport signed by an authority your device trusts. But it doesn't prove the site is honest.
Bandwidth is how much data can flow per second: the width of the pipe. Latency is how long data takes to arrive: the length of the pipe. Now, a shop hosted in London, and a customer in Sydney. Even light in fibre takes time to cross the world, so each round trip takes about a quarter of a second. First, a DNS lookup. Then two handshakes, one to connect and one to set up encryption: half a second. Then the page itself, and the files it needs: another half a second. That's about a second before anything useful appears, and faster broadband would barely change it. Serve the same content from Sydney, and the same steps take about a twentieth of a second. That's why architects cut round trips and move content closer to users.
Let's put it all together. Here's a browser loading a product page. Time runs downwards. First, the browser asks DNS where shop dot example is, and gets an address. Then it opens a connection, sets up encryption, and sends its request for product forty two. The web server asks its database for the product, so the server is also a client. The server replies, two hundred, okay, with the page. The browser fetches the images and styles, and draws the page. This is the client and server model. Clients start requests; servers hold the shared data and rules. And because an app can be modified by its user, a server must never trust a client blindly.
Remember: once a system spans more than one computer, every call between its parts is slower and can fail. The full section has more. Next, in Section zero point five, we look at where data is stored.
What you need to know
- Data crosses networks in packets, which routers forward hop by hop using the destination's IP address; a port number identifies the program on that machine.
- TCP provides a reliable, ordered connection after a handshake; UDP sends individual packets with no guarantees but less delay.
- DNS turns names into IP addresses through a hierarchy of root, top-level domain and authoritative servers, with heavy caching controlled by TTLs.
- HTTP is a stateless request-response protocol: a method (GET, POST, PUT, DELETE), a path, headers and a body, answered by a status code (2xx, 3xx, 4xx, 5xx).
- HTTPS is HTTP over TLS, which encrypts traffic, detects tampering and uses certificates signed by trusted authorities to prove the server's identity.
- In the client-server model clients start requests and servers hold shared data and rules; servers must never trust clients blindly.
- Latency (delay) and bandwidth (capacity) are different; latency is limited by the speed of light, so distance and round trips matter.
Networks and packets
Almost no modern software runs alone. A food-delivery app on your phone talks to the company's servers, which talk to restaurants' tablets, a payment provider, a mapping service and a notification service. This section explains how that talking works, from the bottom up.
A network is a set of computers connected so they can exchange data, by cable, Wi-Fi, mobile signal or fibre-optic link. The internet is a network of networks: millions of separately owned networks (home broadband, mobile operators, universities, cloud providers) that have agreed to carry each other's traffic using common rules called protocols.
Data does not travel as one continuous stream. It is cut into packets: chunks typically up to about 1,500 bytes, each labelled with where it came from and where it is going, like a parcel with a sender's and recipient's address. Devices called routers pass packets from network to network, each choosing a good next hop, much as sorting offices pass parcels on towards their destination. Different packets from the same message may take different routes, arrive out of order or occasionally be lost, and the receiving computer puts them back together. Splitting data into packets lets millions of conversations share the same cables fairly, and lets traffic flow around a broken link.
Packets find their own way
Addresses: IP addresses and ports
For a packet to arrive, the destination needs an address. Every device on the internet is reached through an IP address (IP stands for Internet Protocol). The older version, IPv4, writes addresses as four numbers from 0 to 255, such as 192.0.2.10; it allows about 4.3 billion addresses, which are not enough for every phone, laptop and sensor in the world. The newer IPv6 uses much longer addresses written in hexadecimal (base 16, using the digits 0 to 9 and the letters a to f), such as 2001:db8::1, and has room for practically unlimited devices. Both are in use side by side. (The example addresses in this section come from ranges reserved for documentation, so they belong to no real machine.)
An IP address gets a packet to the right computer, but a computer runs many programs at once. A port number, from 0 to 65535, says which program should receive it. If the IP address is the street address of an office building, the port is the room number. Well-known services have standard ports: 443 for HTTPS, 80 for plain HTTP, 53 for DNS, 5432 for the PostgreSQL database. A server program listens on a port, waiting for connections; when your browser contacts a website it connects to port 443 at the site's IP address.
TCP and UDP: two ways to deliver
On top of IP sit two main transport protocols, which decide how much care is taken over delivery. TCP (Transmission Control Protocol) gives two programs a reliable, ordered stream of bytes. Before any data is sent, the two sides set up a connection with a three-step handshake. Each packet is numbered; the receiver acknowledges what arrived; anything missing is sent again; everything is handed to the program in the right order. TCP also slows down when the network is congested. It is like a recorded-delivery service with tracking: dependable, but with some overhead.
UDP (User Datagram Protocol) simply sends individual packets, called datagrams, with no handshake, no acknowledgements, no resending and no ordering. It is like posting postcards: cheap and quick, but some may not arrive. That is exactly right when a late packet is useless anyway. In a video call, a fragment of sound that arrives half a second late is worse than one that never arrives, so calls, live streams and online games use UDP and cope with small gaps. DNS lookups, which are tiny questions and answers, also traditionally use UDP.
TCP and UDP compared
| TCP | UDP | |
|---|---|---|
| Connection set-up | Yes: a handshake before data flows | None: just send |
| Delivery | Guaranteed: lost packets are resent | Best effort: losses are not repaired |
| Order | Preserved | Not guaranteed |
| Overhead and delay | Higher | Lower |
| Typical uses | Web pages and APIs (HTTP/1.1 and HTTP/2), email, file transfer, database connections | Voice and video calls, live streaming, online games, DNS |
DNS: the internet's address book
People remember names such as shop.example; networks route by IP addresses. The Domain Name System (DNS) translates one into the other. It is a worldwide, distributed directory: no single computer holds every name. Instead, responsibility is split by the dots in the name, read from right to left. The root servers know who is responsible for each top-level domain such as .com or .uk; those top-level domain servers know which authoritative name servers are responsible for each domain registered under them; and the authoritative servers hold the actual records, such as the IP address of www.shop.example. The root zone is served by 13 named server identities, run by 12 independent organisations through well over a thousand server instances around the world.
Your device does not usually walk this chain itself. It asks a recursive resolver, typically run by your internet provider or a public service, which does the legwork and remembers (caches) answers for a period set by the domain owner, called the TTL (time to live). Because answers are cached at many levels, most lookups are answered in a few milliseconds without reaching the root at all. The same caching explains why a change to a DNS record can take minutes or hours to be seen everywhere.
DNS resolution step by step (nothing cached)
- Ask the resolverYour device asks its configured recursive resolver: what is the IP address of
www.shop.example? - Ask a root serverThe resolver asks a root server, which does not know the answer but replies with the servers responsible for the top-level domain.
- Ask the top-level domain serverThe resolver asks one of those servers, which replies with the authoritative name servers for
shop.example. - Ask the authoritative serverThe resolver asks the authoritative server, which replies with the record: for example
203.0.113.5, valid for 300 seconds. - Answer and rememberThe resolver returns the address to your device, and both keep it in their caches until the TTL runs out, so the next lookup is almost instant.
Who answers a DNS question
HTTP: requests and responses
Once a program can reach another, the two need a shared language for what they want. On the web that language is HTTP (Hypertext Transfer Protocol). It follows a simple pattern: the client sends a request; the server sends back one response. Each request names a method (what to do), a path (to what), some headers (extra information as name-value pairs) and sometimes a body (data being sent). Each response carries a status code, headers and usually a body: a web page, an image or data in a format such as JSON (a simple text format for structured data, explained in the section on APIs).
The most common methods are GET (fetch something, without changing it), POST (submit something new, such as placing an order), PUT (replace something at a known address, such as updating a delivery address) and DELETE (remove something). GET, PUT and DELETE are defined to be idempotent: sending the same request twice has the same effect as sending it once, which makes them safe to retry after a network failure. POST is not, which is why a careless retry can place an order twice. Headers carry things such as the content type (Content-Type: application/json), the language the user prefers, cookies (small pieces of data a site asks the browser to store and send back with later requests) and credentials, and caching instructions.
HTTP is stateless: each request is understood on its own, and the server is not required to remember earlier ones. Logged-in sessions are built on top, usually by the client sending a cookie or token with every request. Statelessness is one reason the web scales so well, because any of many identical servers can handle any request.
POST /api/orders HTTP/1.1
Host: shop.example
Content-Type: application/json
Authorization: Bearer eyJhbGciOi...
{"product_id": 42, "quantity": 2}
HTTP/1.1 201 Created
Content-Type: application/json
Location: /api/orders/9917
{"order_id": 9917, "status": "received", "total_pence": 3000}Status codes by family
| Family | Meaning | Common examples |
|---|---|---|
| 2xx | Success | 200 OK; 201 Created (something new was made); 204 No Content |
| 3xx | Redirection: look elsewhere | 301 Moved Permanently; 302 Found (temporary move); 304 Not Modified (your cached copy is still good) |
| 4xx | Client error: the request was wrong | 400 Bad Request; 401 Unauthorized (not logged in); 403 Forbidden (logged in but not allowed); 404 Not Found; 429 Too Many Requests |
| 5xx | Server error: the request was fine, the server failed | 500 Internal Server Error; 502 Bad Gateway; 503 Service Unavailable; 504 Gateway Timeout |
The split between 4xx and 5xx matters in practice. A 4xx says "do not simply retry; fix the request". A 5xx says "the problem is on our side"; retrying later may work, and the operations team should be alerted when 5xx rates rise.
HTTPS and TLS: privacy and identity
Plain HTTP sends everything as readable text, so anyone on the path, such as someone on the same café Wi-Fi, could read or alter it. HTTPS is HTTP sent through a protected channel created by TLS (Transport Layer Security; the current version, TLS 1.3, was published as RFC 8446 in 2018). TLS provides three things: confidentiality (eavesdroppers see only scrambled data), integrity (tampering is detected) and authentication (you are really talking to shop.example, not an impostor).
Authentication rests on certificates. A site's certificate is a digital document saying, in effect, "this public key belongs to shop.example", signed by a certificate authority (CA) that your browser or phone already trusts. It works like a passport: issued by an authority both sides trust, checked against the holder, and valid only until its expiry date. During the TLS handshake the server presents its certificate, the client checks the signature, the name and the dates, and the two sides agree on fresh secret keys for encrypting the rest of the conversation. If any check fails, the browser shows a warning.
TLS protects data in transit between two points. It does not protect data once it is stored, and it does not prove that the site is honest, only that it is who it claims to be. Today HTTPS is the norm for all web traffic, not just payments, and certificates are often issued free and renewed automatically.
The client-server model
Most of the systems in this course follow the client-server model. A client (a browser, a mobile app, another program) starts the conversation by sending a request. A server waits for requests and answers them. The server holds what must be shared and trusted: the product catalogue, everyone's orders, the rules about prices and refunds. The client handles the user's screen and input.
In a restaurant, diners are clients and the kitchen is the server: diners initiate orders; the kitchen holds the ingredients and the expertise and serves many diners at once. One consequence is that the server must never trust the client blindly. A phone app can be modified by its user, so prices, permissions and stock levels must be checked on the server, however carefully the app also checks them.
A server is often also a client: the shop's web server is a client of its database and of the payment provider. Real systems are chains and webs of such relationships, as the sequence diagram below shows.
Latency and bandwidth
Two numbers describe how fast a network feels, and they are often confused. Bandwidth is how much data a connection can carry per second, such as 100 megabits per second: the width of the pipe. Latency is how long a piece of data takes to get from one end to the other, usually measured as a round-trip time (RTT) in milliseconds: the length of the pipe. A motorway analogy helps: adding lanes (bandwidth) lets more cars through per hour but does not make any one car's journey shorter (latency).
Latency has a floor set by physics. Light in optical fibre travels at roughly 200,000 km per second, about two-thirds of its speed in a vacuum. London and Sydney are about 17,000 km apart in a straight line around the globe, so even a perfect fibre along that line would need about 85 ms one way and 170 ms for a round trip. Real cables do not follow the shortest path and routers add delay, so measured round trips are typically around 250 ms. No upgrade can remove that. If loading a page from Sydney needs ten sequential round trips to a server in London, the user waits two and a half seconds, however fast their broadband is.
Worked example
Worked example: a London server, a Sydney customer
A shop hosts everything in London. A customer in Sydney opens a product page over a new HTTPS connection. Assume a round trip of 250 ms and ignore server processing time.
| DNS lookup (not cached) | Resolver may need several queries; say 1 round trip to nearby servers: about 50 ms |
|---|---|
| TCP handshake | 1 round trip to London: 250 ms |
| TLS 1.3 handshake | 1 round trip: 250 ms |
| Request the HTML page | 1 round trip: 250 ms |
| Request CSS and scripts the page needs | At least 1 more round trip: 250 ms |
| Total before anything useful appears | About 1,050 ms, with bandwidth playing almost no part |
| Same customer, content served from Sydney | Round trip of perhaps 10 ms: the same five steps take roughly 50 ms |
For small pages, latency, not bandwidth, dominates. Upgrading the customer's broadband from 50 to 500 megabits per second would barely change the result.
Architects reduce latency by cutting round trips (reusing connections, combining requests) and by moving content closer to users, for example with content delivery networks, covered in Servers and the cloud.
Decision guide
Decision guide: is a slow network experience about latency or bandwidth?
A rough first diagnosis when users complain that something is slow over the network.
- Are small requests (a short API call, a tiny page) slow too?YesLatency is the likely cause. Check the distance to the server and how many sequential round trips the page or app makes.NoGo to the next question.
- Are only large transfers (videos, big downloads, large reports) slow?YesBandwidth is the likely limit, on the user's connection or the server's. Consider compression, smaller files or a content delivery network.NoGo to the next question.
- Is the delay the same from every location?YesThe network may not be the problem at all: look at server processing, database queries and algorithms (see the data and algorithms section).NoLocation-dependent delay points to latency and routing: serve users from closer to where they are.
What happens when you type a web address
All of these pieces come together every time you visit a website. Here is the sequence when you type https://shop.example/products/42 and press Enter, simplified but accurate.
From Enter to page
- Parse the addressThe browser splits the URL into the scheme (
https, so port 443 and TLS), the host name (shop.example) and the path (/products/42). - Find the IP addressThe browser checks its own cache, then the operating system's, then asks the recursive resolver, which consults DNS as described above and returns, say,
203.0.113.5. - Open a TCP connectionThe browser and server exchange the three handshake messages to set up a reliable connection to port 443.
- Set up TLSThe server presents its certificate; the browser checks it is valid for
shop.exampleand signed by a trusted authority; both sides agree on encryption keys. - Send the HTTP requestThe browser sends
GET /products/42with headers such as the accepted languages and any cookies for the site. - The server does its workServer software receives the request, runs the shop's code, which queries a database for product 42, and builds an HTML page.
- Receive the responseThe server replies
200 OKwith the HTML in the body and headers such asContent-Type: text/htmland caching rules. - Fetch the restThe HTML refers to stylesheets, scripts and images; the browser requests those too, often many at once over the same connection.
- RenderThe browser lays out the page and draws it on screen; scripts may then make further requests, for example to fetch reviews.
Sequence diagram: loading a product page
Why this matters for architecture
The moment a system is split across more than one computer, every interaction between its parts becomes a network call, with latency, the chance of failure and the need for security. A function call inside a program takes nanoseconds and never gets lost; a call across a network takes milliseconds, sometimes far more, and sometimes never returns. Many of the hardest problems in architecture follow from that difference, which is why Chapter 6 opens with the fallacies of distributed computing, such as the belief that latency is zero.
The protocols here also reappear as building blocks: HTTP underpins the web APIs in the next part of this chapter and the communication styles of Chapter 6, while TLS and certificates return in secure communication and zero trust. Placing servers close to users is part of multi-region and edge architecture.
Check your understanding
Why does a packet need a port number as well as an IP address?
The IP address gets it to the right computer, but that computer runs many programs; the port says which program, such as the web server listening on 443, should receive it.
What does a 3xx status code tell the client?
That what it asked for is elsewhere or unchanged: for example 301 means it has moved permanently, and 304 means the client's cached copy is still valid.
What is the difference between a 401 and a 503 response?
401 is a client error: the request lacks valid credentials. 503 is a server error: the service is temporarily unable to handle the request.
Why can no network upgrade bring a London to Sydney round trip down to 10 ms?
Light in fibre covers about 200,000 km per second, so the roughly 34,000 km round trip takes at least about 170 ms.
Sources and further reading
Have a question about this section? ArchitectBot, the course’s AI study assistant, answers from the course first.
Ask: “Our users in Australia say the app is slow but our servers are in Europe. What are my options and what does each cost?”