Sources grouped here: Classical Leader Election Algorithms.pdf and Distributed Leader Election Protocols.pdf.

Core idea

A set of distributed processes must choose exactly one coordinator and make every non-faulty process agree on that choice.

1. The leader-election problem

  • Each processor eventually decides either elected/won or not elected/lost.
  • These states are irreversible.
  • In every admissible execution:
    • every processor eventually reaches one of the two states;
    • exactly one processor enters the elected state.
  • Leader election is a symmetry-breaking problem: initially similar processes must give one process a special role.

Uses

  • coordinate system activity;
  • choose a root for spanning-tree construction;
  • reconstruct a lost token in a token-ring network;
  • select a master/primary replica for a database or a distributed lock service.
Plain meaning

Several servers need one agreed “person in charge.” Two leaders can issue conflicting decisions; no leader means nobody coordinates the work.

PYQ • Semester 2025, CO1(i)(c)

A ring of fixed processes must count circulating tokens. Informally specify process actions and messages. Is a correct result possible? If not, why?

Original Semester 2025 CO1(i)(c)

Answer: Out of supplied material. The supplied leader-election lectures mention reconstructing a lost token as a use of election, but do not provide a token-counting-ring algorithm or its correctness proof.

Requirements with failures

In a group with N processes, unique IDs, eventually delivered messages, and possible failures:

  • any process may call an election;
  • a process starts at most one election at a time;
  • several processes may start simultaneously, but the outcome must still be one leader;
  • the result must not depend on who initiated it;
  • Safety: all non-faulty processes select the same eligible/best process (or Null while no result exists); never elect two leaders.
  • Liveness: each election run terminates and every non-faulty process eventually has a non-Null leader.

Usually the “best” attribute is highest ID, but it could be highest IP address, fastest CPU, most disk, etc.

PYQ • CT1 re-test 2026, Q2(a)

Define liveness in leader election. (2 marks)

Original CT1 re-test 2026 Q2(a)
Original paper

Solution: Liveness means that under the protocol’s progress assumptions, the election eventually terminates and every non-faulty process eventually knows the elected leader. An election in which all processes wait forever violates liveness.

PYQ • complete graph, synchronous rounds

CT Re-test 2022, Class Test 1 Q1 and Semester paper printed 2023, CO1: Consider a complete graph of five nodes. Describe a leader-election algorithm using synchronous rounds and count the rounds.

Original 2022 CT1 re-test Q1

Original Semester 2023 CO1 on election in a complete graph

Answer: Out of supplied material. The lectures cover ring algorithms, not a complete-graph synchronous-round election algorithm. The question requires a separate complete-graph algorithm and round analysis.

graph TD P1((P1)) --- P2((P2)) P1 --- P3((P3)) P1 --- P4((P4)) P1 --- P5((P5)) P2 --- P3 P2 --- P4 P2 --- P5 P3 --- P4 P3 --- P5 P4 --- P5

2. Ring terminology and anonymous rings

Oriented ring

Processes form a logical ring. In an oriented ring, every process consistently knows left/right (or clockwise/counter-clockwise). If messages always leave on the same numbered channel, they circulate in one direction.

assets/slide-figures/ring-network-model.png

Slide visual - oriented ring

A consistent channel direction lets every candidate message circulate around the same logical ring.

Anonymous, uniform, and non-uniform

  • Anonymous ring: processors have no unique identifiers.
  • Uniform algorithm: does not use ring size; the same state machine works for every ring size.
  • Non-uniform algorithm: may use ring size; for each size n, all processes use a state machine tailored to n.

Impossibility in anonymous rings

There is no deterministic leader-election algorithm for anonymous rings, even when the algorithm knows n and the model is synchronous.

Why:

  1. All anonymous processes begin in the same state and send the same messages.
  2. They receive the same messages, take the same state transition, and remain indistinguishable in every round.
  3. If one enters elected state, all do - violating safety. If none ever enters, liveness fails.

Because this impossibility holds in the stronger non-uniform synchronous setting, it also holds for weaker uniform and asynchronous settings.

Exam trap: anonymous rings

