An application is a pair of programs running on end systems, and everything in this chapter follows from deciding how those two programs find and talk to each other.
Words you will meet
- Application architecture — how you spread your application across the end systems.
- Client-server architecture — one always-on server answers many clients.
- Peer-to-peer architecture — users’ own machines serve each other directly.
- Peer — one user-owned machine in a peer-to-peer application.
- Self-scalability — the system gains capacity as it gains users.
- Process — a program that is currently running.
- Socket — the door of a program, through which its messages leave and enter.
- Port number — the number that says which program on a host a message is for.
Why this matters
Chapter 1 told you that applications run on hosts and reach the network through the socket interface. It did not say what that actually looks like from inside a program. This section does, and by section 2.7 you will be writing the code.
The two architectures introduced here also divide the rest of the chapter. The Web, e-mail and DNS (Domain Name System) Domain Name System Translates a human-friendly name such as www.ietf.org into a network address. introduced in ch. 1 are client-server. BitTorrent is peer-to-peer. Video streaming is a client-server application that had to invent new machinery to survive its own success. Knowing which pattern you are looking at tells you in advance where the hard problems will be.
Applications live at the edge
Suppose you have an idea for a network application. At its core, developing it means writing programs that run on different end systems and communicate with each other over the network. In the Web there are two such programs: the browser running on the user’s device, and the web server program running on the server host. In a video-on-demand application such as Netflix there is the Netflix app on the user’s phone and the Netflix server program.
So you must write software that runs on several end systems. You could write it in C, Java or Python. But notice what you do not have to write: software that runs on network-core devices such as routers or link-layer switches.
You could not even if you wanted to
Network-core devices do not function at the application layer. They function at lower layers — the network layer and below. There is no application layer inside a router for your code to live in.
This is not a limitation. It is the design decision that made the Internet explode. Because application software is confined to end systems, anyone can invent an application and deploy it without asking permission from anyone who owns a router. Chapter 1’s Figure 1.24 already showed you this; here is what it means for you as a developer.
Drag any device to rearrange the picture. Hover a link to see its rate, delay and length.
The thick arc is the conversation the two application programs experience. The thin lines below it are the links and routers that actually carry it. Drag anything; the arc does not care.
Read this diagram as text
- Phone — wireless link — Cell tower (60 Mbps)
- Tablet — wireless link — Cell tower (60 Mbps)
- Cell tower — wired link — R-mob (1 Gbps)
- Lin’s laptop — wireless link — Home AP (54 Mbps · 0.01 km)
- Phone — wireless link — Home AP (54 Mbps)
- Home AP — wired link — Home router (1 Gbps)
- Home router — wired link — R1 (100 Mbps · 2 ms · 8 km)
- PC — wired link — Switch (1 Gbps)
- PC — wired link — Switch (1 Gbps)
- AP — wired link — Switch (1 Gbps)
- Server — wired link — Switch (10 Gbps)
- Switch — wired link — R1 (1 Gbps)
- R-mob — wired link — R1 (1 Gbps)
- R1 — wired link — R2 (10 Gbps · 1 ms)
- R2 — wired link — R3 (100 Gbps · 34 ms · 6,800 km)
- R3 — wired link — R4 (100 Gbps · 4 ms)
- R3 — wired link — R5 (100 Gbps · 3 ms)
- R4 — wired link — R6 (100 Gbps · 5 ms)
- R5 — wired link — R6 (100 Gbps · 4 ms)
- R5 — wired link — Switch (100 Gbps)
- Switch — wired link — Servers (100 Gbps)
- R6 — wired link — R-cp (100 Gbps · 2 ms)
- R-cp — wired link — Switch (10 Gbps)
- Switch — wired link — www.example.edu (1 Gbps)
The thick arc is the conversation your two programs experience. The thin lines are what actually carries it. From the application’s point of view the arc is the whole story: a message goes in one end and comes out the other. Everything under the arc is somebody else’s problem — which is the entire point of layering.
Two application architectures
Before writing any code you need an architectural plan. Be careful here: an application architecture is not the same thing as the network architecture. The network architecture is the fixed five-layer structure of chapter 1, and from your point of view it is given. The application architecture application architecture Simple How an application spreads its work across the end systems. The developer chooses it. Precise The structure, designed by the application developer, that dictates how the application is organised over the various end systems. It is distinctly different from the network architecture (the fixed five-layer Internet architecture), which from the developer’s point of view is given and provides a specific set of services. introduced in ch. 2 — open in glossary is yours to design, and it dictates how your application is organised over the end systems.
In practice you will pick one of two dominant patterns.
Client-server
In a client-server architecture client-server architecture Simple One always-on server answers many clients. The clients never talk to each other. Precise An application architecture with an always-on host, called the server, which services requests from many other hosts, called clients. Clients do not directly communicate with each other, and the server has a fixed, well-known IP address, so a client can always contact it. The Web, FTP, Telnet and e-mail use this architecture. introduced in ch. 2 — open in glossary there is an always-on host which services requests from many other hosts.
The always-on host is called the server server Simple The host that stores content and answers requests, usually inside a data centre. Precise A more powerful host that stores and distributes Web pages, streams video, relays e-mail and so on. Most servers reside in large data centres. introduced in ch. 1 — open in glossary ; the hosts it services are called clients client Simple The host that asks for something, usually your laptop or phone. Precise A host that requests and receives service from a server. Informally, clients tend to be desktops, laptops and smartphones. introduced in ch. 1 — open in glossary . The Web is the classic example: an always-on web server answers requests from browsers.
Two properties define the pattern, and both matter:
- Clients do not communicate with each other. Two browsers never talk directly. When you send a message to a friend through a web application, it goes to the server and comes back down.
- The server has a fixed, well-known address, called an IP (Internet Protocol) Internet Protocol The network-layer protocol that defines the datagram format and addressing every Internet device must use. introduced in ch. 1 address ip address Simple The number that identifies a device on the Internet, written like 192.168.1.24. Precise An address that every host on the Internet has, carried in a packet's header. Like a postal address it has a hierarchical structure, so a router can examine only a portion of it to index its forwarding table. introduced in ch. 1 — open in glossary . Because the address is fixed and the server is always on, a client can always reach it by sending a packet to that address.
Drag any device to rearrange the picture. Hover a link to see its rate, delay and length.
Play any journey. Every one of them ends at the same always-on server in the data centre. No arrow ever joins two clients.
Read this diagram as text
- Phone — wireless link — Cell tower (60 Mbps)
- Tablet — wireless link — Cell tower (60 Mbps)
- Cell tower — wired link — R-mob (1 Gbps)
- Lin’s laptop — wireless link — Home AP (54 Mbps · 0.01 km)
- Phone — wireless link — Home AP (54 Mbps)
- Home AP — wired link — Home router (1 Gbps)
- Home router — wired link — R1 (100 Mbps · 2 ms · 8 km)
- PC — wired link — Switch (1 Gbps)
- PC — wired link — Switch (1 Gbps)
- AP — wired link — Switch (1 Gbps)
- Server — wired link — Switch (10 Gbps)
- Switch — wired link — R1 (1 Gbps)
- R-mob — wired link — R1 (1 Gbps)
- R1 — wired link — R2 (10 Gbps · 1 ms)
- R2 — wired link — R3 (100 Gbps · 34 ms · 6,800 km)
- R3 — wired link — R4 (100 Gbps · 4 ms)
- R3 — wired link — R5 (100 Gbps · 3 ms)
- R4 — wired link — R6 (100 Gbps · 5 ms)
- R5 — wired link — R6 (100 Gbps · 4 ms)
- R5 — wired link — Switch (100 Gbps)
- Switch — wired link — Servers (100 Gbps)
- R6 — wired link — R-cp (100 Gbps · 2 ms)
- R-cp — wired link — Switch (10 Gbps)
- Switch — wired link — www.example.edu (1 Gbps)
Other well-known client-server applications include FTP (File Transfer Protocol) File Transfer Protocol An application-layer protocol for transferring files between two hosts. introduced in ch. 1 , Telnet and e-mail.
There is a problem, and it arrives with success. A single server host often cannot keep up with all the requests. A popular social-networking site with one server would be overwhelmed immediately. So a data centre data center Simple A building full of thousands of servers, joined by their own internal network. Precise A facility housing tens to hundreds of thousands of hosts, called blades and stacked 20 to 40 per rack, interconnected by a data centre network and connected to the Internet. introduced in ch. 1 — open in glossary , housing a large number of hosts, is used to create one powerful virtual server. Every one of the most popular Internet services runs in one or more data centres:
- search engines such as Google, Bing and Baidu;
- commerce sites such as Amazon, eBay and Alibaba;
- web mail such as Gmail and Yahoo Mail;
- social media such as Facebook, Instagram, Twitter and WeChat.
As section 1.3.3 noted, Google had 19 data centres around the world as of 2020, handling search, YouTube, Gmail and the rest between them.
A data centre can hold hundreds of thousands of servers, all of which must be powered and maintained. On top of that, the service provider pays recurring interconnection charges for sending data out of its data centres. Keep that bill in mind: sections 2.2.5 and 2.6.3 are largely about reducing it.
Peer-to-peer
In a peer-to-peer peer-to-peer architecture Simple Users’ own machines send files straight to each other, with little or no help from servers. Precise An application architecture with minimal or no reliance on dedicated servers in data centres. The application exploits direct communication between pairs of intermittently connected hosts, called peers, which are controlled by users rather than owned by the service provider. BitTorrent is the best-known example. introduced in ch. 2 — open in glossary ( P2P (Peer-to-Peer) Peer-to-Peer An architecture where users’ own machines serve each other directly. introduced in ch. 2 ) architecture there is minimal, or no, reliance on dedicated servers in data centers. Instead the application exploits direct communication between pairs of intermittently connected hosts, called peers peer Simple One user-owned machine in a peer-to-peer application. It downloads and uploads at the same time. Precise An intermittently connected host in a P2P architecture, not owned by the service provider but controlled by a user. Most peers reside in homes, universities and offices. introduced in ch. 2 — open in glossary .
The peers are not owned by the service provider. They are desktops and laptops controlled by users, most of them in homes, universities and offices. Because they communicate without passing through a dedicated server, the architecture is called peer-to-peer. The best-known example is the file-sharing application BitTorrent, which section 2.5 covers in detail.
Drag any device to rearrange the picture. Hover a link to see its rate, delay and length.
The same map, the same links. But now every journey runs between two ordinary user machines, and the data centre is never touched.
Read this diagram as text
- Phone — wireless link — Cell tower (60 Mbps)
- Tablet — wireless link — Cell tower (60 Mbps)
- Cell tower — wired link — R-mob (1 Gbps)
- Lin’s laptop — wireless link — Home AP (54 Mbps · 0.01 km)
- Phone — wireless link — Home AP (54 Mbps)
- Home AP — wired link — Home router (1 Gbps)
- Home router — wired link — R1 (100 Mbps · 2 ms · 8 km)
- PC — wired link — Switch (1 Gbps)
- PC — wired link — Switch (1 Gbps)
- AP — wired link — Switch (1 Gbps)
- Server — wired link — Switch (10 Gbps)
- Switch — wired link — R1 (1 Gbps)
- R-mob — wired link — R1 (1 Gbps)
- R1 — wired link — R2 (10 Gbps · 1 ms)
- R2 — wired link — R3 (100 Gbps · 34 ms · 6,800 km)
- R3 — wired link — R4 (100 Gbps · 4 ms)
- R3 — wired link — R5 (100 Gbps · 3 ms)
- R4 — wired link — R6 (100 Gbps · 5 ms)
- R5 — wired link — R6 (100 Gbps · 4 ms)
- R5 — wired link — Switch (100 Gbps)
- Switch — wired link — Servers (100 Gbps)
- R6 — wired link — R-cp (100 Gbps · 2 ms)
- R-cp — wired link — Switch (10 Gbps)
- Switch — wired link — www.example.edu (1 Gbps)
The most compelling feature of P2P architectures is their self-scalability self-scalability Simple The system gains capacity as it gains users, because every user also serves others. Precise The property of a P2P architecture whereby each peer generates workload by requesting files but also adds service capacity to the system by distributing files to other peers. It is a direct consequence of peers being redistributors as well as consumers of bits. introduced in ch. 2 — open in glossary .
In plain words
In a P2P file-sharing application, each peer generates workload by requesting files. But each peer also adds service capacity, by distributing files to other peers.
So a new user brings a new demand and a new supply. In a client-server application a new user brings only the demand. That single difference is why the two lines in section 2.5’s graph go in such different directions.
P2P architectures are also cost effective, because they normally do not require significant server infrastructure or server upload capacity. But they are not free of trouble. The book is blunt about the price: P2P applications face challenges of security, performance and reliability, because of their highly decentralised structure.
| Client-serverthe Web, e-mail, DNS | Peer-to-peerBitTorrent | |
|---|---|---|
| Always-on host required? | ||
| Fixed, well-known address? | ||
| Do the users’ machines talk to each other? | ||
| What happens as users are added? | ||
| Infrastructure cost | ||
| Hardest part |
Cells marked ⓘ have a reason behind them — click to read it.
Click any ⓘ for the reason behind the cell.
Processes communicating
Now go one level down. What is it, exactly, that communicates?
Not programs. In the language of operating systems, the things that communicate are processes process Simple A program that is currently running inside an end system. Precise A program that is running within an end system. Processes on the same end system communicate using interprocess communication governed by the operating system; processes on different end systems communicate by exchanging messages across the computer network. introduced in ch. 2 — open in glossary . A process is a program that is running within an end system.
When two processes run on the same end system, they communicate using interprocess communication, with rules set by that end system’s operating system. That is an operating-systems topic and this book leaves it alone. What this book cares about is processes running on different hosts, possibly with different operating systems. Those communicate by exchanging messages across the computer network. A sending process creates and sends messages message Simple The packet at the application layer: what your application actually sends. Precise The application-layer packet of information, exchanged between the application-layer protocol entities running in different hosts. Written M in the encapsulation figure. introduced in ch. 1 — open in glossary into the network; a receiving process receives them and may reply.
Which one is the client?
A network application is a pair of processes sending messages to each other. For each pair, we label one the client and the other the server. With the Web, the browser is a client process and the web server is a server process. With P2P file sharing, the peer downloading the file is the client and the peer uploading it is the server.
You may have noticed a difficulty. In P2P file sharing a process both uploads and downloads, so it is both. The book settles this with a definition that depends on the session, not on the machine:
The book’s definition
In the context of a communication session between a pair of processes, the process that initiates the communication (that is, initially contacts the other process at the beginning of the session) is labeled as the client client process Simple The process that speaks first and starts the session. Precise In the context of a communication session between a pair of processes, the process that initiates the communication. That is, the one that first contacts the other process at the beginning of the session. A single process can be a client in one session and a server in another. introduced in ch. 2 — open in glossary . The process that waits to be contacted to begin the session is the server server process Simple The process that waits, and answers when it is contacted. Precise In the context of a communication session between a pair of processes, the process that waits to be contacted to begin the session. introduced in ch. 2 — open in glossary .
In plain words
Whoever speaks first is the client. That is the whole rule.
It is a label for one conversation, not a property of a machine. When peer A asks peer B for a file, A is the client and B is the server. Five seconds later, when B asks A for a different file, the labels swap.
The socket: the door of a process
Any message sent from one process to another must go through the underlying network. A process sends messages into, and receives messages from, the network through a software interface called a socket socket Simple The door of a program, through which its messages leave and enter the network. Precise The software interface between the application layer and the transport layer within a host, through which a process sends messages into, and receives messages from, the network. It is the concrete thing a program holds; the socket interface of §1.1 is the service it offers. It is also called the Application Programming Interface between the application and the network. The developer controls everything on the application side of the socket and almost nothing on the transport side. introduced in ch. 2 — open in glossary .
Everyday picture
A process is a house. Its socket is the door.
When the process wants to send a message to another process on another host, it pushes the message out through its door. It then assumes that some transport system on the other side of the door will carry the message to the door of the destination process. When the message arrives at the destination host, it passes through the receiving process’s door, and the receiving process acts on it.
Where the picture breaks: a real door is passive, and you carry things through it yourself. A socket is not — pushing a message through it hands the message to code you did not write and cannot change. The door analogy also suggests one door per house; a process can hold many sockets at once, and a busy web server holds thousands.
Here is the same idea drawn precisely. This is the book’s Figure 2.3, and the figure assumes the transport protocol underneath is TCP (Transmission Control Protocol) Transmission Control Protocol The Internet transport protocol that delivers data reliably and in order, with flow control and congestion control. introduced in ch. 1 .
A socket is the interface between the application layer and the transport layer within a host. It is also called the Application Programming Interface ( API (Application Programming Interface) Application Programming Interface The published interface through which one program can use another program's services. introduced in ch. 1 ) between the application and the network, because it is the programming interface with which network applications are built.
Where your control stops
The application developer has control of everything on the application-layer side of the socket, and almost none on the transport-layer side. There are exactly two levers:
- The choice of transport protocol — TCP (Transmission Control Protocol) Transmission Control Protocol The Internet transport protocol that delivers data reliably and in order, with flow control and congestion control. introduced in ch. 1 or UDP (User Datagram Protocol) User Datagram Protocol A simple transport protocol with no reliability, no flow control and no congestion control. introduced in ch. 1 , where a choice exists. Section 2.1.3 is about how to choose.
- Perhaps a few transport-layer parameters, such as maximum buffer size and maximum segment size. Chapter 3 covers those.
That is all. Consider what is not on the list: how lost data is retransmitted, how fast the sender is allowed to go, how the bytes are packed into segments. All of that happens below the socket. It is the operating system’s business, not yours.
This is the same relationship chapter 1 described as the socket interface socket interface Simple The set of rules a program follows to ask the Internet to deliver its data. Precise The interface that end systems provide, specifying how a program running on one end system asks the Internet infrastructure to deliver data to a specific destination program running on another end system. introduced in ch. 1 — open in glossary : the rules a program follows to ask the Internet to carry its data. The socket is the concrete object your code holds. From here on this site says socket.
Addressing processes
To send postal mail somewhere, you need an address. Likewise, for a process on one host to send packets to a process on another host, the receiving process needs an address. Two pieces of information are needed:
- the address of the host, and
- an identifier that specifies the receiving process on that host.
In the Internet the host is identified by its IP (Internet Protocol) Internet Protocol The network-layer protocol that defines the datagram format and addressing every Internet device must use. introduced in ch. 1 address. Chapter 4 discusses IP addresses in detail; for now, all you need is that an IP address is a 32-bit quantity that uniquely identifies the host.
That is not enough on its own, because a host may be running many network applications at once. The receiving process — more precisely, the receiving socket — is identified by a destination port number port number Simple A number that says which program on a host a message is meant for. Precise An identifier assigned to a socket which, together with the host’s IP address, specifies the receiving process in the destination host. Popular applications have assigned well-known port numbers: a Web server is port 80, an SMTP mail server port 25, a DNS server port 53. The full list is published by IANA. introduced in ch. 2 — open in glossary .
Somewhere in the world there is a process — a running web server program — that holds this page. To send it a message, the browser needs an address. But an address for what, exactly? Two things have to be pinned down: which host, and which program on that host.
Two numbers, not one. Step forward to watch each one narrow the search.
Read all steps as text
- The problem — Somewhere in the world there is a process — a running web server program — that holds this page. To send it a message, the browser needs an address. But an address for what, exactly? Two things have to be pinned down: which host, and which program on that host.
- First number: the IP address picks the host — The IP address 198.51.100.7 identifies one host out of all of them. It is a 32-bit quantity, which is why chapter 4 spends so long on it. The routers along the path read this number and nothing else — they have no idea a web server is involved.
- But that host runs many programs — A single host can run a web server, a mail server and a name server at the same time. Each of those is a separate process, and each has its own socket. The IP address alone cannot say which one the message is for.
- Second number: the port number picks the process — Every socket is given a port number. Popular applications have been assigned well-known ones: a web server is reached at port 80, a mail server using SMTP at port 25, a name server at port 53. IANA publishes the full list. So the browser sends to 198.51.100.7 port 80, and the operating system on the far side hands the message to the right socket.
Popular applications have been assigned specific port numbers:
| Application | Protocol | Port |
|---|---|---|
| Web | HTTP (HyperText Transfer Protocol) HyperText Transfer Protocol The application-layer protocol that requests and transfers Web documents. introduced in ch. 1 | 80 |
| SMTP (Simple Mail Transfer Protocol) Simple Mail Transfer Protocol The application-layer protocol that transfers e-mail messages. introduced in ch. 1 | 25 | |
| Name lookup | DNS (Domain Name System) Domain Name System Translates a human-friendly name such as www.ietf.org into a network address. introduced in ch. 1 | 53 |
The full list of well-known port numbers for all Internet standard protocols is published by IANA (Internet Assigned Numbers Authority) Internet Assigned Numbers Authority Coordinates the DNS root servers and publishes the well-known port numbers. introduced in ch. 2 . Chapter 3 examines port numbers properly, and section 2.7 uses them in real code — with 12000, a number chosen precisely because nothing well known claims it.
Check yourself
Check yourself
0 of 5 answered1.You are writing a new chat application. On which machines must your code run?
2.In a peer-to-peer file-sharing application, why does adding more peers not slow the system down the way adding more clients slows a server down?
3.Peer A asks peer B to send it a file. In the language of this section, which process is the client?
The labels describe one session, not the machine.
4.Lin's browser wants to reach the web server process at www.example.edu. Knowing the server's IP address 198.51.100.7 is not enough. What else is needed, and why?
5.predictLook again at the diagram of Figure 2.3. The application developer chose TCP and wants to change how lost data is retransmitted. Can they?
Trace which side of the socket each thing sits on.
What to remember
- Application code runs only on end systems. Routers and link-layer switches have no application layer, so there is nowhere in them for it to run. This is why anyone can deploy a new application without permission.
- Client-server means one always-on host with a fixed, well-known IP address, and clients that never talk to each other. Success forces you into a data centre and a large bill. Peer-to-peer uses users’ own intermittently connected machines instead. It is self-scaling: each new peer brings capacity as well as demand.
- Reaching a process needs two numbers: the IP address picks the host, the port number picks the socket on it.