Distributed Consensus and the Raft Algorithm

Concepts of Programming Languages

Sebastian Macke

Rosenheim Technical University

About this Lecture: Some Thoughts

2

Distributed Programming

Terms are not always used consistently.

3

4

The two general problem

5

Discussion: How would you solve the problem?

Three armies, each led by a general, plan to attack a fortified city. The armies may arrive at different times to surround the city, and none of the generals can be certain whether all the armies will arrive at all. Consequently, they have not appointed a single leader.
For the attack to succeed, at least two armies must strike simultaneously. Therefore, the generals need to coordinate and agree on a precise time to launch the attack. They can only communicate by sending messengers.

6

Algorithms under ideal conditions

Reliable communication and all leaders are present
- Just number the armies 0, 1, 2. Army 0 is the leader per definition.
- It sends the time to attack to 1 and 2.

Unreliable communication and all leaders are present
Not solvable, but can be approximated by a two phase commit
- Just number the armies 0, 1, 2. Army 0 is the leader per definition.
- Leader 0 sends the time to attack to 1 and 2.
- They confirm back.
- After receiving both confirmations, army 0 sends a final go message.

7

What is Distributed Consensus?

The consensus problem requires agreement among a number of processes on a single data value.
Distributed consensus protocols can be used for distributed databases which should stay consistent:

8

The CAP Theorem

In a distributed system the following requirements can be met:

Pick Two: Only two requirements can be met -> CP, AP are typical (CA does not exists)

Availability,Partition Tolerance = DNS (Domain Name System)
Consistency,Partition Tolerance = Cash Machine

9

Securing C and P

10

Two Phase Commit

Phases:

This is equivalent with two round trips in the two general problem.

11

What is Raft?

12

Who uses Raft?

13

The Raft Algorithm

14

Raft in Action

15

The Raft State Model

16

Implementing Raft with Go

The most prominent implementation is the Raft implementation of Etcd (Part of Kubernetes)

This implementation is highly optimized and abstracts from the Raft paper

Other implementations

17

Is it possible to build your own Raft implementation?

Requirements and Decisions

18

Interesting Parts

19

Exercise 8.2: Be Creative!

Three armies, each led by a general, plan to attack a fortified city. The armies may arrive at different times to surround the city, and none of the generals can be certain whether all the armies will arrive at all. Consequently, they have not appointed a single leader.
For the attack to succeed, at least two armies must strike simultaneously. Therefore, the generals need to coordinate and agree on a precise time to launch the attack.
To achieve this, they decide to use a simplified version of the Raft algorithm.

20

Summary

21

Thank you

Sebastian Macke

Rosenheim Technical University

Use the left and right arrow keys or click the left and right edges of the page to navigate between slides.
(Press 'H' or navigate to hide this message.)