Unique IDs (or some other asymmetry) are necessary to deterministically elect one process in an anonymous symmetric ring.

PYQ • CT1 2024, Q3(b) and CT1 re-test 2026, Q2(b)

Define uniform, non-uniform, anonymous, non-anonymous, oriented, and non-oriented rings.

Original CT1 2024 Q3(b)

Original CT1 re-test 2026 Q2(b)
2026 re-test paper · 3 marks

Answer:

  1. Anonymous: no unique process identifiers. Non-anonymous: each process has a unique ID.
  2. Uniform: one state machine/algorithm works for every ring size and does not use .
  3. Non-uniform: the algorithm may depend on ring size; a different state machine may be used for each .
  4. Oriented: all processes agree on left/right or clockwise/counter-clockwise.
  5. Non-oriented: no common direction is available; a process cannot assume its local “left” agrees with another process’s left.

3. Classical ring algorithm: LCR / O(n^2) messages

Assume a unidirectional oriented ring with unique IDs. Each process sends its own ID left/clockwise.

When a process with own ID id receives candidate ID j:

  • if j > id, forward j; this process has lost;
  • if j = id, its own ID has completed the ring, so elect itself;
  • if j < id, discard j.

The highest ID cannot be discarded, travels around the full ring, and is elected. This works in synchronous and asynchronous models.

PYQ — CT1 2026, Q4: LCR trace

Original CT1 2026 Q4 with the ring IDs and all four parts

In the clockwise ring , trace LCR, count messages by identifier and in total, and explain the effect of the arrangement.
Answer
  1. The final 3 repeats the first node to close the ring; the eight unique IDs are . Each node initially sends its own ID clockwise. A node forwards a larger ID and discards a smaller one.
  2. The message counts by originating ID are: , , , , , , , . Each count includes the initial send and the message on the hop where the ID is discarded or returns.
  3. Total election messages are 20. ID 8 returns to its origin and elects that node; any later leader-announcement messages are separate.
  4. A nearby larger ID discards a candidate quickly, while descending runs let candidates travel farther. This changes the total from linear in a favorable arrangement to quadratic in the worst case.

Analysis

  • Correctness: elects the processor with largest ID.

  • Time: O(n) message hops/rounds for the maximum ID to cross the ring.

  • Messages: worst arrangement is decreasing IDs around the direction of travel. The largest sends n, second largest n-1, and so on:

Smaller IDs are stopped by a larger ID; the idea behind better algorithms is to stop them much earlier.

assets/slide-figures/ring-election-example.png

Slide visual - LCR election example

The candidate with the greatest ID keeps travelling; a smaller candidate is replaced or discarded when it meets a larger ID.

PYQ — Semester paper printed 2023 (file named 2022), CO1

Original Semester 2023 alternative CO1 on ring election and MIS

Question

Develop and analyse a distributed algorithm for leader election in a ring of nodes. Give a brief correctness outline.

Answer
  1. Use the LCR algorithm on an oriented, unidirectional ring with unique IDs.
  2. Each process sends its own ID clockwise.
  3. On receiving candidate , a process forwards it if , discards it if , and elects itself if .
  4. The maximum ID is never discarded because no greater ID exists.
  5. It completes a full ring traversal and returns to its origin, so that process elects itself.
  6. Every smaller ID is stopped by a larger ID; therefore no second leader can be elected.
  7. Time complexity is ; worst-case messages are .
flowchart LR P1["P1: ID 12"] --> P2["P2: ID 3"] --> P3["P3: ID 80"] --> P4["P4: ID 5"] --> P1

PYQ — Semester 2024, CO1(c)

Original Semester 2024 CO1(c)

Question

Discuss the number of messages in a leader-election algorithm for a ring network.

Answer
  1. In LCR, the largest ID travels all hops; smaller IDs travel until a larger ID discards them.
  2. In the worst decreasing-ID arrangement, the total is messages.
  3. Hirschberg-Sinclair reduces the worst case to by doubling the probe radius while reducing the number of surviving candidates at later phases.
  4. In asynchronous rings of unknown size, is a lower bound, so HS is asymptotically optimal for the stated model.

