Messages, Models, and Agreement

Introduction to
Distributed Algorithms

Debasish Pattanayak

Assistant Professor, IIT Indore

From your phone to the cloud — making many computers act as one

Why should you care?

You already use these every day

💸UPI paymentsUnified Payments Interface: money moves correctly across banks that never share one database.
💬WhatsAppA message reaches everyone in a group, in order, across continents.
🔎Google SearchOne query is answered by thousands of machines working together.
🎬CDNsContent delivery networks stream video from a server near you, not one giant computer.
🎮Online gamesMany players see a single, consistent game world in real time.
⛓️BlockchainsStrangers who trust no one still agree on one shared ledger.
The common pattern

What do these systems have in common?

Many computers

Work is spread across machines that do not share one memory.

Only messages

Each machine learns about the world by receiving messages from others.

One outcome

Somehow they must still agree, coordinate, or elect one process to act.

That tension — local communication, global coordination — is the heart of distributed algorithms.

Interactive pause Think break 1

Which agreement is hiding here?

Pick one system from the previous slide. Before algorithms, name the one fact that many machines must agree on.

Core

For UPI, WhatsApp, search, games, or blockchains: what is the single shared outcome the users expect?

Failure mode

What could go wrong if two machines temporarily believe different versions of that outcome?

Modeling move

Which details would you throw away to get a clean graph-and-message model, and which details feel too important to ignore?

Stretch

If the system is allowed to be briefly inconsistent, what extra rule must eventually repair the disagreement?

The same real system may need broadcast, leader election, ordering, and fault tolerance at different layers.

Today's plan

1Centralized vs. distributedwhat changes
2The model — nodes & messageshow we describe it
3Measuring costtime & messages
4Talking to everyone — broadcastflooding & BFS trees
5Choosing a leader — token ringIDs break symmetry
6When nodes can liea hard problem to end on
1

Centralized vs. Distributed

The whole subject begins with one structural choice.

§1Two ways to organize computers
CENTRALIZED DISTRIBUTED server one point of failure · simple to reason about no boss · survives failures · harder to coordinate

Left: everyone talks to one server. Right: peers talk to each other directly.

§1What actually changes

Centralized system

One machine holds the truth; everyone asks it. There is a global clock and a single memory — the easy world.

But: if it's down, everything stops. It can't grow past one machine, and it can't be everywhere at once.

Distributed system

Many machines, each with its own memory and clock, cooperating only by sending messages.

Gains: scale, fault-tolerance, closeness to users. Price: no one sees the whole picture — coordination becomes the hard part.

The big idea of this lecture

Once you give up a shared clock and shared memory, even simple-sounding tasks — “tell everyone,” “pick one leader” — need real algorithms. That's what we'll build today.

§1Interactive pause Think break 2

Does a leader make it centralized?

Suppose a distributed system first elects one coordinator, then everyone follows that coordinator for the next minute.

Core

Is the system now centralized, distributed, or temporarily both? What would you count as the algorithmic boundary?

Trade-off

What do we gain by having one coordinator, and what new failure point have we created?

Repair

If the coordinator crashes, what information must survive so the rest can choose a replacement?

Stretch

Can the coordinator be a role rather than a machine? How would that change your proof obligations?

Many practical systems are distributed precisely because the identity of the "central" actor can change.

2

The Model

A simple, precise picture of a distributed system: nodes and messages.

§2How we draw a distributed system
one-hop neighbourhood of v x y z w a b c d e v inside: nodes connected to v outside: not neighbours of v

A network is a graph: dots = computers, lines = links.

The graph abstraction

A distributed network is an undirected graph G = (V, E).

Nodes are processes; edges are communication links. We write n = |V| and m = |E|.

Messages travel only along edges, so information spreads one hop at a time.

§2The local view

What does one node know?

Its own state

Process v knows its identifier id(v), its incident links, and the messages it has received so far.

Not the whole network

It does not start with the full graph G, and there is no shared memory to inspect.

Useful notation

dist(u,v) is hop-distance. The diameter D is the largest such distance in the graph.

Why identifiers matter

Unique identifiers (IDs) come from a totally ordered set and fit in O(log n) bits. They are the only thing distinguishing otherwise-identical nodes — a theme that returns in leader election.

