Application layer models: client–server and peer-to-peer
Compare the client–server and peer-to-peer (P2P) application-layer models: definitions, pros/cons, exact derivation of file-distribution time formulas, diagrams to draw, exam-style examples and common pitfalls.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Networked applications use a model to organise who provides services and who consumes them. An engineer chooses between the client–server and peer-to-peer (P2P) models depending on scalability, fault-tolerance and cost: for example, a web server uses client–server, while large file distribution often uses P2P. Understanding both models (and hybrid choices like superpeer) is essential when designing real systems and when analysing performance in exercises and exams.
Key ideas
To draw a diagram: draw one box labelled "Server" at top centre; draw several smaller boxes below labelled "Client 1", "Client 2", ...; draw arrows from each client up to the server (label arrows "request") and arrows from server to clients (label "response"). Annotate the server with "central state/store" and a label for its upload bandwidth Us and processing capacity.
Peer-to-peer (P2P) model — an exact statement: a system where each participating node (peer) can act as both client and server; data or services are shared directly among peers without requiring a single central server (although trackers or bootstrapping servers may exist). Assumption: peers contribute resources (especially upload bandwidth) in addition to consuming them. Consequence: as more peers join, total available aggregate resource may increase — improving scalability for some workloads.
- Draw a diagram: draw many circles (peers) arranged in a ring or cloud. Draw bi-directional arrows between many pairs of peers to show direct transfers. Optionally show a small box labelled "Tracker/Bootstrap" for hybrid systems.
Pure P2P vs hybrid P2P (superpeer) — Pure P2P: no dedicated central server; every node is equal. Hybrid: some peers (superpeers) take on extra duties (indexing, relaying) to improve lookup performance. Define superpeer as a peer that performs extra coordination duties for a group of ordinary peers.
Overlay network — an abstraction: a virtual network formed by logical links between application nodes (peers or clients) that sit on top of the physical network. Example: DHT-based overlays (Chord, Kademlia) route lookups using the overlay links.
Distributed Hash Table (DHT) — exact statement: a structured overlay that maps keys to peers so that key lookup (who stores the object) can be done in O(log N) overlay hops under normal assumptions. Assumptions: nodes maintain routing tables and update them on joins/failures; the DHT provides a deterministic placement function.
Performance properties (definitions): scalability (system continues to meet performance targets as N grows), availability (fraction of time service is reachable), fault tolerance (ability to sustain component failures), latency (time for a request/response), bandwidth (bits/s available). For client–server, server bandwidth is the bottleneck; for P2P, aggregate peer bandwidth matters.
Exact law for server-limited distribution (derived later): when a single source must upload a file to N receivers and that source's upload link is the bottleneck, total distribution time grows linearly with N. For P2P, distribution time can be bounded by the slowest of several constraints (server upload, slowest peer download, and aggregate upload capacity of the system).
Security and NAT issues: P2P must often handle NAT traversal; client–server can use well-known ports and firewalls more easily. Also, decentralisation increases difficulty of access control and trust establishment.
Formulas
T_cs = (N · F) / U_s where T_cs is client–server distribution time (s), N is number of clients (dimensionless), F is file size (bits), U_s is server upload rate (bits/s). Applies when server upload is the bottleneck and server must send a full copy to each client. Derivation: the server must transmit a total of N·F bits over a link of rate U_s, so time = (N·F)/U_s.
T_p2p ≥ max( F / U_s, F / d_min, (N · F) / (U_s + Σ_i u_i) ) where T_p2p is time to distribute a file in a P2P system, d_min is the minimum peer download rate (bits/s), Σ_i u_i is sum of upload rates of all peers (bits/s). Units: seconds. This is a lower bound; actual time ≥ this because of protocol overhead. The three terms represent: server seed time, slowest-peer download time, and system total upload capacity respectively.
ServerLoad = Σ_j r_j where ServerLoad is aggregate throughput the server must provide (bits/s) and r_j are per-client request rates (bits/s). Units: bits/s. Applies for continuous-server workloads and capacity planning.
Note: Symbols used — F (file size, bits), N (number clients/peers), U_s (server upload rate, bits/s), u_i (peer i upload rate, bits/s), d_i (peer i download rate, bits/s), d_min (minimum d_i). Use SI units (bits, seconds, bits/s). Convert bytes to bits by multiplying by 8.
Worked examples
Example 1 — Numerical (classic file-distribution comparison)
Problem: A file of size F = 100 MB must be distributed to N = 50 peers. The server upload capacity is U_s = 10 Mbps, and each peer has upload capacity u = 1 Mbps. Assume each peer has download capacity d = 1 Mbps. Compute client–server distribution time and a P2P lower-bound distribution time using the standard formulas.
Step 1: convert units to bits and bits/s. F = 100 MB = 100 × 10^6 bytes = 800 × 10^6 bits. U_s = 10 Mbps = 10 × 10^6 bits/s. u = 1 Mbps = 1 × 10^6 bits/s. d = 1 Mbps = 1 × 10^6 bits/s.
Step 2: client–server time using T_cs = (N · F) / U_s.
Formula: T_cs = (50 × 800e6) / 10e6 = (40e9) / 10e6 = 4000 s.
Final: T_cs = 4000 s (≈ 66.7 minutes).
Step 3: P2P lower-bound using T_p2p ≥ max(F/U_s, F/d, N·F/(U_s + N·u)).
Compute each term:
- F / U_s = 800e6 / 10e6 = 80 s.
- F / d = 800e6 / 1e6 = 800 s.
- N·F / (U_s + N·u) = (50 × 800e6) / (10e6 + 50 × 1e6) = 40e9 / 60e6 ≈ 666.67 s. So T_p2p ≥ max(80, 800, 666.67) = 800 s. Final: T_p2p ≥ 800 s (≈ 13.3 minutes). Thus P2P is about 5× faster here because peers contribute upload bandwidth.
Example 2 — Theory / diagram question (what to draw and explain)
Question: Sketch and compare client–server and P2P overlays; explain a single point of failure and how superpeers change the model.
Model answer (what to draw):
- Client–server: draw one server box connected to many client boxes with arrows labelled request/response; annotate single point of failure and server upload U_s.
- P2P: draw peers in a cloud with many bi-directional arrows; optionally include a small bootstrap server. Annotate that any peer may fail but others can still serve; note that lookup may require multiple overlay hops.
Explain: In client–server, server failure makes service unavailable unless replication exists. In pure P2P, many failures degrade but do not make service completely unavailable; in hybrid (superpeer) architecture, failure of a superpeer affects the subgroup of peers it serves (a limited centralisation).
Common mistakes
- Assuming P2P is always faster: if peer upload capacities are tiny or peers are few, P2P may be slower or similar to client–server.
- Confusing overlay links with physical links: an overlay hop can map to many physical hops and higher latency.
- Claiming DHT guarantees O(1) lookups — the typical deterministic guarantee is O(log N) overlay hops (depending on the DHT design and failure assumptions).
- Drawing diagrams without labeling important parts (server upload, peer upload, tracker) — exam answers lose marks for missing labels.
For your exam
Typical question forms: definitions (define client–server, P2P, overlay, DHT), short notes (advantages/disadvantages), derivations (derive T_cs and the P2P lower-bound), numerical problems (compute distribution time with given F, N, U_s, u_i), and diagram explanations (draw architectures and label failure modes).
What a full-marks answer includes:
- Precise definitions (bold terms), units and assumptions stated.
- For derivations: step-by-step algebra, clear statement of each assumption (e.g., server must send full copy to each client; peers can concurrently upload parts of the file), and a final boxed formula.
- For numericals: unit conversions shown, substitutions into formula, intermediate arithmetic, and final answer with units.
- For diagrams: neat drawing, labels for components and bandwidths, and short notes explaining centralisation/fault modes.
Quick check
- In one sentence: what is the defining difference between client–server and P2P models?
- Write the client–server file-distribution time formula for N clients and explain each symbol.
- In the P2P lower bound
max(F/U_s, F/d_min, N·F/(U_s + Σ_i u_i)), what does the second term represent?
Answers: 1) Client–server uses dedicated server(s) to provide services while clients only request; P2P lets each node both provide and consume resources. 2) T_cs = (N · F) / U_s where T_cs is seconds, N is number of clients, F is file size in bits, U_s is server upload bits/s. 3) The second term F/d_min is the time for the slowest-downloading peer to obtain a full copy, limited by its minimum download capacity d_min.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?