PYQ — Semester 2025, CO2(iii)(c)

Original Semester 2025 CO2(iii)(c) on fairness

Question

Describe the ring algorithm for leader election. How does it ensure fairness?

Answer
  1. Each process starts with its unique ID and sends it in the common ring direction.
  2. A process forwards a received ID only when it is greater than its own; otherwise it discards the candidate.
  3. A process receives its own ID back only when no larger ID exists, and it then becomes leader.
  4. Every process has an initial opportunity to participate, and a candidate loses only to a larger ID.
  5. The highest eligible ID wins. Every process can participate, but repeated elections with the same participants and IDs elect the same leader.

4. Hirschberg-Sinclair (HS): O(n log n) messages

HS works in a bidirectional ring. Define the k-neighbourhood of process p as processes within distance k in either direction; it contains 2k+1 processes.

The algorithm has phases 0, 1, 2, ....

  • In phase k, a survivor must have the largest ID in its 2^k-neighbourhood.
  • Only phase-k winners enter phase k+1.
  • Each winner probes both directions to distance 2^k.
  • A node with larger ID swallows the probe.
  • If a probe reaches its distance limit unswallowed, the boundary node returns a reply.
  • A process receiving replies from both sides advances to the next phase.
  • If a process receives a probe carrying its own ID, it has crossed the full ring; it elects itself and sends a termination message.

Phase 0

Every process sends its ID to both immediate neighbours. A neighbour swallows a smaller ID; otherwise it sends a reply. Two replies make the initiator a phase-0 winner.

assets/slide-figures/hirschberg-sinclair-probes.png

Slide visual - HS probe/reply pattern

A surviving process sends probes in both directions. Later phases reach further, while fewer processes survive to send them.

Why it improves message complexity

  • Search radius doubles each phase, but the number of surviving candidates falls about by half.
  • A phase-k probe travels at most 2^k; one candidate starts at most 4·2^k probe/reply messages in both directions.
  • At most n/(2^k+1) candidates can be phase-k-1 winners when packed densely.
  • There are about log2(n) phases (more precisely, max phase ceil(log2(n-1))+1).
  • Total message count is O(n log n); termination adds only O(n).

Correctness is the same principle as LCR: no smaller ID defeats a larger ID, and the unique maximum eventually remains.

HS in one sentence

Double the search radius; roughly halve the survivors. That trade-off yields messages instead of LCR’s worst case.

Lower bound and overview

  • Any leader-election algorithm for an asynchronous ring of unknown size requires messages, including a unidirectional ring.
  • LCR and HS are comparison-based: they use only <, >, and = on IDs.
  • In synchronous rings, O(n) messages are possible under certain conditions if general arithmetic/non-comparison operations are allowed and unbounded time is acceptable.
  • Thus the asymptotic bounds presented are tight:
    • asynchronous ring: ;
    • synchronous ring: under stated special conditions, otherwise .

5. Fault-prone ring-election protocol

This protocol assumes a logical unidirectional ring. An election message carries id:attribute.

Protocol

  1. A process that discovers coordinator failure initiates Election(own-id:attr).
  2. On receiving an election message, process p_i compares received attribute with its own.
    • If received value is greater, forward it.
    • If received value is smaller and p_i has not already forwarded an election message, overwrite it with p_i’s own ID/attribute and forward it.
  3. When a process receives its own id:attr back, it has the greatest attribute and becomes coordinator.
  4. It sends Elected(id) around the ring.
  5. Every receiver stores that ID in its elected variable and forwards it unless it is the new coordinator.

Costs without failures

  • Worst case: initiator is successor of the future leader.
    • N-1 hops for election message to reach the best process;
    • N hops for that winning election message to complete the ring;
    • N hops for the elected announcement.
    • Total: 3N-1 messages and message-transmission times.
  • Best case: the future leader initiates; 2N messages and transmission times.
  • With simultaneous initiators, cache initiator IDs and suppress messages from lower-ID initiators. Only the highest-ID initiator’s run completes.

PYQ — CT1 2024, Q3(c) and CT1 re-test 2026, Q2(c)

