Core CS · Computer Networks
One machine serves everyone, or everyone serves each other
Two ways to arrange who provides and who consumes. You will send one file to four laptops both ways, count what each arrangement costs, and get the honest answer to “which is better”.
Send one file to four peers, two ways →01 The idea
Somebody has to be listening first
Nothing on a network happens until one side speaks. For that to work, the other side has to already be there: a process running, bound to an address and a port, doing nothing but waiting. That waiting process is the server. The one that speaks first is the client. Every exchange you have ever made over a network has those two halves, and the whole of this lesson is about where you put them.
In the client server arrangement they live on different machines and stay there. One machine is always on, has a name in DNS that everybody can look up, and answers requests. The clients are laptops and phones that appear, ask for something, and go away. A client never has to be reachable, because it always speaks first and the reply comes back down the connection it opened. That single asymmetry explains most of what follows: why your laptop needs no fixed address, why the server needs a very fixed one, and why the server can never start the conversation.
In peer to peer every node runs both halves. It has a client part, so it can ask for what it does not have, and a server part, so it can hand out what it does. There is no machine whose job it is to be on. Peers arrive, share for a while, and leave, and the system is expected to keep working through all of it. What you gain is that every arrival brings its own storage and its own uplink. What you lose is every guarantee that came from having one place that is always there.
02 Worked example
One lecture recording, four laptops in a hostel
A 300 MB lecture recording sits on a college server whose uplink runs at 100 Mbps. Four students want it. Do the units first, because this is where these questions are lost: 300 MB is 300 × 106 bytes = 2,400 megabits, so one complete copy across a 100 Mbps link takes 2,400 Mb / 100 Mbps = 24 s. Call that one round. Everything below is counted in rounds.
The highlighted node is the entire difference between the two architectures, and it is one sentence: a laptop that has finished downloading is a machine with a copy of the file and an idle uplink. Client server cannot use it, because a client has no server part and nobody would know to ask it. Peer to peer uses it, and from that moment the number of possible sources grows instead of staying at one.
Count both. Client server needs one round per laptop, so four laptops take 4 rounds, the last one waits 4 × 24 s = 96 s, and 12 units of 100 MB each cross the server’s uplink. Peer to peer seeds one copy in round 1, then holders double: 1 holder, 2 holders, 4 holders, so it takes 3 rounds, 3 × 24 s = 72 s, and the server uploads 300 MB once. Now scale it to sixteen laptops. Client server needs 16 rounds, 16 × 24 s = 384 s. Peer to peer needs 1 + log₂16 = 5 rounds = 120 s. The gap is not a constant factor; it widens with every participant.
03 Mechanics
The eight properties an interviewer walks down
One row per property, and the row is only worth marks if you can say why. The last column is the follow-up you will get, so answer it before it is asked. Read the two middle columns as a trade, never as a winner: almost every advantage on one side is a cost on the other side of the same row.
| Property | Client server | Peer to peer | The follow-up |
|---|---|---|---|
| Who speaks first | The client, always. The server never initiates a connection to a client. | Either side. Every node has a client part and a server part running at once. | then how does a server push? It answers inside a connection the client opened first. |
| Addressing | The server needs a fixed, published address: a DNS name and a well-known port, 443 for HTTPS. |
No peer needs a fixed address. A directory or a distributed hash table hands out whoever is online now. | and the client? It needs no address anyone has to look up in advance; a temporary one it did not choose is enough, which is why it can sit behind NAT and a server usually cannot. |
| Cost | you buy the machine, the power and the bandwidth, and you pay for peak demand all year |
Nothing extra. It runs on capacity the participants already own and are already paying for. | is it really free? No: you still pay for discovery, and for the seeder that keeps rare content alive. |
| Administration | One place to patch, configure, monitor and audit. A change takes effect for everybody at once. | every node administers itself; there is no place to stand to change anything |
who upgrades the protocol? Nobody can, centrally, so peers must stay compatible with old versions for years. |
| Access control | One gate. The server authenticates you and decides per request what you may see. | no gate exists; anyone who can reach a peer can ask it for anything it holds |
so how is anything trusted? By verifying the bytes, not the sender: every piece is checked against a hash agreed in advance. |
| Backup and durability | One canonical copy, so a schedule, a retention policy and a restore test are all possible. | no canonical copy; the file exists while peers happen to hold it and vanishes when they stop |
is replication not backup? No. Many copies of a file somebody deleted is many copies of nothing. |
| As demand rises | capacity is fixed at whatever the server has, so each client’s share falls as clients arrive |
Each arrival brings an uplink, so capacity rises roughly with the number of participants. | can you not add servers? Yes, and that is what a CDN is: still client server, only more of it, and you pay for it. |
| Failure | the server is a single point of failure; it goes down and the service is gone for everyone |
No single node whose loss stops the system. Peers route around whoever left. | so P2P cannot fail? It can: a central tracker is one point, and content dies when the last holder leaves. |
Now the honest part, because pure peer to peer is rare and interviewers know it. Nearly every deployed system is a hybrid: a small central service does discovery, and the payload never touches it. That is the index server pattern. Napster was the first at scale, and it is also the cleanest warning: the transfers were peer to peer, but the index was one company’s server, and shutting that server down ended the network. Gnutella answered by removing the index entirely and paid for it by flooding every search query to its neighbours, which does not scale either. BitTorrent settled in between.
peer → tracker GET /announce?info_hash=...&peer_id=...&port=6881tracker → peer a list of ip:port for peers on this torrentpeer ↔ peer the pieces themselves, direct, in both directions -- discovery is client server. the payload is peer to peer. the tracker-- never sees one byte of the file, so it needs almost no bandwidth.-- BEP 5 adds a DHT: the peer list itself is stored across the peers,-- so a swarm can survive with no tracker at all.-- every piece is checked against a hash from the .torrent before it-- counts: SHA-1 per piece in v1, SHA-256 in v2 (BEP 52).
Lines 1 and 2 are an ordinary client server exchange over HTTP, and they are the only lines a tracker takes part in. Line 3 is where the 300 MB goes, and the tracker cannot see it, throttle it or be overloaded by it. That split is why the pattern works: the central component carries the metadata, which is tiny, and the decentralised part carries the payload, which is not. Lines 9 and 10 are what replaces the missing gate. You cannot trust a peer, so you do not have to: a peer that sends you a corrupt piece fails the hash and the piece is discarded.
05 Cheat sheet
The card to read on the morning of the interview
Nine rows. Six of them carry a rose cell marking the side that loses that row, and the rose cells fall in both columns, which is the point: there is no column that wins the table. The other three rows are facts, not verdicts.
| Question | Client server | Peer to peer |
|---|---|---|
| Who initiates | the client, every time | any peer; both roles run on every node |
| Fixed address needed | yes, for the server: DNS name plus a well-known port | no; a tracker or DHT finds whoever is online |
| Cost to run | a dedicated always-on machine and its bandwidth | the participants’ own spare capacity |
| Administration | one place to patch, configure and audit | every node on its own; no central place to change anything |
| Access control | one gate; authenticate then authorise per request | no gate; trust the hash of the content, never the sender |
| Backup | one canonical copy you can schedule and restore | no canonical copy; data lives only while peers hold it |
| As demand rises | capacity fixed; every new client gets a smaller share | capacity rises with each participant |
| Single point of failure | yes, the server; it stops and everyone stops | none in the transfer path; a tracker is still one |
| Where you meet it | HTTPS on 443, DNS on 53, IMAPS on 993, online banking | BitTorrent swarms, Bitcoin gossip on 8333, phone-to-phone Wi-Fi Direct transfers |
06 Where & why
Four systems running right now, and which way each leans
Every one of these is something you can point a tool at today. Name the system, then name which half of it is client server and which half is not, because the interesting systems are almost never all one thing.
Your browser speaks first, every time. A web server cannot decide to send you a page, because it does not know where you are until you connect. Server push exists only inside a channel the client opened first, which is exactly what WebSocket and server-sent events are for. Online banking is the same shape with the stakes turned up: one gate, one audit log, one backup.
Your device is a client of a resolver at a fixed address on port 53, and that resolver is in turn a client of the root, TLD and authoritative servers. Nothing in the chain ever calls you back. The hierarchy looks distributed, and it is, but every single hop in it is one client asking one server that was already listening.
The tracker announce is an ordinary HTTP request and gets back a list of peers. Every byte of the file then moves peer to peer, which is why a tracker for a huge swarm needs almost no bandwidth. BEP 5 spreads the peer list across the peers themselves, so a swarm can run with no tracker at all. This is the index server pattern in its most quoted form.
Every full node stores the whole chain and relays new blocks and transactions to the neighbours it is connected to. There is no address whose loss stops the network, and no operator to serve a court order on. The nearest thing to a directory is bootstrap: a brand new node finds its first few peers through DNS seed names shipped inside the software, then keeps its own address book and stops needing them. The price is paid in the other columns: every node keeps a full copy, admits no administrator, and validates everything itself because it can trust nobody.
07 Interview questions
What they actually ask
This is a first-round networking question and it is usually answered as two memorised lists. What separates candidates is naming a trade in both directions and admitting that the real system in front of you is a hybrid.
What is the client server model, in one line?
What makes a peer different from a client?
Does the server ever speak first?
Why does the client not need an address of its own?
Compare the two on cost and administration.
Which is more secure?
What happens to each one as demand rises?
Is peer to peer really free of a single point of failure?
Is BitTorrent pure peer to peer?
Email feels decentralised. Is it client server?
So which is better?
08 Practice problems
Six to work through
For each one, decide who speaks first and who has to be reachable before you decide anything else. Those two answers settle most of the rest, and getting them backwards is how a good design argument goes wrong in the first sentence.