§2Interactive pause Think break 3

What can one node distinguish?

You are node v. After two synchronous rounds, you know everything within distance two, but nothing beyond that frontier.

Core

Draw two different graphs whose radius-2 view around v is identical. What decision must v make the same way in both?

Cost

If a decision depends on a node at distance d, what lower bound on rounds follows immediately?

IDs

Do unique IDs help v see farther, or only help it compare names inside the part it has already seen?

Stretch

Can two graphs have the same radius-t view around every node but require different global answers?

This is the seed of indistinguishability proofs: same local view forces same local behaviour.

§2The life of a node — and how time works

One synchronous round

Time advances in rounds t = 1, 2, …. In each round every process simultaneously (i) sends a message on each incident link, (ii) receives that round's incoming messages, (iii) updates its state by a transition function.

A message sent in round t arrives by round t+1. (Real systems are asynchronous; rounds just keep the ideas clean.)

Configurations & executions

A configuration is the tuple of all local states; an execution is the sequence C0, C1, C2, … the round function produces.

Local computation is unbounded and free — only communication is counted.

§2Interactive pause Think break 4

What if the round clock disappears?

Now messages still arrive eventually, but with unpredictable delays; a process cannot tell "slow" from "silent".

Core

Which line of the synchronous-round model breaks first? Sending, receiving, or deciding when to halt?

Timeout trap

If no message arrives for one second, did a neighbour crash, or is the network just slow?

Algorithm design

What extra mechanism might replace rounds: acknowledgements, clocks, failure detectors, or none of these?

Stretch

Which theorem or impossibility result would you expect to become harder once timing is unreliable?

Synchronous rounds are a teaching scaffold; removing them turns timing into part of the problem.

§2What changes in the analysis

A different bottleneck

Contrast — NP = nondeterministic polynomial time

There the scarce resource is time, and computation is the adversary. Here computation is free — the bottleneck is information: what a node can possibly know from local messages alone.

Mental model

A distributed lower bound usually says: after this many rounds, some node still cannot have learned enough to distinguish two possible worlds.

3

Measuring Cost

Two simple questions we ask of every distributed algorithm.

§3The two yardsticks

How good is an algorithm?

Round (time) complexity T(n)

Rounds until every process has halted, worst-case over all inputs (id assignments, graphs in the class). When information must cross the whole network, this is bounded below by the diameter D — the largest hop-distance between any two nodes.

Message complexity M(n)

Total messages sent over the whole execution, again worst-case. (Refine to bit complexity when message size matters.)

Same O, Θ, Ω asymptotics as always — but now in two resources that can trade off against each other.

§3Lower-bound mindset

Centralized vs. distributed analysis

Same asymptotics, different bottleneck

In a centralized algorithm, the usual question is how many steps or comparisons one machine needs. In a distributed algorithm, the scarce resource is communication: what information can reach which node, and how many rounds or messages it takes.

The technique rhymes: adversary and indistinguishability arguments. We'll meet one on the ring.

4

Talking to Everyone

Concept ① — Broadcast. One node has news; everyone must hear it.

§4The simplest possible idea

Broadcast by flooding

The idea

The source tells its neighbours. The first time a node hears M, it relays to all other neighbours, then goes silent — gossip through a crowd.

Flooding — at every node v if v is the source: send M to all neighbours; halt. on first receipt of M from neighbour p: parent(v) ← p # a tree edge send M to all neighbours except p ignore every later copy of M

First receipt sets the parent; later copies are ignored. Watch it run — press ▶ next.

§4Animated example — press play

Flooding, round by round

s a b c d e round 0
§4Interactive pause Think break 5

What if messages collide?

Now that flooding's relay rule is clear, test the channel assumption: each link must actually deliver the messages sent on it.

Core

If two neighbours transmit to the same receiver at once and both messages are lost, does flooding still guarantee broadcast?

Patch

Would random backoff, acknowledgements, or a fixed schedule restore the proof? Which one changes time complexity most?

Accounting

If every failed transmission is counted as a message attempt, what happens to the clean 2m bound?

Stretch