Original CT1 2024 Q3(c)

Original CT1 re-test 2026 Q2(c)

Question

Illustrate best- and worst-case Ring Election Protocol scenarios and determine message complexity in each.
2026 re-test paper · 3 marks

Answer

Assume one initiator, a functioning ring of processes, and one message per hop. Count both the election and the announcement.

  1. Best case: the process with the highest election attribute starts the election.
  2. Its Election message completes one ring traversal, then its Elected announcement completes one more traversal.
  3. Therefore best-case complexity is messages.
  4. Worst case: the initiator is immediately after the eventual leader in the message direction.
  5. The candidate message needs hops to reach the leader, then the unchanged winning Election message needs hops to complete the ring, and Elected needs another hops.
  6. Therefore worst-case complexity is messages.

Result: Both cases are . For example, with five processes the best case uses transmissions and the worst case uses .

flowchart LR A["Initiator"] --> B["..."] --> L["Highest ID / leader"] --> C["..."] --> A

PYQ — Semester 2025, CO2(iii)(a)

Original Semester 2025 CO2(iii)(a) on message counts

Question

In a 10-process system, ID 2 initiates election. How many messages are exchanged in the worst case before the new leader is elected?

Answer
  1. The paper leaves the ring protocol unspecified. Using the single-initiator protocol in this section, the worst case has hops to reach the winning process and more for its identifier to return.
  2. For , that is 19 transmissions up to the point where the winner elects itself.
  3. Announcing the result along the complete ring costs another 10 transmissions, so the total including the announcement is 29. State which protocol and stopping point you assume.

Failure problem

If a process fails after an election starts, an Election or Elected message can circulate or wait forever. Liveness fails.

Two attempted repairs:

  • Predecessor/successor repair: when a node times out waiting for an elected message, it starts a new election. This can fail if that node and successive predecessors also fail.
  • Failure-detector repair: any receiver detects failure and starts a new run. But detectors may be incomplete (miss failure - safety issue in the slide’s presentation) or inaccurate (mistake a live node for failed - endless elections, liveness issue).

The deeper lesson is that, in a purely asynchronous system, timeouts cannot guarantee termination because a slow message is indistinguishable from a failed process.

Failure-detector trap

A timeout is evidence of delay or failure, not proof of either. This is why simple election protocols cannot guarantee liveness in a fully asynchronous model.

PYQ • Semester 2025, CO2(i)(d)

During an election, if the highest-ID process fails before declaring itself leader, how does the algorithm ensure a new leader is elected?

Original Semester 2025 CO2(i)(d)

Answer:

  1. The failure must be detected by a predecessor/successor timeout or a failure detector.
  2. A process then starts a new Election message so that the highest remaining non-faulty process can replace the failed candidate.
  3. A predecessor can re-initiate if it receives Election but times out waiting for Elected, or after an Elected message when the coordinator later fails.
  4. A failure detector may be incomplete (miss a real failure) or inaccurate (suspect a live process). Thus simple timeout protocols cannot guarantee termination in a fully asynchronous system, where slow and failed look alike.

6. Why leader election is hard: relation to consensus

Leader election is consensus-like. If processes could elect a leader, they could use a deterministic property of its ID (for example, the last bit) as a consensus decision. Since deterministic consensus is impossible in the fully asynchronous crash-failure model under the usual assumptions, reliable election is also hard there.

Industry therefore uses consensus-like protocols such as Paxos/Zab rather than relying only on simple timeout ring algorithms.

7. Bully algorithm

Assumptions: all processes know every other process ID; a higher ID has higher priority.

Protocol

  1. A process detects coordinator failure.
  2. If it knows it has the highest ID, it declares itself coordinator and sends Coordinator to all lower-ID processes.
  3. Otherwise it sends Election only to processes with higher IDs.
  4. If no OK arrives before timeout, it becomes leader and notifies lower IDs.
  5. If an OK arrives, a higher non-faulty process exists. The sender waits for a Coordinator message; if none arrives before another timeout, it retries.
  6. A process receiving Election replies OK and starts its own election unless it already has.

