Knowledge / Computer Science and Engineering / Distributed systems basics

Distributed systems basics

Computer Science and Engineering (B.E./B.Tech) · Theory and architecture · free study notes for exams, placements and interviews

In short

A distributed system is a collection of independent computers, connected by a network and without shared memory or a common clock, that cooperate to look to users like one coherent system. Everything hard about it comes from three facts: messages take unpredictable time, parts fail independently, and there is no global "now". It is a standard final-year elective (AICTE/CBCS "Distributed Systems", "Cloud Computing", "Advanced Operating Systems"), appears in GATE/UGC-NET through clocks, mutual exclusion, commit protocols and consistency, and dominates backend interviews at Indian product and services firms — UPI/NPCI-scale payment systems, Flipkart, Zomato, PhonePe, Zerodha, Razorpay, Infosys/TCS cloud teams — where "design a system that stays correct when a node dies" is the standard question.

Explained

What a distributed system is, and the models used to reason about it

Architectures, communication and middleware

Time, logical clocks and global state

Mutual exclusion, election and deadlock

Replication, consistency and the CAP theorem

Distributed transactions, commit and consensus

Distributed file systems, naming and big-data processing

Key points

Formulas and examples

Clock drift and resynchronisation: after time Δt, two clocks with drift rate ρ differ by at most 2ρ·Δt. For a maximum skew δ: Δt = δ / (2ρ). (ρ in s/s, dimensionless; δ, Δt in seconds.)
Cristian's algorithm: T_client = T_server + RTT/2, where RTT = T₁ − T₀ (client's own clock). Accuracy = ±(RTT/2 − min), min = minimum one-way delay.
Lamport clock: Li ← Li + 1 (local event); send (m, Li); on receive: Lj ← max(Lj, t) + 1.
Vector clock: Vi[i] ← Vi[i] + 1; on receive m with Vm: Vi[k] ← max(Vi[k], Vm[k]) ∀k, then Vi[i] ← Vi[i] + 1.
Quorum consistency: R + W > N and W > N/2, where N = replicas, R = read quorum, W = write quorum.
Message complexity (per critical-section entry): central = 3; Lamport = 3(n−1); Ricart–Agrawala = 2(n−1); Maekawa ≈ 3√n; token ring = 1 to ∞.
Availability of replicas: with independent node availability p and k of N needed, A = Σ (from i=k to N) C(N,i) pi (1−p)N−i. For "at least one of N": A = 1 − (1−p)N.
Byzantine and crash bounds: n ≥ 3f + 1 (Byzantine), n ≥ 2f + 1 (crash/majority quorum).

Example 1 — Clock resynchronisation interval. Two machines have quartz clocks with drift rate ρ = 2 × 10⁻⁶ s/s. The application needs clocks never more than 50 ms apart.

Example 2 — Cristian's algorithm with real numbers. A client sends a time request at T₀ = 10:00:00.000 (its clock) and the reply arrives at T₁ = 10:00:00.240. The server's timestamp in the reply is 10:00:04.000. Minimum one-way network delay is known to be 20 ms.

Example 3 — Lamport vs vector clocks on the same execution. Three processes; events: P1: a (local), then send m1 to P2. P2: b (local), receive m1 → c, then send m2 to P3. P3: d (local), then receive m2 → e. All clocks start at 0.

EventProcessLamportVector (P1,P2,P3)
aP11(1,0,0)
send m1P12(2,0,0)
bP21(0,1,0)
c = recv m1P2max(1,2)+1 = 3(2,2,0)
send m2P24(2,3,0)
dP31(0,0,1)
e = recv m2P3max(1,4)+1 = 5(2,3,2)

Example 4 — Quorum design. A Cassandra-style store in an Indian data-centre keeps N = 5 replicas of each row.

Example 5 — Mutual exclusion message cost. A system has n = 25 nodes, with 40 critical-section entries per second in total across the system.

AlgorithmMessages per entryMessages per second (40 entries/s)Entry delay
Central coordinator31202 messages (1 RTT)
Lamport3(n−1) = 722,8801 RTT
Ricart–Agrawala2(n−1) = 481,9201 RTT
Maekawa (√n = 5)≈ 3√n = 156001 RTT (2 for conflicts)
Token ring1 to 24 (avg ≈ 12.5)~500, but constant circulation0 to n−1 messages

Comparison — CP vs AP stores

CP (consistency-first)AP (availability-first)
Behaviour on partitionMinority side refuses requestsBoth sides serve, diverge
Consistency modelLinearizable / sequentialEventual / causal
Typical systemsZooKeeper, etcd, HBase, Spanner (CP with TrueTime)Cassandra, DynamoDB, Riak, CouchDB
Conflict resolutionNot needed (single order)LWW, version vectors, CRDTs
FitsLedgers, balances, locks, configCarts, feeds, session data, metrics

Where it is used

Interview questions

Common mistakes

Related topics

Operating systems: processes, threads and scheduling · Computer networks: TCP/IP and sockets · Database management systems and transactions · Cloud computing and virtualisation · Parallel computing and GPUs · Microservices and system design.

Open in the Knowledge reader →Find jobs →