Can you define a collision model precise enough that the theorem statement becomes true or false, not vague?

Many "obvious" algorithms depend on hidden channel assumptions.

§4What we just saw — stated precisely
Proposition

Synchronous flooding from s reaches every node, finishing in exactly ecc(s) rounds — the distance to the farthest node, at most the diameter D — and sending at most 2m messages. The parent pointers form a BFS (breadth-first search) tree rooted at s.

Proof sketch

Induction on d: a node at distance d from s first receives M in round d — a shortest path delivers it by round d, and nothing is faster since each hop costs one round. The last node sits at distance ecc(s). Each edge carries M at most once per direction ⇒ ≤ 2m messages.

§4Interactive pause Think break 6

How fragile is flooding?

Change exactly one assumption in the proposition and decide whether the statement survives.

Lost message

One message may be lost, but processes do not know which one. What is the smallest repair that guarantees delivery?

Duplicate message

The network may duplicate messages. Does the "first receipt sets parent" rule still produce a tree?

Finite buffers

If each node can store only one unseen message at a time, can flooding overload a high-degree node?

Stretch

Which assumption affects correctness, and which only affects the cost bound?

A theorem is always a theorem about a model; changing the model changes the contract.

§4Message count intuition

Why 2m, not n−1?

Remark

The spanning tree informs all n nodes with only n−1 messages. Every other message is a duplicate — a copy arriving where the news already reached.

Counting both directions of every edge gives the clean bound 2m.

Broadcast is cheap. Electing one leader is where locality starts to bite.

5

Choosing a Leader

Concept ② — Leader election. The network must single out exactly one node.

§5The problem, and a catch

The problem

Each process has an output variable. In the final configuration exactly one process outputs leader; all others output non-leader.

Why bother? A leader becomes the coordinator — it holds the lock, sequences events, or starts the next phase. Many protocols begin by electing one.

We take the canonical setting: a ring of n nodes with unique IDs.

Why IDs are essential

On a ring all nodes are structurally identical. Without distinct names, a deterministic algorithm cannot break the tie — we'll prove this at the end of the section.

Unique IDs supply the asymmetry; the algorithm only exploits it.

§5The algorithm, precisely
LCR = Le Lann–Chang–Roberts — unidirectional ring init: send id(v) clockwise. on receiving value m: if m > id(v): forward m # larger survives if m < id(v): discard m # smaller dies if m = id(v): output leader # my id came home

We analyze LCR synchronously for clarity; Chang–Roberts originally runs asynchronously, with the same message counts.

§5Correctness proof

Why the maximum ID is the only survivor

Lemma (correctness)

Let v* = arg max id. Then exactly v* outputs leader.

Survival

A token m is discarded at the first node whose id exceeds it. Since id(v*) is maximum, its token is never discarded.

Election

The maximum token is forwarded n times and returns to v*, which sees m = id(v*) and elects. Every other token dies before completing the lap.

§5Fully animated — token-based leader election

The biggest ID wins the ring

Press ▶ Play — or Step ▶ to advance round by round.

§5Interactive pause Think break 7

What if the ring is not oriented?

LCR has now used the phrase "send clockwise" as a real algorithmic assumption. Suppose neighbouring nodes may name their two ports inconsistently.

Core

Can the exact LCR code still run? Where does the phrase send clockwise become ambiguous?

Adapt

Try sending each ID in both directions. What new problem appears when the same ID returns from two sides?

Orientation first

Could leader election itself be used to orient the ring afterward? What circularity does that reveal?

Stretch

With unique IDs, is unoriented leader election impossible, or just more expensive and more delicate?

Orientation is not a cosmetic detail; it is part of the distributed input.

§5Cost analysis

Counting messages on the ring

Time

Θ(n) rounds — the winning token needs n hops to close the lap.

Messages — worst case

Θ(n²). Adversarial input: IDs decreasing along the travel direction, so the token from the k-th node survives k hops — total 1+2+⋯+n = n(n+1)/2.

Messages — average

Θ(n log n) over uniformly random ID orderings (expected total ≈ n·Hn). We counted 15 in the demo.

§5Interactive pause Think break 8

Can we beat LCR's message cost?