assets/slide-figures/bully-election-example.png

Slide visual - Bully election

The highest non-faulty process ultimately announces itself as coordinator after higher-ID candidates either respond or time out.

Why “bully”?

The highest surviving ID wins by forcing lower IDs to defer.

Time and message analysis

  • If failures stop, the algorithm eventually elects a leader only when timeouts are chosen well enough for the model.
  • With no failures during the run, worst completion is described as five message-transmission times: election from lowest to next-highest, reply, election to highest, timeout, then coordinator announcement.
  • Worst message count: if lowest ID detects failure, election messages sum to (N-1)+(N-2)+...+1 = N(N-1)/2 = O(N^2).
  • Best case: second-highest process detects failure, sends coordinator announcements to lower processes; completion is one transmission time in the slide model.
  • In a truly asynchronous system, the protocol may never terminate; in a synchronous model with known worst-case latency/processing time, timeouts can support liveness.

8. Consensus, Paxos, Chubby, and ZooKeeper

Paxos essentials

Paxos reaches agreement on one value/state across distributed nodes even if some fail or are unreachable.

assets/slide-figures/paxos-in-action.png

Slide visual - Paxos in action

A proposer first obtains promises from a quorum, then asks it to accept a value; a majority acceptance chooses the value.

  • Proposers initiate values.
  • Acceptors promise/accept/reject under Paxos rules.
  • Learners learn the value chosen; they do not decide it.
  • A quorum is the set needed to accept a proposal, normally a majority.

Simple 3-node example:

  1. Proposer A chooses proposal number 1 and sends Prepare(1) to B and C.
  2. B and C return Promise(1) because no higher proposal is known.
  3. After a majority of promises, A sends Propose(X).
  4. B and C reply Accepted(X).
  5. Two out of three is a majority, so X is chosen.

Advantages: tolerates some failures while a majority remains, avoids a permanent single point of failure because any node may propose, and preserves eventual agreement/consistency.

Google Chubby

  • Chubby is a locking service used by Google systems such as Bigtable and Megastore.
  • A replica group must keep a master/leader elected.
  • Potential leaders seek votes; each server votes for at most one candidate; a majority winner becomes master and informs everyone.

Apache ZooKeeper

  • ZooKeeper server ensemble: servers elect a candidate with up-to-date transaction history. In Zab (ZooKeeper Atomic Broadcast), the candidate synchronizes its followers and becomes active after a quorum acknowledges the new leadership. If activation loses quorum, the servers retry the election. Apache ZooKeeper internals
  • Application election using ZooKeeper: each candidate creates an ephemeral sequential znode. The smallest sequence number wins and every other candidate watches its immediate predecessor in sequence order. When a session expires its znode is removed. The notified candidate rechecks its position and leads if it is now first. Watching predecessors avoids waking every contender when the leader disappears. Apache ZooKeeper leader-election recipe
PYQ • CT1 2024, Q3(d) and CT1 re-test 2026, Q2(d)

How does ZooKeeper handle failures during the leader-election process?

Original CT1 2024 Q3(d)

Original CT1 re-test 2026 Q2(d)
2026 re-test paper · 2 marks

Solution: For the ensemble, a replacement leader needs a quorum of synchronized servers to become active. If that quorum is lost during activation, the servers go back to election. For the application recipe, a failed leader’s ephemeral znode disappears when its session expires. The next candidate is notified by its predecessor watch and takes over after checking that it has the smallest remaining sequence number.

9. Final exam summary

  • Anonymous symmetric rings cannot deterministically elect one leader.
  • With unique IDs, LCR is simple but Θ(n^2) messages; HS is Θ(n log n) messages.
  • Failure detection/timeouts are the hard part: they cannot distinguish slowness from failure in a fully asynchronous system.
  • Ring and bully algorithms are useful teaching models but are failure-prone.
  • Production systems use consensus-based leader election, majority quorums, and failure-handling protocols such as Paxos/Zab.
30-second revision

Anonymous ring: impossible.
LCR: simplest, messages.
HS: messages.
Production: consensus/majority quorum (Paxos or Zab).