LCR wastes messages because many small IDs travel several hops before a larger ID kills them.

Core

What local evidence tells a process that its own ID is too small to keep competing?

Design idea

What if nodes explore in phases of length 1, 2, 4, 8, ... before continuing? How might that save messages?

Lower bound

Even with clever phases, why should every "region" of the ring need to reveal at least one strong candidate?

Stretch

Which algorithms are ruled out by the comparison-based lower bound, and which escape by using more than comparisons?

The jump from quadratic to n log n comes from killing hopeless candidates earlier.

§5How good can leader election get?

The tight bound on rings

Theorem — a matching lower bound

Every comparison-based ring leader-election algorithm sends Ω(n log n) messages in the worst case (Frederickson–Lynch 1987; cf. Burns 1980 for asynchronous rings).

Hirschberg–Sinclair (1980) attains O(n log n), so the bound is tight.

§5Why the IDs were not optional
Lemma (Angluin 1980)

No deterministic algorithm elects a leader on an anonymous ring — even synchronous, even with n known to all.

Proof

Induction on the round t. All nodes start in identical states and run identical code; by the ring's symmetry they receive identical messages, so after every round they remain in identical states. If one node ever outputs leader, all do at once — never exactly one.

An indistinguishability argument

Same shape as the selection lower bounds: exhibit executions a node cannot tell apart, forcing identical behaviour. Here symmetry itself is the adversary.

Two escape hatches: unique IDs (what LCR uses) or randomization — break symmetry with high probability.

§5Interactive pause Think break 9

How else can symmetry be broken?

The anonymous-ring proof blocks deterministic algorithms because identical nodes stay identical forever.

Random bits

If each node privately flips coins, are the states still forced to remain identical?

Advice

What if all nodes know n, a common orientation, or a distinguished edge? Which of these actually breaks symmetry?

Probability

Would you accept an algorithm that elects exactly one leader with probability at least 1 - 1/n?

Stretch

How would the specification change if "eventually one leader with high probability" replaced deterministic certainty?

Impossibility results often point to the exact extra power needed to escape them.

6

When Nodes Can Lie

So far everyone was honest. One last problem — to leave you thinking.

§6A famous puzzle
enemy city G1 G2 G3 traitor G4 G5 G6 “attack” “retreat”

A traitor (coral) can tell different generals different things.

Byzantine Generals (Lamport–Shostak–Pease 1982)

n processes; up to f are Byzantine — arbitrarily faulty, even malicious. A commander holds a value x ∈ {attack, retreat} and sends orders; every correct process must decide.

§6Agreement requirements

What must the correct nodes guarantee?

Agreement

All correct processes decide the same value, no matter how the faulty processes behave.

Validity

If the commander is correct, every correct process decides the commander's value x.

For which n, f is this possible? That is where the next lecture begins.

§6Interactive pause Think break 10

How many liars can agreement survive?

Try the smallest nontrivial case: one Byzantine process, and everyone else follows the protocol.

n = 3, f = 1

Can two honest processes always tell whether the commander lied, or whether the other lieutenant is lying about the command?

n = 4, f = 1

What extra cross-check becomes possible when there are three honest processes instead of two?

Rule guess

Based on these cases, guess a threshold relating n and f.

Stretch

Which assumption would change the threshold: digital signatures, synchrony, private channels, or authenticated sender IDs?

This is the gateway to Byzantine agreement: the model decides what "trust" means.

§6Where this leads

The honest truth about lying nodes

The answer is surprising

Whether agreement is even possible turns on n versus the number of liars f — sometimes it simply cannot be done. The proofs are, again, indistinguishability arguments. (Next lecture.)

It's everywhere — and verified

Behind blockchains, avionics, and fault-tolerant databases. Proving such protocols correct is a prime target for model checking (Govind's lecture).

You now have the tools

Graph model, rounds, two-resource complexity, broadcast, leader election, and one impossibility proof — enough to read on.

Three ideas to keep: a precise model, broadcast, and leader election — and the habit of asking “is this even possible?”

Many computers, no shared memory—
only messages, and they agree.

Thank you. Questions?

Debasish Pattanayak · IIT Indore · drdebmath.github.io