238
Raft Utah Distributed Systems Meetup and Reading Group - Raft JT Olds Space Monkey Vivint R&D November 18, 2014

Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Utah Distributed Systems Meetup andReading Group - Raft

JT Olds

Space MonkeyVivint R&D

November 18, 2014

Page 2: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Outline

1 Introduction

2 Algorithm

3 Other practical concerns

4 Paper Conclusion

5 Raft issues

Page 3: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Outline

1 Introduction

2 Algorithm

3 Other practical concerns

4 Paper Conclusion

5 Raft issues

Page 4: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Introduction

1 IntroductionAbstract1. Introduction2. Replicated state machines3. What’s wrong with Paxos?4. Designing for understandability

Page 5: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Nearly all content and images from Diego Ongaro and JohnOusterhout’s 2014 paper, In Search of an Understandable

Consensus Algorithm (Extended Version).

Page 6: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Abstract

Introduction

1 IntroductionAbstract1. Introduction2. Replicated state machines3. What’s wrong with Paxos?4. Designing for understandability

Page 7: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Abstract

Raft is a consensus algorithm for managing a replicatedlog.Equivalent to Paxos in operation, except moreunderstandable.Separates leader election, log replication, safety, andreduces possible states.Easier to learn.Supports cluster membership changes.

Page 8: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Abstract

Raft is a consensus algorithm for managing a replicatedlog.Equivalent to Paxos in operation, except moreunderstandable.Separates leader election, log replication, safety, andreduces possible states.Easier to learn.Supports cluster membership changes.

Page 9: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Abstract

Raft is a consensus algorithm for managing a replicatedlog.Equivalent to Paxos in operation, except moreunderstandable.Separates leader election, log replication, safety, andreduces possible states.Easier to learn.Supports cluster membership changes.

Page 10: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Abstract

Raft is a consensus algorithm for managing a replicatedlog.Equivalent to Paxos in operation, except moreunderstandable.Separates leader election, log replication, safety, andreduces possible states.Easier to learn.Supports cluster membership changes.

Page 11: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

Abstract

Raft is a consensus algorithm for managing a replicatedlog.Equivalent to Paxos in operation, except moreunderstandable.Separates leader election, log replication, safety, andreduces possible states.Easier to learn.Supports cluster membership changes.

Page 12: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Introduction

1 IntroductionAbstract1. Introduction2. Replicated state machines3. What’s wrong with Paxos?4. Designing for understandability

Page 13: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Consensus algorithms allow a collection of machines towork as a coherent group that can survive the failure ofsome members.Paxos has been the primary consensus algorithm for toolong.Paxos is difficult to understand and implement.Raft’s key goal is understandability.

Page 14: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Consensus algorithms allow a collection of machines towork as a coherent group that can survive the failure ofsome members.Paxos has been the primary consensus algorithm for toolong.Paxos is difficult to understand and implement.Raft’s key goal is understandability.

Page 15: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Consensus algorithms allow a collection of machines towork as a coherent group that can survive the failure ofsome members.Paxos has been the primary consensus algorithm for toolong.Paxos is difficult to understand and implement.Raft’s key goal is understandability.

Page 16: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Consensus algorithms allow a collection of machines towork as a coherent group that can survive the failure ofsome members.Paxos has been the primary consensus algorithm for toolong.Paxos is difficult to understand and implement.Raft’s key goal is understandability.

Page 17: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Notable raft features

Strong leaderRandomized timeouts for leader electionMembership changes

Page 18: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Notable raft features

Strong leaderRandomized timeouts for leader electionMembership changes

Page 19: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Notable raft features

Strong leaderRandomized timeouts for leader electionMembership changes

Page 20: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

1. Introduction

Notable raft features

Strong leaderRandomized timeouts for leader electionMembership changes

Page 21: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

Introduction

1 IntroductionAbstract1. Introduction2. Replicated state machines3. What’s wrong with Paxos?4. Designing for understandability

Page 22: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

Figure 1: Replicated state machine architecture. The con-sensus algorithm manages a replicated log containing statemachine commands from clients. The state machines processidentical sequences of commands from the logs, so they pro-duce the same outputs.

used to solve a variety of fault tolerance problems in dis-tributed systems. For example, large-scale systems thathave a single cluster leader, such as GFS [8], HDFS [38],and RAMCloud [33], typically use a separate replicatedstate machine to manage leader election and store config-uration information that must survive leader crashes. Ex-amples of replicated state machines include Chubby [2]and ZooKeeper [11].

Replicated state machines are typically implementedusing a replicated log, as shown in Figure 1. Each serverstores a log containing a series of commands, which itsstate machine executes in order. Each log contains thesame commands in the same order, so each state ma-chine processes the same sequence of commands. Sincethe state machines are deterministic, each computes thesame state and the same sequence of outputs.

Keeping the replicated log consistent is the job of theconsensus algorithm. The consensus module on a serverreceives commands from clients and adds them to its log.It communicates with the consensus modules on otherservers to ensure that every log eventually contains thesame requests in the same order, even if some servers fail.Once commands are properly replicated, each server’sstate machine processes them in log order, and the out-puts are returned to clients. As a result, the servers appearto form a single, highly reliable state machine.

Consensus algorithms for practical systems typicallyhave the following properties:• They ensure safety (never returning an incorrect re-

sult) under all non-Byzantine conditions, includingnetwork delays, partitions, and packet loss, duplica-tion, and reordering.

• They are fully functional (available) as long as anymajority of the servers are operational and can com-municate with each other and with clients. Thus, atypical cluster of five servers can tolerate the failureof any two servers. Servers are assumed to fail bystopping; they may later recover from state on stablestorage and rejoin the cluster.

• They do not depend on timing to ensure the consis-

tency of the logs: faulty clocks and extreme messagedelays can, at worst, cause availability problems.

• In the common case, a command can complete assoon as a majority of the cluster has responded to asingle round of remote procedure calls; a minority ofslow servers need not impact overall system perfor-mance.

3 What’s wrong with Paxos?Over the last ten years, Leslie Lamport’s Paxos proto-

col [15] has become almost synonymous with consensus:it is the protocol most commonly taught in courses, andmost implementations of consensus use it as a startingpoint. Paxos first defines a protocol capable of reachingagreement on a single decision, such as a single replicatedlog entry. We refer to this subset as single-decree Paxos.Paxos then combines multiple instances of this protocol tofacilitate a series of decisions such as a log (multi-Paxos).Paxos ensures both safety and liveness, and it supportschanges in cluster membership. Its correctness has beenproven, and it is efficient in the normal case.

Unfortunately, Paxos has two significant drawbacks.The first drawback is that Paxos is exceptionally diffi-cult to understand. The full explanation [15] is notori-ously opaque; few people succeed in understanding it, andonly with great effort. As a result, there have been severalattempts to explain Paxos in simpler terms [16, 20, 21].These explanations focus on the single-decree subset, yetthey are still challenging. In an informal survey of atten-dees at NSDI 2012, we found few people who were com-fortable with Paxos, even among seasoned researchers.We struggled with Paxos ourselves; we were not able tounderstand the complete protocol until after reading sev-eral simplified explanations and designing our own alter-native protocol, a process that took almost a year.

We hypothesize that Paxos’ opaqueness derives fromits choice of the single-decree subset as its foundation.Single-decree Paxos is dense and subtle: it is divided intotwo stages that do not have simple intuitive explanationsand cannot be understood independently. Because of this,it is difficult to develop intuitions about why the single-decree protocol works. The composition rules for multi-Paxos add significant additional complexity and subtlety.We believe that the overall problem of reaching consensuson multiple decisions (i.e., a log instead of a single entry)can be decomposed in other ways that are more direct andobvious.

The second problem with Paxos is that it does not pro-vide a good foundation for building practical implemen-tations. One reason is that there is no widely agreed-upon algorithm for multi-Paxos. Lamport’s descriptionsare mostly about single-decree Paxos; he sketched possi-ble approaches to multi-Paxos, but many details are miss-ing. There have been several attempts to flesh out and op-timize Paxos, such as [26], [39], and [13], but these differ

2

Page 23: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

State machines must be completely deterministic.State machines operate on events popped from a log.Logs are managed by the consensus algorithm.

Consensus algorithms

should provide safety - never return an incorrect result.should provide availability - must work when a majority ofservers are up.should not depend on timing.can mitigate poor performance. A slow minority shouldn’tbe waited for.

Page 24: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

State machines must be completely deterministic.State machines operate on events popped from a log.Logs are managed by the consensus algorithm.

Consensus algorithms

should provide safety - never return an incorrect result.should provide availability - must work when a majority ofservers are up.should not depend on timing.can mitigate poor performance. A slow minority shouldn’tbe waited for.

Page 25: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

State machines must be completely deterministic.State machines operate on events popped from a log.Logs are managed by the consensus algorithm.

Consensus algorithms

should provide safety - never return an incorrect result.should provide availability - must work when a majority ofservers are up.should not depend on timing.can mitigate poor performance. A slow minority shouldn’tbe waited for.

Page 26: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

State machines must be completely deterministic.State machines operate on events popped from a log.Logs are managed by the consensus algorithm.

Consensus algorithms

should provide safety - never return an incorrect result.should provide availability - must work when a majority ofservers are up.should not depend on timing.can mitigate poor performance. A slow minority shouldn’tbe waited for.

Page 27: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

State machines must be completely deterministic.State machines operate on events popped from a log.Logs are managed by the consensus algorithm.

Consensus algorithms

should provide safety - never return an incorrect result.should provide availability - must work when a majority ofservers are up.should not depend on timing.can mitigate poor performance. A slow minority shouldn’tbe waited for.

Page 28: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

State machines must be completely deterministic.State machines operate on events popped from a log.Logs are managed by the consensus algorithm.

Consensus algorithms

should provide safety - never return an incorrect result.should provide availability - must work when a majority ofservers are up.should not depend on timing.can mitigate poor performance. A slow minority shouldn’tbe waited for.

Page 29: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

State machines must be completely deterministic.State machines operate on events popped from a log.Logs are managed by the consensus algorithm.

Consensus algorithms

should provide safety - never return an incorrect result.should provide availability - must work when a majority ofservers are up.should not depend on timing.can mitigate poor performance. A slow minority shouldn’tbe waited for.

Page 30: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

2. Replicated state machines

State machines must be completely deterministic.State machines operate on events popped from a log.Logs are managed by the consensus algorithm.

Consensus algorithms

should provide safety - never return an incorrect result.should provide availability - must work when a majority ofservers are up.should not depend on timing.can mitigate poor performance. A slow minority shouldn’tbe waited for.

Page 31: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Introduction

1 IntroductionAbstract1. Introduction2. Replicated state machines3. What’s wrong with Paxos?4. Designing for understandability

Page 32: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside

1970s - Jim Gray and others propose two-phase commit.Vulnerable to partitions.1980s - Three-phase commit. Not provably correct, hasproblems.1990s - Leslie Lamport tries to prove the properties ofwhat became Paxos is impossible, comes up with Paxos.

Page 33: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside

1970s - Jim Gray and others propose two-phase commit.Vulnerable to partitions.1980s - Three-phase commit. Not provably correct, hasproblems.1990s - Leslie Lamport tries to prove the properties ofwhat became Paxos is impossible, comes up with Paxos.

Page 34: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside

1970s - Jim Gray and others propose two-phase commit.Vulnerable to partitions.1980s - Three-phase commit. Not provably correct, hasproblems.1990s - Leslie Lamport tries to prove the properties ofwhat became Paxos is impossible, comes up with Paxos.

Page 35: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside

1970s - Jim Gray and others propose two-phase commit.Vulnerable to partitions.1980s - Three-phase commit. Not provably correct, hasproblems.1990s - Leslie Lamport tries to prove the properties ofwhat became Paxos is impossible, comes up with Paxos.

Page 36: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 37: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 38: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 39: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 40: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 41: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 42: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 43: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 44: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 45: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 46: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 2

The part-time parliament - 1998Paxos made simple - 2001The ABCD’s of Paxos - 2001Generalized consensus and Paxos - 2005Fast paxos - 2006Paxos made live: an engineering perspective - 2007Paxos made practical - 2007Paxos for system builders - 2008Paxos made moderately complex - 2012In search of an understandable consensus algorithm -2013

Page 47: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 3

Go To Statement Considered Harmful - 1968‘GOTO Considered Harmful’ Considered Harmful - 1987‘"GOTO Considered Harmful" Considered Harmful’Considered Harmful? - 1987On a Somewhat Disappointing Correspondence - 1987

Page 48: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 3

Go To Statement Considered Harmful - 1968‘GOTO Considered Harmful’ Considered Harmful - 1987‘"GOTO Considered Harmful" Considered Harmful’Considered Harmful? - 1987On a Somewhat Disappointing Correspondence - 1987

Page 49: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 3

Go To Statement Considered Harmful - 1968‘GOTO Considered Harmful’ Considered Harmful - 1987‘"GOTO Considered Harmful" Considered Harmful’Considered Harmful? - 1987On a Somewhat Disappointing Correspondence - 1987

Page 50: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 3

Go To Statement Considered Harmful - 1968‘GOTO Considered Harmful’ Considered Harmful - 1987‘"GOTO Considered Harmful" Considered Harmful’Considered Harmful? - 1987On a Somewhat Disappointing Correspondence - 1987

Page 51: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Brief aside - part 3

Go To Statement Considered Harmful - 1968‘GOTO Considered Harmful’ Considered Harmful - 1987‘"GOTO Considered Harmful" Considered Harmful’Considered Harmful? - 1987On a Somewhat Disappointing Correspondence - 1987

Page 52: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Paxos is broken into

single-decree Paxos - goal is to replicate one log entrymulti-Paxos - combines single-decree Paxos to decide afull log.

Page 53: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Paxos is broken into

single-decree Paxos - goal is to replicate one log entrymulti-Paxos - combines single-decree Paxos to decide afull log.

Page 54: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Paxos is broken into

single-decree Paxos - goal is to replicate one log entrymulti-Paxos - combines single-decree Paxos to decide afull log.

Page 55: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Problems?

super opaque and subtle - probably due to weirddecomposition.multi-Paxos only has possible approach sketches!Attempts to flesh out missing details differ from Lamport’ssketch and each other, and some have not been published.Paxos is symmetric peer-to-peer at its core (no leaders)which is inefficient when a bunch of decisions need to bemade.Paxos is good for proving theorems about Paxos, but saidproofs matter little when real implementations can differ sodrastically.

Page 56: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Problems?

super opaque and subtle - probably due to weirddecomposition.multi-Paxos only has possible approach sketches!Attempts to flesh out missing details differ from Lamport’ssketch and each other, and some have not been published.Paxos is symmetric peer-to-peer at its core (no leaders)which is inefficient when a bunch of decisions need to bemade.Paxos is good for proving theorems about Paxos, but saidproofs matter little when real implementations can differ sodrastically.

Page 57: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Problems?

super opaque and subtle - probably due to weirddecomposition.multi-Paxos only has possible approach sketches!Attempts to flesh out missing details differ from Lamport’ssketch and each other, and some have not been published.Paxos is symmetric peer-to-peer at its core (no leaders)which is inefficient when a bunch of decisions need to bemade.Paxos is good for proving theorems about Paxos, but saidproofs matter little when real implementations can differ sodrastically.

Page 58: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Problems?

super opaque and subtle - probably due to weirddecomposition.multi-Paxos only has possible approach sketches!Attempts to flesh out missing details differ from Lamport’ssketch and each other, and some have not been published.Paxos is symmetric peer-to-peer at its core (no leaders)which is inefficient when a bunch of decisions need to bemade.Paxos is good for proving theorems about Paxos, but saidproofs matter little when real implementations can differ sodrastically.

Page 59: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Problems?

super opaque and subtle - probably due to weirddecomposition.multi-Paxos only has possible approach sketches!Attempts to flesh out missing details differ from Lamport’ssketch and each other, and some have not been published.Paxos is symmetric peer-to-peer at its core (no leaders)which is inefficient when a bunch of decisions need to bemade.Is this actually a problem? Byzantine empires might say no.

Paxos is good for proving theorems about Paxos, but saidproofs matter little when real implementations can differ sodrastically.

Page 60: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

3. What’s wrong with Paxos?

Problems?

super opaque and subtle - probably due to weirddecomposition.multi-Paxos only has possible approach sketches!Attempts to flesh out missing details differ from Lamport’ssketch and each other, and some have not been published.Paxos is symmetric peer-to-peer at its core (no leaders)which is inefficient when a bunch of decisions need to bemade.Is this actually a problem? Byzantine empires might say no.

Paxos is good for proving theorems about Paxos, but saidproofs matter little when real implementations can differ sodrastically.

Page 61: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Introduction

1 IntroductionAbstract1. Introduction2. Replicated state machines3. What’s wrong with Paxos?4. Designing for understandability

Page 62: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Goals

Reduce developer design work (no unproven protocols)Safe under all conditionsAvailable under typical conditionsEfficient for common operationsUnderstandable

Page 63: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Goals

Reduce developer design work (no unproven protocols)Safe under all conditionsAvailable under typical conditionsEfficient for common operationsUnderstandable

Page 64: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Goals

Reduce developer design work (no unproven protocols)Safe under all conditionsAvailable under typical conditionsEfficient for common operationsUnderstandable

Page 65: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Goals

Reduce developer design work (no unproven protocols)Safe under all conditionsAvailable under typical conditionsEfficient for common operationsUnderstandable

Page 66: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Goals

Reduce developer design work (no unproven protocols)Safe under all conditionsAvailable under typical conditionsEfficient for common operationsUnderstandable

Page 67: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Goals

Reduce developer design work (no unproven protocols)Safe under all conditionsAvailable under typical conditionsEfficient for common operationsUnderstandable

Page 68: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Understandability

When faced with a choice, choose the easiest to explain.Subdivide problemsShrink state space

Nondeterminism

Nondeterminism usually eliminatedexcept where it makes the system simpler! (randomizedapproaches)

Page 69: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Understandability

When faced with a choice, choose the easiest to explain.Subdivide problemsShrink state space

Nondeterminism

Nondeterminism usually eliminatedexcept where it makes the system simpler! (randomizedapproaches)

Page 70: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Understandability

When faced with a choice, choose the easiest to explain.Subdivide problemsShrink state space

Nondeterminism

Nondeterminism usually eliminatedexcept where it makes the system simpler! (randomizedapproaches)

Page 71: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Understandability

When faced with a choice, choose the easiest to explain.Subdivide problemsShrink state space

Nondeterminism

Nondeterminism usually eliminatedexcept where it makes the system simpler! (randomizedapproaches)

Page 72: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Understandability

When faced with a choice, choose the easiest to explain.Subdivide problemsShrink state space

Nondeterminism

Nondeterminism usually eliminatedexcept where it makes the system simpler! (randomizedapproaches)

Page 73: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Understandability

When faced with a choice, choose the easiest to explain.Subdivide problemsShrink state space

Nondeterminism

Nondeterminism usually eliminatedexcept where it makes the system simpler! (randomizedapproaches)

Page 74: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Introduction

4. Designing for understandability

Understandability

When faced with a choice, choose the easiest to explain.Subdivide problemsShrink state space

Nondeterminism

Nondeterminism usually eliminatedexcept where it makes the system simpler! (randomizedapproaches)

Page 75: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

Outline

1 Introduction

2 Algorithm

3 Other practical concerns

4 Paper Conclusion

5 Raft issues

Page 76: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

Algorithm

2 Algorithm5. The Raft consensus algorithm5.1. Raft basics5.2. Leader election5.3. Log replication5.4. Safety5.5. Follower and candidate crashes5.6. Timing and availability

Page 77: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

Simulation

raftconsensus.github.io

Page 78: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Algorithm

2 Algorithm5. The Raft consensus algorithm5.1. Raft basics5.2. Leader election5.3. Log replication5.4. Safety5.5. Follower and candidate crashes5.6. Timing and availability

Page 79: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Invoked by candidates to gather votes (§5.2).

Arguments:

term candidate’s termcandidateId candidate requesting vote

lastLogIndex index of candidate’s last log entry (§5.4)lastLogTerm term of candidate’s last log entry (§5.4)

Results:

term currentTerm, for candidate to update itselfvoteGranted true means candidate received vote

Receiver implementation:1. Reply false if term < currentTerm (§5.1)

2. If votedFor is null or candidateId, and candidate’s log is at

least as up-to-date as receiver’s log, grant vote (§5.2, §5.4)

RequestVote RPC

Invoked by leader to replicate log entries (§5.3); also used asheartbeat (§5.2).

Arguments:term leader’s term

leaderId so follower can redirect clientsprevLogIndex index of log entry immediately preceding

new ones

prevLogTerm term of prevLogIndex entryentries[] log entries to store (empty for heartbeat;

may send more than one for efficiency)leaderCommit leader’s commitIndex

Results:

term currentTerm, for leader to update itselfsuccess true if follower contained entry matching

prevLogIndex and prevLogTerm

Receiver implementation:1. Reply false if term < currentTerm (§5.1)

2. Reply false if log doesn’t contain an entry at prevLogIndexwhose term matches prevLogTerm (§5.3)

3. If an existing entry conflicts with a new one (same index

but different terms), delete the existing entry and all thatfollow it (§5.3)

4. Append any new entries not already in the log5. If leaderCommit > commitIndex, set commitIndex =

min(leaderCommit, index of last new entry)

AppendEntries RPC

Persistent state on all servers:(Updated on stable storage before responding to RPCs)

currentTerm latest term server has seen (initialized to 0on first boot, increases monotonically)

votedFor candidateId that received vote in current

term (or null if none)log[] log entries; each entry contains command

for state machine, and term when entrywas received by leader (first index is 1)

Volatile state on all servers:commitIndex index of highest log entry known to be

committed (initialized to 0, increases

monotonically)lastApplied index of highest log entry applied to state

machine (initialized to 0, increases

monotonically)

Volatile state on leaders:

(Reinitialized after election)nextIndex[] for each server, index of the next log entry

to send to that server (initialized to leader

last log index + 1)matchIndex[] for each server, index of highest log entry

known to be replicated on server(initialized to 0, increases monotonically)

State

All Servers:• If commitIndex > lastApplied: increment lastApplied, apply

log[lastApplied] to state machine (§5.3)• If RPC request or response contains term T > currentTerm:

set currentTerm = T, convert to follower (§5.1)

Followers (§5.2):• Respond to RPCs from candidates and leaders

• If election timeout elapses without receiving AppendEntriesRPC from current leader or granting vote to candidate:

convert to candidate

Candidates (§5.2):

• On conversion to candidate, start election:

• Increment currentTerm• Vote for self

• Reset election timer

• Send RequestVote RPCs to all other servers• If votes received from majority of servers: become leader

• If AppendEntries RPC received from new leader: convert tofollower

• If election timeout elapses: start new election

Leaders:• Upon election: send initial empty AppendEntries RPCs

(heartbeat) to each server; repeat during idle periods toprevent election timeouts (§5.2)

• If command received from client: append entry to local log,

respond after entry applied to state machine (§5.3)• If last log index ≥ nextIndex for a follower: send

AppendEntries RPC with log entries starting at nextIndex• If successful: update nextIndex and matchIndex for

follower (§5.3)

• If AppendEntries fails because of log inconsistency:decrement nextIndex and retry (§5.3)

• If there exists an N such that N > commitIndex, a majorityof matchIndex[i] ≥ N, and log[N].term == currentTerm:

set commitIndex = N (§5.3, §5.4).

Rules for Servers

Figure 2: A condensed summary of the Raft consensus algorithm (excluding membership changes and log compaction). The serverbehavior in the upper-left box is described as a set of rules that trigger independently and repeatedly. Section numbers such as §5.2indicate where particular features are discussed. A formal specification [31] describes the algorithm more precisely.

4

Page 80: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Invoked by candidates to gather votes (§5.2).

Arguments:

term candidate’s termcandidateId candidate requesting vote

lastLogIndex index of candidate’s last log entry (§5.4)lastLogTerm term of candidate’s last log entry (§5.4)

Results:

term currentTerm, for candidate to update itselfvoteGranted true means candidate received vote

Receiver implementation:1. Reply false if term < currentTerm (§5.1)

2. If votedFor is null or candidateId, and candidate’s log is at

least as up-to-date as receiver’s log, grant vote (§5.2, §5.4)

RequestVote RPC

Invoked by leader to replicate log entries (§5.3); also used asheartbeat (§5.2).

Arguments:term leader’s term

leaderId so follower can redirect clientsprevLogIndex index of log entry immediately preceding

new ones

prevLogTerm term of prevLogIndex entryentries[] log entries to store (empty for heartbeat;

may send more than one for efficiency)leaderCommit leader’s commitIndex

Results:

term currentTerm, for leader to update itselfsuccess true if follower contained entry matching

prevLogIndex and prevLogTerm

Receiver implementation:1. Reply false if term < currentTerm (§5.1)

2. Reply false if log doesn’t contain an entry at prevLogIndexwhose term matches prevLogTerm (§5.3)

3. If an existing entry conflicts with a new one (same index

but different terms), delete the existing entry and all thatfollow it (§5.3)

4. Append any new entries not already in the log5. If leaderCommit > commitIndex, set commitIndex =

min(leaderCommit, index of last new entry)

AppendEntries RPC

Persistent state on all servers:(Updated on stable storage before responding to RPCs)

currentTerm latest term server has seen (initialized to 0on first boot, increases monotonically)

votedFor candidateId that received vote in current

term (or null if none)log[] log entries; each entry contains command

for state machine, and term when entrywas received by leader (first index is 1)

Volatile state on all servers:commitIndex index of highest log entry known to be

committed (initialized to 0, increases

monotonically)lastApplied index of highest log entry applied to state

machine (initialized to 0, increases

monotonically)

Volatile state on leaders:

(Reinitialized after election)nextIndex[] for each server, index of the next log entry

to send to that server (initialized to leader

last log index + 1)matchIndex[] for each server, index of highest log entry

known to be replicated on server(initialized to 0, increases monotonically)

State

All Servers:• If commitIndex > lastApplied: increment lastApplied, apply

log[lastApplied] to state machine (§5.3)• If RPC request or response contains term T > currentTerm:

set currentTerm = T, convert to follower (§5.1)

Followers (§5.2):• Respond to RPCs from candidates and leaders

• If election timeout elapses without receiving AppendEntriesRPC from current leader or granting vote to candidate:

convert to candidate

Candidates (§5.2):

• On conversion to candidate, start election:

• Increment currentTerm• Vote for self

• Reset election timer

• Send RequestVote RPCs to all other servers• If votes received from majority of servers: become leader

• If AppendEntries RPC received from new leader: convert tofollower

• If election timeout elapses: start new election

Leaders:• Upon election: send initial empty AppendEntries RPCs

(heartbeat) to each server; repeat during idle periods toprevent election timeouts (§5.2)

• If command received from client: append entry to local log,

respond after entry applied to state machine (§5.3)• If last log index ≥ nextIndex for a follower: send

AppendEntries RPC with log entries starting at nextIndex• If successful: update nextIndex and matchIndex for

follower (§5.3)

• If AppendEntries fails because of log inconsistency:decrement nextIndex and retry (§5.3)

• If there exists an N such that N > commitIndex, a majorityof matchIndex[i] ≥ N, and log[N].term == currentTerm:

set commitIndex = N (§5.3, §5.4).

Rules for Servers

Figure 2: A condensed summary of the Raft consensus algorithm (excluding membership changes and log compaction). The serverbehavior in the upper-left box is described as a set of rules that trigger independently and repeatedly. Section numbers such as §5.2indicate where particular features are discussed. A formal specification [31] describes the algorithm more precisely.

4

Page 81: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Leaders

Leaders get complete responsibility for managing thereplicated log.All changes flow from the leader to others.

Subproblems

Leader election (5.2)Log replication (5.3)Safety (5.4)

Page 82: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Leaders

Leaders get complete responsibility for managing thereplicated log.All changes flow from the leader to others.

Subproblems

Leader election (5.2)Log replication (5.3)Safety (5.4)

Page 83: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Leaders

Leaders get complete responsibility for managing thereplicated log.All changes flow from the leader to others.

Subproblems

Leader election (5.2)Log replication (5.3)Safety (5.4)

Page 84: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Leaders

Leaders get complete responsibility for managing thereplicated log.All changes flow from the leader to others.

Subproblems

Leader election (5.2)Log replication (5.3)Safety (5.4)

Page 85: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Leaders

Leaders get complete responsibility for managing thereplicated log.All changes flow from the leader to others.

Subproblems

Leader election (5.2)Log replication (5.3)Safety (5.4)

Page 86: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Leaders

Leaders get complete responsibility for managing thereplicated log.All changes flow from the leader to others.

Subproblems

Leader election (5.2)Log replication (5.3)Safety (5.4)

Page 87: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Leaders

Leaders get complete responsibility for managing thereplicated log.All changes flow from the leader to others.

Subproblems

Leader election (5.2)Log replication (5.3)Safety (5.4)

Page 88: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5. The Raft consensus algorithm

Election Safety: at most one leader can be elected in agiven term. §5.2

Leader Append-Only: a leader never overwrites or deletesentries in its log; it only appends new entries. §5.3

Log Matching: if two logs contain an entry with the sameindex and term, then the logs are identical in all entriesup through the given index. §5.3

Leader Completeness: if a log entry is committed in agiven term, then that entry will be present in the logsof the leaders for all higher-numbered terms. §5.4

State Machine Safety: if a server has applied a log entryat a given index to its state machine, no other serverwill ever apply a different log entry for the same index.§5.4.3

Figure 3: Raft guarantees that each of these properties is trueat all times. The section numbers indicate where each prop-erty is discussed.

from clients and replicate them across the cluster,forcing the other logs to agree with its own (Sec-tion 5.3).

• Safety: the key safety property for Raft is the StateMachine Safety Property in Figure 3: if any serverhas applied a particular log entry to its state machine,then no other server may apply a different commandfor the same log index. Section 5.4 describes howRaft ensures this property; the solution involves anadditional restriction on the election mechanism de-scribed in Section 5.2.

After presenting the consensus algorithm, this section dis-cusses the issue of availability and the role of timing in thesystem.

5.1 Raft basicsA Raft cluster contains several servers; five is a typical

number, which allows the system to tolerate two failures.At any given time each server is in one of three states:leader, follower, or candidate. In normal operation thereis exactly one leader and all of the other servers are fol-lowers. Followers are passive: they issue no requests ontheir own but simply respond to requests from leadersand candidates. The leader handles all client requests (ifa client contacts a follower, the follower redirects it to theleader). The third state, candidate, is used to elect a newleader as described in Section 5.2. Figure 4 shows thestates and their transitions; the transitions are discussedbelow.

Raft divides time into terms of arbitrary length, asshown in Figure 5. Terms are numbered with consecutiveintegers. Each term begins with an election, in which oneor more candidates attempt to become leader as describedin Section 5.2. If a candidate wins the election, then itserves as leader for the rest of the term. In some situationsan election will result in a split vote. In this case the termwill end with no leader; a new term (with a new election)

Figure 4: Server states. Followers only respond to requestsfrom other servers. If a follower receives no communication,it becomes a candidate and initiates an election. A candidatethat receives votes from a majority of the full cluster becomesthe new leader. Leaders typically operate until they fail.

Figure 5: Time is divided into terms, and each term beginswith an election. After a successful election, a single leadermanages the cluster until the end of the term. Some electionsfail, in which case the term ends without choosing a leader.The transitions between terms may be observed at differenttimes on different servers.

will begin shortly. Raft ensures that there is at most oneleader in a given term.

Different servers may observe the transitions betweenterms at different times, and in some situations a servermay not observe an election or even entire terms. Termsact as a logical clock [14] in Raft, and they allow serversto detect obsolete information such as stale leaders. Eachserver stores a current term number, which increasesmonotonically over time. Current terms are exchangedwhenever servers communicate; if one server’s currentterm is smaller than the other’s, then it updates its currentterm to the larger value. If a candidate or leader discoversthat its term is out of date, it immediately reverts to fol-lower state. If a server receives a request with a stale termnumber, it rejects the request.

Raft servers communicate using remote procedure calls(RPCs), and the basic consensus algorithm requires onlytwo types of RPCs. RequestVote RPCs are initiated bycandidates during elections (Section 5.2), and Append-Entries RPCs are initiated by leaders to replicate log en-tries and to provide a form of heartbeat (Section 5.3). Sec-tion 7 adds a third RPC for transferring snapshots betweenservers. Servers retry RPCs if they do not receive a re-sponse in a timely manner, and they issue RPCs in parallelfor best performance.

5.2 Leader electionRaft uses a heartbeat mechanism to trigger leader elec-

tion. When servers start up, they begin as followers. Aserver remains in follower state as long as it receives valid

5

Page 89: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Algorithm

2 Algorithm5. The Raft consensus algorithm5.1. Raft basics5.2. Leader election5.3. Log replication5.4. Safety5.5. Follower and candidate crashes5.6. Timing and availability

Page 90: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Raft cluster contains several servers - e.g. five allows fortwo failures.Servers are in one of only three states - leader, follower, orcandidate.There should only be one leader. Leader handles all clientrequests.Leaders typically operate until they fail.Followers are passive - all client requests are forwarded tothe leader.

Page 91: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Raft cluster contains several servers - e.g. five allows fortwo failures.Servers are in one of only three states - leader, follower, orcandidate.There should only be one leader. Leader handles all clientrequests.Leaders typically operate until they fail.Followers are passive - all client requests are forwarded tothe leader.

Page 92: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Raft cluster contains several servers - e.g. five allows fortwo failures.Servers are in one of only three states - leader, follower, orcandidate.There should only be one leader. Leader handles all clientrequests.Leaders typically operate until they fail.Followers are passive - all client requests are forwarded tothe leader.

Page 93: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Raft cluster contains several servers - e.g. five allows fortwo failures.Servers are in one of only three states - leader, follower, orcandidate.There should only be one leader. Leader handles all clientrequests.Leaders typically operate until they fail.Followers are passive - all client requests are forwarded tothe leader.

Page 94: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Raft cluster contains several servers - e.g. five allows fortwo failures.Servers are in one of only three states - leader, follower, orcandidate.There should only be one leader. Leader handles all clientrequests.Leaders typically operate until they fail.Followers are passive - all client requests are forwarded tothe leader.

Page 95: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Election Safety: at most one leader can be elected in agiven term. §5.2

Leader Append-Only: a leader never overwrites or deletesentries in its log; it only appends new entries. §5.3

Log Matching: if two logs contain an entry with the sameindex and term, then the logs are identical in all entriesup through the given index. §5.3

Leader Completeness: if a log entry is committed in agiven term, then that entry will be present in the logsof the leaders for all higher-numbered terms. §5.4

State Machine Safety: if a server has applied a log entryat a given index to its state machine, no other serverwill ever apply a different log entry for the same index.§5.4.3

Figure 3: Raft guarantees that each of these properties is trueat all times. The section numbers indicate where each prop-erty is discussed.

from clients and replicate them across the cluster,forcing the other logs to agree with its own (Sec-tion 5.3).

• Safety: the key safety property for Raft is the StateMachine Safety Property in Figure 3: if any serverhas applied a particular log entry to its state machine,then no other server may apply a different commandfor the same log index. Section 5.4 describes howRaft ensures this property; the solution involves anadditional restriction on the election mechanism de-scribed in Section 5.2.

After presenting the consensus algorithm, this section dis-cusses the issue of availability and the role of timing in thesystem.

5.1 Raft basicsA Raft cluster contains several servers; five is a typical

number, which allows the system to tolerate two failures.At any given time each server is in one of three states:leader, follower, or candidate. In normal operation thereis exactly one leader and all of the other servers are fol-lowers. Followers are passive: they issue no requests ontheir own but simply respond to requests from leadersand candidates. The leader handles all client requests (ifa client contacts a follower, the follower redirects it to theleader). The third state, candidate, is used to elect a newleader as described in Section 5.2. Figure 4 shows thestates and their transitions; the transitions are discussedbelow.

Raft divides time into terms of arbitrary length, asshown in Figure 5. Terms are numbered with consecutiveintegers. Each term begins with an election, in which oneor more candidates attempt to become leader as describedin Section 5.2. If a candidate wins the election, then itserves as leader for the rest of the term. In some situationsan election will result in a split vote. In this case the termwill end with no leader; a new term (with a new election)

Figure 4: Server states. Followers only respond to requestsfrom other servers. If a follower receives no communication,it becomes a candidate and initiates an election. A candidatethat receives votes from a majority of the full cluster becomesthe new leader. Leaders typically operate until they fail.

Figure 5: Time is divided into terms, and each term beginswith an election. After a successful election, a single leadermanages the cluster until the end of the term. Some electionsfail, in which case the term ends without choosing a leader.The transitions between terms may be observed at differenttimes on different servers.

will begin shortly. Raft ensures that there is at most oneleader in a given term.

Different servers may observe the transitions betweenterms at different times, and in some situations a servermay not observe an election or even entire terms. Termsact as a logical clock [14] in Raft, and they allow serversto detect obsolete information such as stale leaders. Eachserver stores a current term number, which increasesmonotonically over time. Current terms are exchangedwhenever servers communicate; if one server’s currentterm is smaller than the other’s, then it updates its currentterm to the larger value. If a candidate or leader discoversthat its term is out of date, it immediately reverts to fol-lower state. If a server receives a request with a stale termnumber, it rejects the request.

Raft servers communicate using remote procedure calls(RPCs), and the basic consensus algorithm requires onlytwo types of RPCs. RequestVote RPCs are initiated bycandidates during elections (Section 5.2), and Append-Entries RPCs are initiated by leaders to replicate log en-tries and to provide a form of heartbeat (Section 5.3). Sec-tion 7 adds a third RPC for transferring snapshots betweenservers. Servers retry RPCs if they do not receive a re-sponse in a timely manner, and they issue RPCs in parallelfor best performance.

5.2 Leader electionRaft uses a heartbeat mechanism to trigger leader elec-

tion. When servers start up, they begin as followers. Aserver remains in follower state as long as it receives valid

5

Page 96: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Terms

A term is arbitrary length.Terms are numbered with consecutive integers.Terms begin with an election.Terms with split-vote elections end with no leader, and anew term starts.Terms form a logical clock and the current term isexchanged during all communications.Stale terms are rejected, new terms are immediatelyaccepted (reverting to follower state).

Page 97: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Terms

A term is arbitrary length.Terms are numbered with consecutive integers.Terms begin with an election.Terms with split-vote elections end with no leader, and anew term starts.Terms form a logical clock and the current term isexchanged during all communications.Stale terms are rejected, new terms are immediatelyaccepted (reverting to follower state).

Page 98: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Terms

A term is arbitrary length.Terms are numbered with consecutive integers.Terms begin with an election.Terms with split-vote elections end with no leader, and anew term starts.Terms form a logical clock and the current term isexchanged during all communications.Stale terms are rejected, new terms are immediatelyaccepted (reverting to follower state).

Page 99: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Terms

A term is arbitrary length.Terms are numbered with consecutive integers.Terms begin with an election.Terms with split-vote elections end with no leader, and anew term starts.Terms form a logical clock and the current term isexchanged during all communications.Stale terms are rejected, new terms are immediatelyaccepted (reverting to follower state).

Page 100: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Terms

A term is arbitrary length.Terms are numbered with consecutive integers.Terms begin with an election.Terms with split-vote elections end with no leader, and anew term starts.Terms form a logical clock and the current term isexchanged during all communications.Stale terms are rejected, new terms are immediatelyaccepted (reverting to follower state).

Page 101: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Terms

A term is arbitrary length.Terms are numbered with consecutive integers.Terms begin with an election.Terms with split-vote elections end with no leader, and anew term starts.Terms form a logical clock and the current term isexchanged during all communications.Stale terms are rejected, new terms are immediatelyaccepted (reverting to follower state).

Page 102: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Terms

A term is arbitrary length.Terms are numbered with consecutive integers.Terms begin with an election.Terms with split-vote elections end with no leader, and anew term starts.Terms form a logical clock and the current term isexchanged during all communications.Stale terms are rejected, new terms are immediatelyaccepted (reverting to follower state).

Page 103: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Election Safety: at most one leader can be elected in agiven term. §5.2

Leader Append-Only: a leader never overwrites or deletesentries in its log; it only appends new entries. §5.3

Log Matching: if two logs contain an entry with the sameindex and term, then the logs are identical in all entriesup through the given index. §5.3

Leader Completeness: if a log entry is committed in agiven term, then that entry will be present in the logsof the leaders for all higher-numbered terms. §5.4

State Machine Safety: if a server has applied a log entryat a given index to its state machine, no other serverwill ever apply a different log entry for the same index.§5.4.3

Figure 3: Raft guarantees that each of these properties is trueat all times. The section numbers indicate where each prop-erty is discussed.

from clients and replicate them across the cluster,forcing the other logs to agree with its own (Sec-tion 5.3).

• Safety: the key safety property for Raft is the StateMachine Safety Property in Figure 3: if any serverhas applied a particular log entry to its state machine,then no other server may apply a different commandfor the same log index. Section 5.4 describes howRaft ensures this property; the solution involves anadditional restriction on the election mechanism de-scribed in Section 5.2.

After presenting the consensus algorithm, this section dis-cusses the issue of availability and the role of timing in thesystem.

5.1 Raft basicsA Raft cluster contains several servers; five is a typical

number, which allows the system to tolerate two failures.At any given time each server is in one of three states:leader, follower, or candidate. In normal operation thereis exactly one leader and all of the other servers are fol-lowers. Followers are passive: they issue no requests ontheir own but simply respond to requests from leadersand candidates. The leader handles all client requests (ifa client contacts a follower, the follower redirects it to theleader). The third state, candidate, is used to elect a newleader as described in Section 5.2. Figure 4 shows thestates and their transitions; the transitions are discussedbelow.

Raft divides time into terms of arbitrary length, asshown in Figure 5. Terms are numbered with consecutiveintegers. Each term begins with an election, in which oneor more candidates attempt to become leader as describedin Section 5.2. If a candidate wins the election, then itserves as leader for the rest of the term. In some situationsan election will result in a split vote. In this case the termwill end with no leader; a new term (with a new election)

Figure 4: Server states. Followers only respond to requestsfrom other servers. If a follower receives no communication,it becomes a candidate and initiates an election. A candidatethat receives votes from a majority of the full cluster becomesthe new leader. Leaders typically operate until they fail.

Figure 5: Time is divided into terms, and each term beginswith an election. After a successful election, a single leadermanages the cluster until the end of the term. Some electionsfail, in which case the term ends without choosing a leader.The transitions between terms may be observed at differenttimes on different servers.

will begin shortly. Raft ensures that there is at most oneleader in a given term.

Different servers may observe the transitions betweenterms at different times, and in some situations a servermay not observe an election or even entire terms. Termsact as a logical clock [14] in Raft, and they allow serversto detect obsolete information such as stale leaders. Eachserver stores a current term number, which increasesmonotonically over time. Current terms are exchangedwhenever servers communicate; if one server’s currentterm is smaller than the other’s, then it updates its currentterm to the larger value. If a candidate or leader discoversthat its term is out of date, it immediately reverts to fol-lower state. If a server receives a request with a stale termnumber, it rejects the request.

Raft servers communicate using remote procedure calls(RPCs), and the basic consensus algorithm requires onlytwo types of RPCs. RequestVote RPCs are initiated bycandidates during elections (Section 5.2), and Append-Entries RPCs are initiated by leaders to replicate log en-tries and to provide a form of heartbeat (Section 5.3). Sec-tion 7 adds a third RPC for transferring snapshots betweenservers. Servers retry RPCs if they do not receive a re-sponse in a timely manner, and they issue RPCs in parallelfor best performance.

5.2 Leader electionRaft uses a heartbeat mechanism to trigger leader elec-

tion. When servers start up, they begin as followers. Aserver remains in follower state as long as it receives valid

5

Page 104: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Only two main RPCs, three if you count log compaction

RequestVote - initiated by candidates, used duringelections.AppendEntries - initiated by leaders for heartbeats and logreplication.InstallSnapshot - used for log compaction extension

RPC properties

RPCs are retried until responses are received.RPCs are idempotent.RPCs are issued in parallel wherever possible.

Page 105: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Only two main RPCs, three if you count log compaction

RequestVote - initiated by candidates, used duringelections.AppendEntries - initiated by leaders for heartbeats and logreplication.InstallSnapshot - used for log compaction extension

RPC properties

RPCs are retried until responses are received.RPCs are idempotent.RPCs are issued in parallel wherever possible.

Page 106: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Only two main RPCs, three if you count log compaction

RequestVote - initiated by candidates, used duringelections.AppendEntries - initiated by leaders for heartbeats and logreplication.InstallSnapshot - used for log compaction extension

RPC properties

RPCs are retried until responses are received.RPCs are idempotent.RPCs are issued in parallel wherever possible.

Page 107: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Only two main RPCs, three if you count log compaction

RequestVote - initiated by candidates, used duringelections.AppendEntries - initiated by leaders for heartbeats and logreplication.InstallSnapshot - used for log compaction extension

RPC properties

RPCs are retried until responses are received.RPCs are idempotent.RPCs are issued in parallel wherever possible.

Page 108: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Only two main RPCs, three if you count log compaction

RequestVote - initiated by candidates, used duringelections.AppendEntries - initiated by leaders for heartbeats and logreplication.InstallSnapshot - used for log compaction extension

RPC properties

RPCs are retried until responses are received.RPCs are idempotent.RPCs are issued in parallel wherever possible.

Page 109: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Only two main RPCs, three if you count log compaction

RequestVote - initiated by candidates, used duringelections.AppendEntries - initiated by leaders for heartbeats and logreplication.InstallSnapshot - used for log compaction extension

RPC properties

RPCs are retried until responses are received.RPCs are idempotent.RPCs are issued in parallel wherever possible.

Page 110: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Only two main RPCs, three if you count log compaction

RequestVote - initiated by candidates, used duringelections.AppendEntries - initiated by leaders for heartbeats and logreplication.InstallSnapshot - used for log compaction extension

RPC properties

RPCs are retried until responses are received.RPCs are idempotent.RPCs are issued in parallel wherever possible.

Page 111: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.1. Raft basics

Only two main RPCs, three if you count log compaction

RequestVote - initiated by candidates, used duringelections.AppendEntries - initiated by leaders for heartbeats and logreplication.InstallSnapshot - used for log compaction extension

RPC properties

RPCs are retried until responses are received.RPCs are idempotent.RPCs are issued in parallel wherever possible.

Page 112: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Algorithm

2 Algorithm5. The Raft consensus algorithm5.1. Raft basics5.2. Leader election5.3. Log replication5.4. Safety5.5. Follower and candidate crashes5.6. Timing and availability

Page 113: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

All servers begin as followers.Servers stay followers as long as they receiveAppendEntries RPCs heartbeats (whether or not there areany log entries).If a server hears no AppendEntries call before an electiontimeout, it begins an election.

Page 114: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

All servers begin as followers.Servers stay followers as long as they receiveAppendEntries RPCs heartbeats (whether or not there areany log entries).If a server hears no AppendEntries call before an electiontimeout, it begins an election.

Page 115: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

All servers begin as followers.Servers stay followers as long as they receiveAppendEntries RPCs heartbeats (whether or not there areany log entries).If a server hears no AppendEntries call before an electiontimeout, it begins an election.

Page 116: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Elections

Follower increments its current term and transitions tocandidate state.Votes for itself and requests votes from the other servers.

Election termination

One of three things:it wins the election; now it’s the leaderit finds out about another leader; now it’s a followerneither previous case happens before another electiontimeout; the election starts over.

Page 117: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Elections

Follower increments its current term and transitions tocandidate state.Votes for itself and requests votes from the other servers.

Election termination

One of three things:it wins the election; now it’s the leaderit finds out about another leader; now it’s a followerneither previous case happens before another electiontimeout; the election starts over.

Page 118: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Elections

Follower increments its current term and transitions tocandidate state.Votes for itself and requests votes from the other servers.

Election termination

One of three things:it wins the election; now it’s the leaderit finds out about another leader; now it’s a followerneither previous case happens before another electiontimeout; the election starts over.

Page 119: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Elections

Follower increments its current term and transitions tocandidate state.Votes for itself and requests votes from the other servers.

Election termination

One of three things:it wins the election; now it’s the leaderit finds out about another leader; now it’s a followerneither previous case happens before another electiontimeout; the election starts over.

Page 120: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Elections

Follower increments its current term and transitions tocandidate state.Votes for itself and requests votes from the other servers.

Election termination

One of three things:it wins the election; now it’s the leaderit finds out about another leader; now it’s a followerneither previous case happens before another electiontimeout; the election starts over.

Page 121: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Elections

Follower increments its current term and transitions tocandidate state.Votes for itself and requests votes from the other servers.

Election termination

One of three things:it wins the election; now it’s the leaderit finds out about another leader; now it’s a followerneither previous case happens before another electiontimeout; the election starts over.

Page 122: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Elections

Follower increments its current term and transitions tocandidate state.Votes for itself and requests votes from the other servers.

Election termination

One of three things:it wins the election; now it’s the leaderit finds out about another leader; now it’s a followerneither previous case happens before another electiontimeout; the election starts over.

Page 123: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Voting

Winning is assumed if you receive a majority of votes.Each follower will vote for at most one candidate per term,first-come-first-served.At any time if any server hears a heartbeat message with aleader in the current term or newer, it assumes the sourceis the leader.

Split votes

Randomized election timeouts!

Page 124: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Voting

Winning is assumed if you receive a majority of votes.Each follower will vote for at most one candidate per term,first-come-first-served.At any time if any server hears a heartbeat message with aleader in the current term or newer, it assumes the sourceis the leader.

Split votes

Randomized election timeouts!

Page 125: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Voting

Winning is assumed if you receive a majority of votes.Each follower will vote for at most one candidate per term,first-come-first-served.At any time if any server hears a heartbeat message with aleader in the current term or newer, it assumes the sourceis the leader.

Split votes

Randomized election timeouts!

Page 126: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Voting

Winning is assumed if you receive a majority of votes.Each follower will vote for at most one candidate per term,first-come-first-served.At any time if any server hears a heartbeat message with aleader in the current term or newer, it assumes the sourceis the leader.

Split votes

Randomized election timeouts!

Page 127: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Voting

Winning is assumed if you receive a majority of votes.Each follower will vote for at most one candidate per term,first-come-first-served.At any time if any server hears a heartbeat message with aleader in the current term or newer, it assumes the sourceis the leader.

Split votes

Randomized election timeouts!

Page 128: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Election Safety: at most one leader can be elected in agiven term. §5.2

Leader Append-Only: a leader never overwrites or deletesentries in its log; it only appends new entries. §5.3

Log Matching: if two logs contain an entry with the sameindex and term, then the logs are identical in all entriesup through the given index. §5.3

Leader Completeness: if a log entry is committed in agiven term, then that entry will be present in the logsof the leaders for all higher-numbered terms. §5.4

State Machine Safety: if a server has applied a log entryat a given index to its state machine, no other serverwill ever apply a different log entry for the same index.§5.4.3

Figure 3: Raft guarantees that each of these properties is trueat all times. The section numbers indicate where each prop-erty is discussed.

from clients and replicate them across the cluster,forcing the other logs to agree with its own (Sec-tion 5.3).

• Safety: the key safety property for Raft is the StateMachine Safety Property in Figure 3: if any serverhas applied a particular log entry to its state machine,then no other server may apply a different commandfor the same log index. Section 5.4 describes howRaft ensures this property; the solution involves anadditional restriction on the election mechanism de-scribed in Section 5.2.

After presenting the consensus algorithm, this section dis-cusses the issue of availability and the role of timing in thesystem.

5.1 Raft basicsA Raft cluster contains several servers; five is a typical

number, which allows the system to tolerate two failures.At any given time each server is in one of three states:leader, follower, or candidate. In normal operation thereis exactly one leader and all of the other servers are fol-lowers. Followers are passive: they issue no requests ontheir own but simply respond to requests from leadersand candidates. The leader handles all client requests (ifa client contacts a follower, the follower redirects it to theleader). The third state, candidate, is used to elect a newleader as described in Section 5.2. Figure 4 shows thestates and their transitions; the transitions are discussedbelow.

Raft divides time into terms of arbitrary length, asshown in Figure 5. Terms are numbered with consecutiveintegers. Each term begins with an election, in which oneor more candidates attempt to become leader as describedin Section 5.2. If a candidate wins the election, then itserves as leader for the rest of the term. In some situationsan election will result in a split vote. In this case the termwill end with no leader; a new term (with a new election)

Figure 4: Server states. Followers only respond to requestsfrom other servers. If a follower receives no communication,it becomes a candidate and initiates an election. A candidatethat receives votes from a majority of the full cluster becomesthe new leader. Leaders typically operate until they fail.

Figure 5: Time is divided into terms, and each term beginswith an election. After a successful election, a single leadermanages the cluster until the end of the term. Some electionsfail, in which case the term ends without choosing a leader.The transitions between terms may be observed at differenttimes on different servers.

will begin shortly. Raft ensures that there is at most oneleader in a given term.

Different servers may observe the transitions betweenterms at different times, and in some situations a servermay not observe an election or even entire terms. Termsact as a logical clock [14] in Raft, and they allow serversto detect obsolete information such as stale leaders. Eachserver stores a current term number, which increasesmonotonically over time. Current terms are exchangedwhenever servers communicate; if one server’s currentterm is smaller than the other’s, then it updates its currentterm to the larger value. If a candidate or leader discoversthat its term is out of date, it immediately reverts to fol-lower state. If a server receives a request with a stale termnumber, it rejects the request.

Raft servers communicate using remote procedure calls(RPCs), and the basic consensus algorithm requires onlytwo types of RPCs. RequestVote RPCs are initiated bycandidates during elections (Section 5.2), and Append-Entries RPCs are initiated by leaders to replicate log en-tries and to provide a form of heartbeat (Section 5.3). Sec-tion 7 adds a third RPC for transferring snapshots betweenservers. Servers retry RPCs if they do not receive a re-sponse in a timely manner, and they issue RPCs in parallelfor best performance.

5.2 Leader electionRaft uses a heartbeat mechanism to trigger leader elec-

tion. When servers start up, they begin as followers. Aserver remains in follower state as long as it receives valid

5

Page 129: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.2. Leader election

Election Safety: at most one leader can be elected in agiven term. §5.2

Leader Append-Only: a leader never overwrites or deletesentries in its log; it only appends new entries. §5.3

Log Matching: if two logs contain an entry with the sameindex and term, then the logs are identical in all entriesup through the given index. §5.3

Leader Completeness: if a log entry is committed in agiven term, then that entry will be present in the logsof the leaders for all higher-numbered terms. §5.4

State Machine Safety: if a server has applied a log entryat a given index to its state machine, no other serverwill ever apply a different log entry for the same index.§5.4.3

Figure 3: Raft guarantees that each of these properties is trueat all times. The section numbers indicate where each prop-erty is discussed.

from clients and replicate them across the cluster,forcing the other logs to agree with its own (Sec-tion 5.3).

• Safety: the key safety property for Raft is the StateMachine Safety Property in Figure 3: if any serverhas applied a particular log entry to its state machine,then no other server may apply a different commandfor the same log index. Section 5.4 describes howRaft ensures this property; the solution involves anadditional restriction on the election mechanism de-scribed in Section 5.2.

After presenting the consensus algorithm, this section dis-cusses the issue of availability and the role of timing in thesystem.

5.1 Raft basicsA Raft cluster contains several servers; five is a typical

number, which allows the system to tolerate two failures.At any given time each server is in one of three states:leader, follower, or candidate. In normal operation thereis exactly one leader and all of the other servers are fol-lowers. Followers are passive: they issue no requests ontheir own but simply respond to requests from leadersand candidates. The leader handles all client requests (ifa client contacts a follower, the follower redirects it to theleader). The third state, candidate, is used to elect a newleader as described in Section 5.2. Figure 4 shows thestates and their transitions; the transitions are discussedbelow.

Raft divides time into terms of arbitrary length, asshown in Figure 5. Terms are numbered with consecutiveintegers. Each term begins with an election, in which oneor more candidates attempt to become leader as describedin Section 5.2. If a candidate wins the election, then itserves as leader for the rest of the term. In some situationsan election will result in a split vote. In this case the termwill end with no leader; a new term (with a new election)

Figure 4: Server states. Followers only respond to requestsfrom other servers. If a follower receives no communication,it becomes a candidate and initiates an election. A candidatethat receives votes from a majority of the full cluster becomesthe new leader. Leaders typically operate until they fail.

Figure 5: Time is divided into terms, and each term beginswith an election. After a successful election, a single leadermanages the cluster until the end of the term. Some electionsfail, in which case the term ends without choosing a leader.The transitions between terms may be observed at differenttimes on different servers.

will begin shortly. Raft ensures that there is at most oneleader in a given term.

Different servers may observe the transitions betweenterms at different times, and in some situations a servermay not observe an election or even entire terms. Termsact as a logical clock [14] in Raft, and they allow serversto detect obsolete information such as stale leaders. Eachserver stores a current term number, which increasesmonotonically over time. Current terms are exchangedwhenever servers communicate; if one server’s currentterm is smaller than the other’s, then it updates its currentterm to the larger value. If a candidate or leader discoversthat its term is out of date, it immediately reverts to fol-lower state. If a server receives a request with a stale termnumber, it rejects the request.

Raft servers communicate using remote procedure calls(RPCs), and the basic consensus algorithm requires onlytwo types of RPCs. RequestVote RPCs are initiated bycandidates during elections (Section 5.2), and Append-Entries RPCs are initiated by leaders to replicate log en-tries and to provide a form of heartbeat (Section 5.3). Sec-tion 7 adds a third RPC for transferring snapshots betweenservers. Servers retry RPCs if they do not receive a re-sponse in a timely manner, and they issue RPCs in parallelfor best performance.

5.2 Leader electionRaft uses a heartbeat mechanism to trigger leader elec-

tion. When servers start up, they begin as followers. Aserver remains in follower state as long as it receives valid

5

Page 130: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Algorithm

2 Algorithm5. The Raft consensus algorithm5.1. Raft basics5.2. Leader election5.3. Log replication5.4. Safety5.5. Follower and candidate crashes5.6. Timing and availability

Page 131: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

RPCs from a leader or candidate. Leaders send periodicheartbeats (AppendEntries RPCs that carry no log entries)to all followers in order to maintain their authority. If afollower receives no communication over a period of timecalled the election timeout, then it assumes there is no vi-able leader and begins an election to choose a new leader.

To begin an election, a follower increments its currentterm and transitions to candidate state. It then votes foritself and issues RequestVote RPCs in parallel to each ofthe other servers in the cluster. A candidate continues inthis state until one of three things happens: (a) it wins theelection, (b) another server establishes itself as leader, or(c) a period of time goes by with no winner. These out-comes are discussed separately in the paragraphs below.

A candidate wins an election if it receives votes froma majority of the servers in the full cluster for the sameterm. Each server will vote for at most one candidate in agiven term, on a first-come-first-served basis (note: Sec-tion 5.4 adds an additional restriction on votes). The ma-jority rule ensures that at most one candidate can win theelection for a particular term (the Election Safety Prop-erty in Figure 3). Once a candidate wins an election, itbecomes leader. It then sends heartbeat messages to all ofthe other servers to establish its authority and prevent newelections.

While waiting for votes, a candidate may receive anAppendEntries RPC from another server claiming to beleader. If the leader’s term (included in its RPC) is at leastas large as the candidate’s current term, then the candidaterecognizes the leader as legitimate and returns to followerstate. If the term in the RPC is smaller than the candidate’scurrent term, then the candidate rejects the RPC and con-tinues in candidate state.

The third possible outcome is that a candidate neitherwins nor loses the election: if many followers becomecandidates at the same time, votes could be split so thatno candidate obtains a majority. When this happens, eachcandidate will time out and start a new election by incre-menting its term and initiating another round of Request-Vote RPCs. However, without extra measures split votescould repeat indefinitely.

Raft uses randomized election timeouts to ensure thatsplit votes are rare and that they are resolved quickly. Toprevent split votes in the first place, election timeouts arechosen randomly from a fixed interval (e.g., 150–300ms).This spreads out the servers so that in most cases only asingle server will time out; it wins the election and sendsheartbeats before any other servers time out. The samemechanism is used to handle split votes. Each candidaterestarts its randomized election timeout at the start of anelection, and it waits for that timeout to elapse beforestarting the next election; this reduces the likelihood ofanother split vote in the new election. Section 9.3 showsthat this approach elects a leader rapidly.

Figure 6: Logs are composed of entries, which are numberedsequentially. Each entry contains the term in which it wascreated (the number in each box) and a command for the statemachine. An entry is considered committed if it is safe for thatentry to be applied to state machines.

Elections are an example of how understandabilityguided our choice between design alternatives. Initiallywe planned to use a ranking system: each candidate wasassigned a unique rank, which was used to select betweencompeting candidates. If a candidate discovered anothercandidate with higher rank, it would return to followerstate so that the higher ranking candidate could more eas-ily win the next election. We found that this approachcreated subtle issues around availability (a lower-rankedserver might need to time out and become a candidateagain if a higher-ranked server fails, but if it does so toosoon, it can reset progress towards electing a leader). Wemade adjustments to the algorithm several times, but aftereach adjustment new corner cases appeared. Eventuallywe concluded that the randomized retry approach is moreobvious and understandable.

5.3 Log replicationOnce a leader has been elected, it begins servicing

client requests. Each client request contains a command tobe executed by the replicated state machines. The leaderappends the command to its log as a new entry, then is-sues AppendEntries RPCs in parallel to each of the otherservers to replicate the entry. When the entry has beensafely replicated (as described below), the leader appliesthe entry to its state machine and returns the result of thatexecution to the client. If followers crash or run slowly,or if network packets are lost, the leader retries Append-Entries RPCs indefinitely (even after it has responded tothe client) until all followers eventually store all log en-tries.

Logs are organized as shown in Figure 6. Each log en-try stores a state machine command along with the termnumber when the entry was received by the leader. Theterm numbers in log entries are used to detect inconsis-tencies between logs and to ensure some of the propertiesin Figure 3. Each log entry also has an integer index iden-

6

Page 132: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Leaders service client requests.Client request commands are added to the leader’s log.Leaders then pester followers to add the command to theirlogs via AppendEntries.Entries are identified by their term number and log index.Entries are uncommitted until the leader has determinedthat a majority of servers have the entry.AppendEntries calls (including heartbeats) indicate thehighest committed index.Committed entries are passed off to each server’s statemachine in order.

Page 133: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Leaders service client requests.Client request commands are added to the leader’s log.Leaders then pester followers to add the command to theirlogs via AppendEntries.Entries are identified by their term number and log index.Entries are uncommitted until the leader has determinedthat a majority of servers have the entry.AppendEntries calls (including heartbeats) indicate thehighest committed index.Committed entries are passed off to each server’s statemachine in order.

Page 134: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Leaders service client requests.Client request commands are added to the leader’s log.Leaders then pester followers to add the command to theirlogs via AppendEntries.Entries are identified by their term number and log index.Entries are uncommitted until the leader has determinedthat a majority of servers have the entry.AppendEntries calls (including heartbeats) indicate thehighest committed index.Committed entries are passed off to each server’s statemachine in order.

Page 135: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Leaders service client requests.Client request commands are added to the leader’s log.Leaders then pester followers to add the command to theirlogs via AppendEntries.Entries are identified by their term number and log index.Entries are uncommitted until the leader has determinedthat a majority of servers have the entry.AppendEntries calls (including heartbeats) indicate thehighest committed index.Committed entries are passed off to each server’s statemachine in order.

Page 136: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Leaders service client requests.Client request commands are added to the leader’s log.Leaders then pester followers to add the command to theirlogs via AppendEntries.Entries are identified by their term number and log index.Entries are uncommitted until the leader has determinedthat a majority of servers have the entry.AppendEntries calls (including heartbeats) indicate thehighest committed index.Committed entries are passed off to each server’s statemachine in order.

Page 137: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Leaders service client requests.Client request commands are added to the leader’s log.Leaders then pester followers to add the command to theirlogs via AppendEntries.Entries are identified by their term number and log index.Entries are uncommitted until the leader has determinedthat a majority of servers have the entry.AppendEntries calls (including heartbeats) indicate thehighest committed index.Committed entries are passed off to each server’s statemachine in order.

Page 138: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Leaders service client requests.Client request commands are added to the leader’s log.Leaders then pester followers to add the command to theirlogs via AppendEntries.Entries are identified by their term number and log index.Entries are uncommitted until the leader has determinedthat a majority of servers have the entry.AppendEntries calls (including heartbeats) indicate thehighest committed index.Committed entries are passed off to each server’s statemachine in order.

Page 139: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Logs match

Every log entry is given a term id.There is only one leader per term, and leaders neverchange log entry indices.So, given a term id, the log index is unique.AppendEntries includes the previous term id and log index,so if that log entry is missing, the follower will reject the call.The leader will back up and replay the log up to theoffending entry.

Page 140: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Logs match

Every log entry is given a term id.There is only one leader per term, and leaders neverchange log entry indices.So, given a term id, the log index is unique.AppendEntries includes the previous term id and log index,so if that log entry is missing, the follower will reject the call.The leader will back up and replay the log up to theoffending entry.

Page 141: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Logs match

Every log entry is given a term id.There is only one leader per term, and leaders neverchange log entry indices.So, given a term id, the log index is unique.AppendEntries includes the previous term id and log index,so if that log entry is missing, the follower will reject the call.The leader will back up and replay the log up to theoffending entry.

Page 142: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Logs match

Every log entry is given a term id.There is only one leader per term, and leaders neverchange log entry indices.So, given a term id, the log index is unique.AppendEntries includes the previous term id and log index,so if that log entry is missing, the follower will reject the call.The leader will back up and replay the log up to theoffending entry.

Page 143: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Logs match

Every log entry is given a term id.There is only one leader per term, and leaders neverchange log entry indices.So, given a term id, the log index is unique.AppendEntries includes the previous term id and log index,so if that log entry is missing, the follower will reject the call.The leader will back up and replay the log up to theoffending entry.

Page 144: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Logs match

Every log entry is given a term id.There is only one leader per term, and leaders neverchange log entry indices.So, given a term id, the log index is unique.AppendEntries includes the previous term id and log index,so if that log entry is missing, the follower will reject the call.The leader will back up and replay the log up to theoffending entry.

Page 145: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

tifying its position in the log.The leader decides when it is safe to apply a log en-

try to the state machines; such an entry is called commit-ted. Raft guarantees that committed entries are durableand will eventually be executed by all of the availablestate machines. A log entry is committed once the leaderthat created the entry has replicated it on a majority ofthe servers (e.g., entry 7 in Figure 6). This also commitsall preceding entries in the leader’s log, including entriescreated by previous leaders. Section 5.4 discusses somesubtleties when applying this rule after leader changes,and it also shows that this definition of commitment issafe. The leader keeps track of the highest index it knowsto be committed, and it includes that index in futureAppendEntries RPCs (including heartbeats) so that theother servers eventually find out. Once a follower learnsthat a log entry is committed, it applies the entry to itslocal state machine (in log order).

We designed the Raft log mechanism to maintain a highlevel of coherency between the logs on different servers.Not only does this simplify the system’s behavior andmake it more predictable, but it is an important componentof ensuring safety. Raft maintains the following proper-ties, which together constitute the Log Matching Propertyin Figure 3:• If two entries in different logs have the same index

and term, then they store the same command.• If two entries in different logs have the same index

and term, then the logs are identical in all precedingentries.

The first property follows from the fact that a leadercreates at most one entry with a given log index in a giventerm, and log entries never change their position in thelog. The second property is guaranteed by a simple con-sistency check performed by AppendEntries. When send-ing an AppendEntries RPC, the leader includes the indexand term of the entry in its log that immediately precedesthe new entries. If the follower does not find an entry inits log with the same index and term, then it refuses thenew entries. The consistency check acts as an inductionstep: the initial empty state of the logs satisfies the LogMatching Property, and the consistency check preservesthe Log Matching Property whenever logs are extended.As a result, whenever AppendEntries returns successfully,the leader knows that the follower’s log is identical to itsown log up through the new entries.

During normal operation, the logs of the leader andfollowers stay consistent, so the AppendEntries consis-tency check never fails. However, leader crashes can leavethe logs inconsistent (the old leader may not have fullyreplicated all of the entries in its log). These inconsisten-cies can compound over a series of leader and followercrashes. Figure 7 illustrates the ways in which followers’logs may differ from that of a new leader. A follower may

Figure 7: When the leader at the top comes to power, it ispossible that any of scenarios (a–f) could occur in followerlogs. Each box represents one log entry; the number in thebox is its term. A follower may be missing entries (a–b), mayhave extra uncommitted entries (c–d), or both (e–f). For ex-ample, scenario (f) could occur if that server was the leaderfor term 2, added several entries to its log, then crashed beforecommitting any of them; it restarted quickly, became leaderfor term 3, and added a few more entries to its log; before anyof the entries in either term 2 or term 3 were committed, theserver crashed again and remained down for several terms.

be missing entries that are present on the leader, it mayhave extra entries that are not present on the leader, orboth. Missing and extraneous entries in a log may spanmultiple terms.

In Raft, the leader handles inconsistencies by forcingthe followers’ logs to duplicate its own. This means thatconflicting entries in follower logs will be overwrittenwith entries from the leader’s log. Section 5.4 will showthat this is safe when coupled with one more restriction.

To bring a follower’s log into consistency with its own,the leader must find the latest log entry where the twologs agree, delete any entries in the follower’s log afterthat point, and send the follower all of the leader’s entriesafter that point. All of these actions happen in responseto the consistency check performed by AppendEntriesRPCs. The leader maintains a nextIndex for each follower,which is the index of the next log entry the leader willsend to that follower. When a leader first comes to power,it initializes all nextIndex values to the index just after thelast one in its log (11 in Figure 7). If a follower’s log isinconsistent with the leader’s, the AppendEntries consis-tency check will fail in the next AppendEntries RPC. Af-ter a rejection, the leader decrements nextIndex and retriesthe AppendEntries RPC. Eventually nextIndex will reacha point where the leader and follower logs match. Whenthis happens, AppendEntries will succeed, which removesany conflicting entries in the follower’s log and appendsentries from the leader’s log (if any). Once AppendEntriessucceeds, the follower’s log is consistent with the leader’s,and it will remain that way for the rest of the term.

If desired, the protocol can be optimized to reduce thenumber of rejected AppendEntries RPCs. For example,when rejecting an AppendEntries request, the follower

7

Page 146: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Conflict handling

Leaders force followers logs to duplicate their own.Conflicting entries will get overwritten.Leaders never overwrite or delete their own entries.

Page 147: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Conflict handling

Leaders force followers logs to duplicate their own.Conflicting entries will get overwritten.Leaders never overwrite or delete their own entries.

Page 148: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Conflict handling

Leaders force followers logs to duplicate their own.Conflicting entries will get overwritten.Leaders never overwrite or delete their own entries.

Page 149: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Conflict handling

Leaders force followers logs to duplicate their own.Conflicting entries will get overwritten.Leaders never overwrite or delete their own entries.

Page 150: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.3. Log replication

Whoa?!

Page 151: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.4. Safety

Algorithm

2 Algorithm5. The Raft consensus algorithm5.1. Raft basics5.2. Leader election5.3. Log replication5.4. Safety5.5. Follower and candidate crashes5.6. Timing and availability

Page 152: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.4. Safety

5.4.1 Election restriction

A leader will not get voted for if it’s missing entries the voterhas.Logs are efficiently compared by sorting the 2-tuple (termid, log index)

Page 153: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.4. Safety

5.4.1 Election restriction

A leader will not get voted for if it’s missing entries the voterhas.Logs are efficiently compared by sorting the 2-tuple (termid, log index)

Page 154: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.4. Safety

5.4.1 Election restriction

A leader will not get voted for if it’s missing entries the voterhas.Logs are efficiently compared by sorting the 2-tuple (termid, log index)

Page 155: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.4. Safety

5.4.2 Committing entries from previous terms

A leader cannot assume an entry that exists on a majority ofservers from a previous term is committed.

Page 156: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.4. Safety

5.4.2 Committing entries from previous terms

can include the term of the conflicting entry and the firstindex it stores for that term. With this information, theleader can decrement nextIndex to bypass all of the con-flicting entries in that term; one AppendEntries RPC willbe required for each term with conflicting entries, ratherthan one RPC per entry. In practice, we doubt this opti-mization is necessary, since failures happen infrequentlyand it is unlikely that there will be many inconsistent en-tries.

With this mechanism, a leader does not need to take anyspecial actions to restore log consistency when it comes topower. It just begins normal operation, and the logs auto-matically converge in response to failures of the Append-Entries consistency check. A leader never overwrites ordeletes entries in its own log (the Leader Append-OnlyProperty in Figure 3).

This log replication mechanism exhibits the desirableconsensus properties described in Section 2: Raft can ac-cept, replicate, and apply new log entries as long as a ma-jority of the servers are up; in the normal case a new entrycan be replicated with a single round of RPCs to a ma-jority of the cluster; and a single slow follower will notimpact performance.

5.4 SafetyThe previous sections described how Raft elects lead-

ers and replicates log entries. However, the mechanismsdescribed so far are not quite sufficient to ensure that eachstate machine executes exactly the same commands in thesame order. For example, a follower might be unavailablewhile the leader commits several log entries, then it couldbe elected leader and overwrite these entries with newones; as a result, different state machines might executedifferent command sequences.

This section completes the Raft algorithm by adding arestriction on which servers may be elected leader. Therestriction ensures that the leader for any given term con-tains all of the entries committed in previous terms (theLeader Completeness Property from Figure 3). Given theelection restriction, we then make the rules for commit-ment more precise. Finally, we present a proof sketch forthe Leader Completeness Property and show how it leadsto correct behavior of the replicated state machine.

5.4.1 Election restrictionIn any leader-based consensus algorithm, the leader

must eventually store all of the committed log entries. Insome consensus algorithms, such as Viewstamped Repli-cation [22], a leader can be elected even if it doesn’tinitially contain all of the committed entries. These al-gorithms contain additional mechanisms to identify themissing entries and transmit them to the new leader, ei-ther during the election process or shortly afterwards. Un-fortunately, this results in considerable additional mecha-nism and complexity. Raft uses a simpler approach whereit guarantees that all the committed entries from previous

Figure 8: A time sequence showing why a leader cannot de-termine commitment using log entries from older terms. In(a) S1 is leader and partially replicates the log entry at index2. In (b) S1 crashes; S5 is elected leader for term 3 with votesfrom S3, S4, and itself, and accepts a different entry at logindex 2. In (c) S5 crashes; S1 restarts, is elected leader, andcontinues replication. At this point, the log entry from term 2has been replicated on a majority of the servers, but it is notcommitted. If S1 crashes as in (d), S5 could be elected leader(with votes from S2, S3, and S4) and overwrite the entry withits own entry from term 3. However, if S1 replicates an en-try from its current term on a majority of the servers beforecrashing, as in (e), then this entry is committed (S5 cannotwin an election). At this point all preceding entries in the logare committed as well.

terms are present on each new leader from the moment ofits election, without the need to transfer those entries tothe leader. This means that log entries only flow in one di-rection, from leaders to followers, and leaders never over-write existing entries in their logs.

Raft uses the voting process to prevent a candidate fromwinning an election unless its log contains all committedentries. A candidate must contact a majority of the clusterin order to be elected, which means that every committedentry must be present in at least one of those servers. If thecandidate’s log is at least as up-to-date as any other login that majority (where “up-to-date” is defined preciselybelow), then it will hold all the committed entries. TheRequestVote RPC implements this restriction: the RPCincludes information about the candidate’s log, and thevoter denies its vote if its own log is more up-to-date thanthat of the candidate.

Raft determines which of two logs is more up-to-dateby comparing the index and term of the last entries in thelogs. If the logs have last entries with different terms, thenthe log with the later term is more up-to-date. If the logsend with the same term, then whichever log is longer ismore up-to-date.

5.4.2 Committing entries from previous termsAs described in Section 5.3, a leader knows that an en-

try from its current term is committed once that entry isstored on a majority of the servers. If a leader crashes be-fore committing an entry, future leaders will attempt tofinish replicating the entry. However, a leader cannot im-mediately conclude that an entry from a previous term iscommitted once it is stored on a majority of servers. Fig-

8

Page 157: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.4. Safety

5.4.3 Safety argument

Proof

Page 158: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.5. Follower and candidate crashes

Algorithm

2 Algorithm5. The Raft consensus algorithm5.1. Raft basics5.2. Leader election5.3. Log replication5.4. Safety5.5. Follower and candidate crashes5.6. Timing and availability

Page 159: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.5. Follower and candidate crashes

Raft RPCs are idempotentRaft retries failed requests indefinitelyFollower and candidate crashes are trivially handled forfree.

Page 160: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.5. Follower and candidate crashes

Raft RPCs are idempotentRaft retries failed requests indefinitelyFollower and candidate crashes are trivially handled forfree.

Page 161: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.5. Follower and candidate crashes

Raft RPCs are idempotentRaft retries failed requests indefinitelyFollower and candidate crashes are trivially handled forfree.

Page 162: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.6. Timing and availability

Algorithm

2 Algorithm5. The Raft consensus algorithm5.1. Raft basics5.2. Leader election5.3. Log replication5.4. Safety5.5. Follower and candidate crashes5.6. Timing and availability

Page 163: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.6. Timing and availability

Timing requirement

broadcastTime << electionTimeout << MTBFbroadcastTime and MTBF are usually fixed.broadcastTime is usually dominated by disk write time,since logs are persisted to stable storage.So, electionTimeout is typically between 10ms and 500ms.

Page 164: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.6. Timing and availability

Timing requirement

broadcastTime << electionTimeout << MTBFbroadcastTime and MTBF are usually fixed.broadcastTime is usually dominated by disk write time,since logs are persisted to stable storage.So, electionTimeout is typically between 10ms and 500ms.

Page 165: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.6. Timing and availability

Timing requirement

broadcastTime << electionTimeout << MTBFbroadcastTime and MTBF are usually fixed.broadcastTime is usually dominated by disk write time,since logs are persisted to stable storage.So, electionTimeout is typically between 10ms and 500ms.

Page 166: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.6. Timing and availability

Timing requirement

broadcastTime << electionTimeout << MTBFbroadcastTime and MTBF are usually fixed.broadcastTime is usually dominated by disk write time,since logs are persisted to stable storage.So, electionTimeout is typically between 10ms and 500ms.

Page 167: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.6. Timing and availability

Timing requirement

broadcastTime << electionTimeout << MTBFbroadcastTime and MTBF are usually fixed.broadcastTime is usually dominated by disk write time,since logs are persisted to stable storage.So, electionTimeout is typically between 10ms and 500ms.

Page 168: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Algorithm

5.6. Timing and availability

Simulation

raftconsensus.github.io

Page 169: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

Outline

1 Introduction

2 Algorithm

3 Other practical concerns

4 Paper Conclusion

5 Raft issues

Page 170: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

Other practical concerns

3 Other practical concerns6. Cluster membership changes7. Log compaction8. Client interaction

Page 171: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Other practical concerns

3 Other practical concerns6. Cluster membership changes7. Log compaction8. Client interaction

Page 172: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Overall idea

Must adhere to one-leader-per-term rule during switch.Rules out any direct or atomic configuration switches.Two-phase approach uses joint-consensus: for a term thesystem uses the union of the two configurations.

Page 173: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Overall idea

Must adhere to one-leader-per-term rule during switch.Rules out any direct or atomic configuration switches.Two-phase approach uses joint-consensus: for a term thesystem uses the union of the two configurations.

Page 174: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Overall idea

Must adhere to one-leader-per-term rule during switch.Rules out any direct or atomic configuration switches.Two-phase approach uses joint-consensus: for a term thesystem uses the union of the two configurations.

Page 175: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Overall idea

Must adhere to one-leader-per-term rule during switch.Rules out any direct or atomic configuration switches.Two-phase approach uses joint-consensus: for a term thesystem uses the union of the two configurations.

Page 176: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Implementation

Uses a special configuration log entry. The latestconfiguration log entry applies regardless ofcommittedness.Once a configuration is committed it is safe to move to thenext configuration (from joint to new).

Page 177: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Implementation

Uses a special configuration log entry. The latestconfiguration log entry applies regardless ofcommittedness.Once a configuration is committed it is safe to move to thenext configuration (from joint to new).

Page 178: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Implementation

Uses a special configuration log entry. The latestconfiguration log entry applies regardless ofcommittedness.Once a configuration is committed it is safe to move to thenext configuration (from joint to new).

Page 179: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Issues

New servers might be incredibly behind - can join asnon-voting members before new configuration is appliedCurrent leader might not be part of new configuration -leaders step down after committing configuration andpossibly shouldn’t count themselves as part of the majority.Cluster can be disrupted by old nodes interferring andbecoming candidates - servers can disregard RequestVotewhen they believe a leader exists, but it’s best to get oldnodes out.

Page 180: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Issues

New servers might be incredibly behind - can join asnon-voting members before new configuration is appliedCurrent leader might not be part of new configuration -leaders step down after committing configuration andpossibly shouldn’t count themselves as part of the majority.Cluster can be disrupted by old nodes interferring andbecoming candidates - servers can disregard RequestVotewhen they believe a leader exists, but it’s best to get oldnodes out.

Page 181: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Issues

New servers might be incredibly behind - can join asnon-voting members before new configuration is appliedCurrent leader might not be part of new configuration -leaders step down after committing configuration andpossibly shouldn’t count themselves as part of the majority.Cluster can be disrupted by old nodes interferring andbecoming candidates - servers can disregard RequestVotewhen they believe a leader exists, but it’s best to get oldnodes out.

Page 182: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

6. Cluster membership changes

Issues

New servers might be incredibly behind - can join asnon-voting members before new configuration is appliedCurrent leader might not be part of new configuration -leaders step down after committing configuration andpossibly shouldn’t count themselves as part of the majority.Cluster can be disrupted by old nodes interferring andbecoming candidates - servers can disregard RequestVotewhen they believe a leader exists, but it’s best to get oldnodes out.

Page 183: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

7. Log compaction

Other practical concerns

3 Other practical concerns6. Cluster membership changes7. Log compaction8. Client interaction

Page 184: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

7. Log compaction

Snapshotting

Requires interaction with state machine and state machineserialization.Snapshot should indicate last included log index.InstallSnapshot RPC applies a snapshot to a follower whenthe follower is farther behind what the log has.

Page 185: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

7. Log compaction

Snapshotting

Requires interaction with state machine and state machineserialization.Snapshot should indicate last included log index.InstallSnapshot RPC applies a snapshot to a follower whenthe follower is farther behind what the log has.

Page 186: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

7. Log compaction

Snapshotting

Requires interaction with state machine and state machineserialization.Snapshot should indicate last included log index.InstallSnapshot RPC applies a snapshot to a follower whenthe follower is farther behind what the log has.

Page 187: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

7. Log compaction

Snapshotting

Requires interaction with state machine and state machineserialization.Snapshot should indicate last included log index.InstallSnapshot RPC applies a snapshot to a follower whenthe follower is farther behind what the log has.

Page 188: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

8. Client interaction

Other practical concerns

3 Other practical concerns6. Cluster membership changes7. Log compaction8. Client interaction

Page 189: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

8. Client interaction

Linearizability

Clients must make all operations idempotent, or attach uniqueserial numbers to all commands, in case the request is receivedbut the response is lost.

Read-only ops

Leaders should know the latest information on what entriesare committed, so at least one heartbeat or operationneeds to have happened when the leader starts.Leaders may have gotten deposed, so they need to checkwith the cluster before responding to read-only requests.

Page 190: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

8. Client interaction

Linearizability

Clients must make all operations idempotent, or attach uniqueserial numbers to all commands, in case the request is receivedbut the response is lost.

Read-only ops

Leaders should know the latest information on what entriesare committed, so at least one heartbeat or operationneeds to have happened when the leader starts.Leaders may have gotten deposed, so they need to checkwith the cluster before responding to read-only requests.

Page 191: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

8. Client interaction

Linearizability

Clients must make all operations idempotent, or attach uniqueserial numbers to all commands, in case the request is receivedbut the response is lost.

Read-only ops

Leaders should know the latest information on what entriesare committed, so at least one heartbeat or operationneeds to have happened when the leader starts.Leaders may have gotten deposed, so they need to checkwith the cluster before responding to read-only requests.

Page 192: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Other practical concerns

8. Client interaction

Linearizability

Clients must make all operations idempotent, or attach uniqueserial numbers to all commands, in case the request is receivedbut the response is lost.

Read-only ops

Leaders should know the latest information on what entriesare committed, so at least one heartbeat or operationneeds to have happened when the leader starts.Leaders may have gotten deposed, so they need to checkwith the cluster before responding to read-only requests.

Page 193: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

Outline

1 Introduction

2 Algorithm

3 Other practical concerns

4 Paper Conclusion

5 Raft issues

Page 194: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

Paper Conclusion

4 Paper Conclusion9. Implementation and evaluation10. Related work11, 12. Conclusion & Acknowledgements

Page 195: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

Paper Conclusion

4 Paper Conclusion9. Implementation and evaluation10. Related work11, 12. Conclusion & Acknowledgements

Page 196: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

9.1. Understandability

How do you measure understandability?You teach two otherwise-identical classes on Paxos andRaft, and make kids take tests!Paxos lecture: http://youtu.be/JEpsBg0AO6oRaft lecture: http://youtu.be/YbZ3zDzDnrwExams: https://ramcloud.stanford.edu/~ongaro/userstudy/quizzes.html

Page 197: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

9.1. Understandability

How do you measure understandability?You teach two otherwise-identical classes on Paxos andRaft, and make kids take tests!Paxos lecture: http://youtu.be/JEpsBg0AO6oRaft lecture: http://youtu.be/YbZ3zDzDnrwExams: https://ramcloud.stanford.edu/~ongaro/userstudy/quizzes.html

Page 198: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

9.1. Understandability

How do you measure understandability?You teach two otherwise-identical classes on Paxos andRaft, and make kids take tests!Paxos lecture: http://youtu.be/JEpsBg0AO6oRaft lecture: http://youtu.be/YbZ3zDzDnrwExams: https://ramcloud.stanford.edu/~ongaro/userstudy/quizzes.html

Page 199: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

9.1. Understandability

How do you measure understandability?You teach two otherwise-identical classes on Paxos andRaft, and make kids take tests!Paxos lecture: http://youtu.be/JEpsBg0AO6oRaft lecture: http://youtu.be/YbZ3zDzDnrwExams: https://ramcloud.stanford.edu/~ongaro/userstudy/quizzes.html

Page 200: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

9.1. Understandability

How do you measure understandability?You teach two otherwise-identical classes on Paxos andRaft, and make kids take tests!Paxos lecture: http://youtu.be/JEpsBg0AO6oRaft lecture: http://youtu.be/YbZ3zDzDnrwExams: https://ramcloud.stanford.edu/~ongaro/userstudy/quizzes.html

Page 201: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

9.1. Understandability

How do you measure understandability?You teach two otherwise-identical classes on Paxos andRaft, and make kids take tests!Paxos lecture: http://youtu.be/JEpsBg0AO6oRaft lecture: http://youtu.be/YbZ3zDzDnrwExams: https://ramcloud.stanford.edu/~ongaro/userstudy/quizzes.html

Page 202: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

How’d they do?

0

10

20

30

40

50

60

0 10 20 30 40 50 60

Raf

t gra

de

Paxos grade

Raft then PaxosPaxos then Raft

Figure 14: A scatter plot comparing 43 participants’ perfor-mance on the Raft and Paxos quizzes. Points above the diag-onal (33) represent participants who scored higher for Raft.

lecture covered enough material to create an equivalentreplicated state machine, including single-decree Paxos,multi-decree Paxos, reconfiguration, and a few optimiza-tions needed in practice (such as leader election). Thequizzes tested basic understanding of the algorithms andalso required students to reason about corner cases. Eachstudent watched one video, took the corresponding quiz,watched the second video, and took the second quiz.About half of the participants did the Paxos portion firstand the other half did the Raft portion first in order toaccount for both individual differences in performanceand experience gained from the first portion of the study.We compared participants’ scores on each quiz to deter-mine whether participants showed a better understandingof Raft.

We tried to make the comparison between Paxos andRaft as fair as possible. The experiment favored Paxos intwo ways: 15 of the 43 participants reported having someprior experience with Paxos, and the Paxos video is 14%longer than the Raft video. As summarized in Table 1, wehave taken steps to mitigate potential sources of bias. Allof our materials are available for review [28, 31].

On average, participants scored 4.9 points higher on theRaft quiz than on the Paxos quiz (out of a possible 60points, the mean Raft score was 25.7 and the mean Paxosscore was 20.8); Figure 14 shows their individual scores.A paired t-test states that, with 95% confidence, the truedistribution of Raft scores has a mean at least 2.5 pointslarger than the true distribution of Paxos scores.

We also created a linear regression model that predictsa new student’s quiz scores based on three factors: whichquiz they took, their degree of prior Paxos experience, and

0

5

10

15

20

implement explain

num

ber o

f par

ticip

ants

Paxos much easierPaxos somewhat easierRoughly equalRaft somewhat easierRaft much easier

Figure 15: Using a 5-point scale, participants were asked(left) which algorithm they felt would be easier to implementin a functioning, correct, and efficient system, and (right)which would be easier to explain to a CS graduate student.

the order in which they learned the algorithms. The modelpredicts that the choice of quiz produces a 12.5-point dif-ference in favor of Raft. This is significantly higher thanthe observed difference of 4.9 points, because many of theactual students had prior Paxos experience, which helpedPaxos considerably, whereas it helped Raft slightly less.Curiously, the model also predicts scores 6.3 points loweron Raft for people that have already taken the Paxos quiz;although we don’t know why, this does appear to be sta-tistically significant.

We also surveyed participants after their quizzes to seewhich algorithm they felt would be easier to implementor explain; these results are shown in Figure 15. An over-whelming majority of participants reported Raft would beeasier to implement and explain (33 of 41 for each ques-tion). However, these self-reported feelings may be lessreliable than participants’ quiz scores, and participantsmay have been biased by knowledge of our hypothesisthat Raft is easier to understand.

A detailed discussion of the Raft user study is availableat [31].

9.2 CorrectnessWe have developed a formal specification and a proof

of safety for the consensus mechanism described in Sec-tion 5. The formal specification [31] makes the informa-tion summarized in Figure 2 completely precise using theTLA+ specification language [17]. It is about 400 lineslong and serves as the subject of the proof. It is also use-ful on its own for anyone implementing Raft. We havemechanically proven the Log Completeness Property us-ing the TLA proof system [7]. However, this proof relieson invariants that have not been mechanically checked(for example, we have not proven the type safety of thespecification). Furthermore, we have written an informalproof [31] of the State Machine Safety property whichis complete (it relies on the specification alone) and rela-

Concern Steps taken to mitigate bias Materials for review [28, 31]Equal lecture quality Same lecturer for both. Paxos lecture based on and improved from exist-

ing materials used in several universities. Paxos lecture is 14% longer.videos

Equal quiz difficulty Questions grouped in difficulty and paired across exams. quizzesFair grading Used rubric. Graded in random order, alternating between quizzes. rubric

Table 1: Concerns of possible bias against Paxos in the study, steps taken to counter each, and additional materials available.

14

0

10

20

30

40

50

60

0 10 20 30 40 50 60

Raf

t gra

de

Paxos grade

Raft then PaxosPaxos then Raft

Figure 14: A scatter plot comparing 43 participants’ perfor-mance on the Raft and Paxos quizzes. Points above the diag-onal (33) represent participants who scored higher for Raft.

lecture covered enough material to create an equivalentreplicated state machine, including single-decree Paxos,multi-decree Paxos, reconfiguration, and a few optimiza-tions needed in practice (such as leader election). Thequizzes tested basic understanding of the algorithms andalso required students to reason about corner cases. Eachstudent watched one video, took the corresponding quiz,watched the second video, and took the second quiz.About half of the participants did the Paxos portion firstand the other half did the Raft portion first in order toaccount for both individual differences in performanceand experience gained from the first portion of the study.We compared participants’ scores on each quiz to deter-mine whether participants showed a better understandingof Raft.

We tried to make the comparison between Paxos andRaft as fair as possible. The experiment favored Paxos intwo ways: 15 of the 43 participants reported having someprior experience with Paxos, and the Paxos video is 14%longer than the Raft video. As summarized in Table 1, wehave taken steps to mitigate potential sources of bias. Allof our materials are available for review [28, 31].

On average, participants scored 4.9 points higher on theRaft quiz than on the Paxos quiz (out of a possible 60points, the mean Raft score was 25.7 and the mean Paxosscore was 20.8); Figure 14 shows their individual scores.A paired t-test states that, with 95% confidence, the truedistribution of Raft scores has a mean at least 2.5 pointslarger than the true distribution of Paxos scores.

We also created a linear regression model that predictsa new student’s quiz scores based on three factors: whichquiz they took, their degree of prior Paxos experience, and

0

5

10

15

20

implement explain

num

ber o

f par

ticip

ants

Paxos much easierPaxos somewhat easierRoughly equalRaft somewhat easierRaft much easier

Figure 15: Using a 5-point scale, participants were asked(left) which algorithm they felt would be easier to implementin a functioning, correct, and efficient system, and (right)which would be easier to explain to a CS graduate student.

the order in which they learned the algorithms. The modelpredicts that the choice of quiz produces a 12.5-point dif-ference in favor of Raft. This is significantly higher thanthe observed difference of 4.9 points, because many of theactual students had prior Paxos experience, which helpedPaxos considerably, whereas it helped Raft slightly less.Curiously, the model also predicts scores 6.3 points loweron Raft for people that have already taken the Paxos quiz;although we don’t know why, this does appear to be sta-tistically significant.

We also surveyed participants after their quizzes to seewhich algorithm they felt would be easier to implementor explain; these results are shown in Figure 15. An over-whelming majority of participants reported Raft would beeasier to implement and explain (33 of 41 for each ques-tion). However, these self-reported feelings may be lessreliable than participants’ quiz scores, and participantsmay have been biased by knowledge of our hypothesisthat Raft is easier to understand.

A detailed discussion of the Raft user study is availableat [31].

9.2 CorrectnessWe have developed a formal specification and a proof

of safety for the consensus mechanism described in Sec-tion 5. The formal specification [31] makes the informa-tion summarized in Figure 2 completely precise using theTLA+ specification language [17]. It is about 400 lineslong and serves as the subject of the proof. It is also use-ful on its own for anyone implementing Raft. We havemechanically proven the Log Completeness Property us-ing the TLA proof system [7]. However, this proof relieson invariants that have not been mechanically checked(for example, we have not proven the type safety of thespecification). Furthermore, we have written an informalproof [31] of the State Machine Safety property whichis complete (it relies on the specification alone) and rela-

Concern Steps taken to mitigate bias Materials for review [28, 31]Equal lecture quality Same lecturer for both. Paxos lecture based on and improved from exist-

ing materials used in several universities. Paxos lecture is 14% longer.videos

Equal quiz difficulty Questions grouped in difficulty and paired across exams. quizzesFair grading Used rubric. Graded in random order, alternating between quizzes. rubric

Table 1: Concerns of possible bias against Paxos in the study, steps taken to counter each, and additional materials available.

14

Page 203: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

9.2. Correctness

They wrote proofs! See citations.

Page 204: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

9. Implementation and evaluation

9.3. Performance

0%

20%

40%

60%

80%

100%

100 1000 10000 100000

cum

ulat

ive

perc

ent

150-150ms150-151ms150-155ms150-175ms150-200ms150-300ms

0%

20%

40%

60%

80%

100%

0 100 200 300 400 500 600

cum

ulat

ive

perc

ent

time without leader (ms)

12-24ms25-50ms

50-100ms100-200ms150-300ms

Figure 16: The time to detect and replace a crashed leader.The top graph varies the amount of randomness in electiontimeouts, and the bottom graph scales the minimum electiontimeout. Each line represents 1000 trials (except for 100 tri-als for “150–150ms”) and corresponds to a particular choiceof election timeouts; for example, “150–155ms” means thatelection timeouts were chosen randomly and uniformly be-tween 150ms and 155ms. The measurements were taken on acluster of five servers with a broadcast time of roughly 15ms.Results for a cluster of nine servers are similar.

tively precise (it is about 3500 words long).

9.3 PerformanceRaft’s performance is similar to other consensus algo-

rithms such as Paxos. The most important case for per-formance is when an established leader is replicating newlog entries. Raft achieves this using the minimal numberof messages (a single round-trip from the leader to half thecluster). It is also possible to further improve Raft’s per-formance. For example, it easily supports batching andpipelining requests for higher throughput and lower la-tency. Various optimizations have been proposed in theliterature for other algorithms; many of these could be ap-plied to Raft, but we leave this to future work.

We used our Raft implementation to measure the per-formance of Raft’s leader election algorithm and answertwo questions. First, does the election process convergequickly? Second, what is the minimum downtime that canbe achieved after leader crashes?

To measure leader election, we repeatedly crashed theleader of a cluster of five servers and timed how long ittook to detect the crash and elect a new leader (see Fig-ure 16). To generate a worst-case scenario, the servers ineach trial had different log lengths, so some candidateswere not eligible to become leader. Furthermore, to en-courage split votes, our test script triggered a synchro-nized broadcast of heartbeat RPCs from the leader beforeterminating its process (this approximates the behaviorof the leader replicating a new log entry prior to crash-

ing). The leader was crashed uniformly randomly withinits heartbeat interval, which was half of the minimumelection timeout for all tests. Thus, the smallest possibledowntime was about half of the minimum election time-out.

The top graph in Figure 16 shows that a small amountof randomization in the election timeout is enough toavoid split votes in elections. In the absence of random-ness, leader election consistently took longer than 10 sec-onds in our tests due to many split votes. Adding just 5msof randomness helps significantly, resulting in a mediandowntime of 287ms. Using more randomness improvesworst-case behavior: with 50ms of randomness the worst-case completion time (over 1000 trials) was 513ms.

The bottom graph in Figure 16 shows that downtimecan be reduced by reducing the election timeout. Withan election timeout of 12–24ms, it takes only 35ms onaverage to elect a leader (the longest trial took 152ms).However, lowering the timeouts beyond this point violatesRaft’s timing requirement: leaders have difficulty broad-casting heartbeats before other servers start new elections.This can cause unnecessary leader changes and loweroverall system availability. We recommend using a con-servative election timeout such as 150–300ms; such time-outs are unlikely to cause unnecessary leader changes andwill still provide good availability.

10 Related workThere have been numerous publications related to con-

sensus algorithms, many of which fall into one of the fol-lowing categories:• Lamport’s original description of Paxos [15], and at-

tempts to explain it more clearly [16, 20, 21].• Elaborations of Paxos, which fill in missing details

and modify the algorithm to provide a better founda-tion for implementation [26, 39, 13].

• Systems that implement consensus algorithms, suchas Chubby [2, 4], ZooKeeper [11, 12], and Span-ner [6]. The algorithms for Chubby and Spannerhave not been published in detail, though both claimto be based on Paxos. ZooKeeper’s algorithm hasbeen published in more detail, but it is quite differentfrom Paxos.

• Performance optimizations that can be applied toPaxos [18, 19, 3, 25, 1, 27].

• Oki and Liskov’s Viewstamped Replication (VR), analternative approach to consensus developed aroundthe same time as Paxos. The original description [29]was intertwined with a protocol for distributed trans-actions, but the core consensus protocol has beenseparated in a recent update [22]. VR uses a leader-based approach with many similarities to Raft.

The greatest difference between Raft and Paxos isRaft’s strong leadership: Raft uses leader election as anessential part of the consensus protocol, and it concen-

15

Page 205: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Paper Conclusion

4 Paper Conclusion9. Implementation and evaluation10. Related work11, 12. Conclusion & Acknowledgements

Page 206: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Categories of related work

PaxosImplementations of PaxosImplementations of consensus systems (Chubby,ZooKeeper, Spanner, etc)Performance improvements for PaxosViewstamped Replication - similar to Raft, about as old asPaxos.

Page 207: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Categories of related work

PaxosImplementations of PaxosImplementations of consensus systems (Chubby,ZooKeeper, Spanner, etc)Performance improvements for PaxosViewstamped Replication - similar to Raft, about as old asPaxos.

Page 208: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Categories of related work

PaxosImplementations of PaxosImplementations of consensus systems (Chubby,ZooKeeper, Spanner, etc)Performance improvements for PaxosViewstamped Replication - similar to Raft, about as old asPaxos.

Page 209: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Categories of related work

PaxosImplementations of PaxosImplementations of consensus systems (Chubby,ZooKeeper, Spanner, etc)Performance improvements for PaxosViewstamped Replication - similar to Raft, about as old asPaxos.

Page 210: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Categories of related work

PaxosImplementations of PaxosImplementations of consensus systems (Chubby,ZooKeeper, Spanner, etc)Performance improvements for PaxosViewstamped Replication - similar to Raft, about as old asPaxos.

Page 211: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Categories of related work

PaxosImplementations of PaxosImplementations of consensus systems (Chubby,ZooKeeper, Spanner, etc)Performance improvements for PaxosViewstamped Replication - similar to Raft, about as old asPaxos.

Page 212: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Comparisons

Raft’s leader-based approach is touted as better thanPaxos (leadership in Paxos is only a performanceoptimization)VR and ZooKeeper are also leaderbased, but are morecomplicated (you can add log entries during elections, etc)Raft has less message-types in general.Egalitarian Paxos can be faster under certain conditionsdue to lack of leader.Cluster membership changes have a variety ofapproaches, but Raft’s played to its own strengths.

Page 213: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Comparisons

Raft’s leader-based approach is touted as better thanPaxos (leadership in Paxos is only a performanceoptimization)VR and ZooKeeper are also leaderbased, but are morecomplicated (you can add log entries during elections, etc)Raft has less message-types in general.Egalitarian Paxos can be faster under certain conditionsdue to lack of leader.Cluster membership changes have a variety ofapproaches, but Raft’s played to its own strengths.

Page 214: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Comparisons

Raft’s leader-based approach is touted as better thanPaxos (leadership in Paxos is only a performanceoptimization)VR and ZooKeeper are also leaderbased, but are morecomplicated (you can add log entries during elections, etc)Raft has less message-types in general.Egalitarian Paxos can be faster under certain conditionsdue to lack of leader.Cluster membership changes have a variety ofapproaches, but Raft’s played to its own strengths.

Page 215: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Comparisons

Raft’s leader-based approach is touted as better thanPaxos (leadership in Paxos is only a performanceoptimization)VR and ZooKeeper are also leaderbased, but are morecomplicated (you can add log entries during elections, etc)Raft has less message-types in general.Egalitarian Paxos can be faster under certain conditionsdue to lack of leader.Cluster membership changes have a variety ofapproaches, but Raft’s played to its own strengths.

Page 216: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Comparisons

Raft’s leader-based approach is touted as better thanPaxos (leadership in Paxos is only a performanceoptimization)VR and ZooKeeper are also leaderbased, but are morecomplicated (you can add log entries during elections, etc)Raft has less message-types in general.Egalitarian Paxos can be faster under certain conditionsdue to lack of leader.Cluster membership changes have a variety ofapproaches, but Raft’s played to its own strengths.

Page 217: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

10. Related work

Comparisons

Raft’s leader-based approach is touted as better thanPaxos (leadership in Paxos is only a performanceoptimization)VR and ZooKeeper are also leaderbased, but are morecomplicated (you can add log entries during elections, etc)Raft has less message-types in general.Egalitarian Paxos can be faster under certain conditionsdue to lack of leader.Cluster membership changes have a variety ofapproaches, but Raft’s played to its own strengths.

Page 218: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Paper Conclusion

11, 12. Conclusion & Acknowledgements

Paper Conclusion

4 Paper Conclusion9. Implementation and evaluation10. Related work11, 12. Conclusion & Acknowledgements

Page 219: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Outline

1 Introduction

2 Algorithm

3 Other practical concerns

4 Paper Conclusion

5 Raft issues

Page 220: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Raft issues

5 Raft issues

Page 221: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Load balancing

Every server must completely manage its own statemachine.Every request must go through the leader.Doesn’t horizontally scale well.

Page 222: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Load balancing

Every server must completely manage its own statemachine.Every request must go through the leader.Doesn’t horizontally scale well.

Page 223: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Load balancing

Every server must completely manage its own statemachine.Every request must go through the leader.Doesn’t horizontally scale well.

Page 224: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Load balancing

Every server must completely manage its own statemachine.Every request must go through the leader.Doesn’t horizontally scale well.

Page 225: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Byzantine failures

You trust all your servers, but one gets hacked.You trust all your servers, but they’re on an insecurenetwork.You don’t trust some of your servers.You don’t trust all of your servers.Bitcoin comparison?

Discussion

How can you hack a Raft cluster?

Page 226: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Byzantine failures

You trust all your servers, but one gets hacked.You trust all your servers, but they’re on an insecurenetwork.You don’t trust some of your servers.You don’t trust all of your servers.Bitcoin comparison?

Discussion

How can you hack a Raft cluster?

Page 227: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Byzantine failures

You trust all your servers, but one gets hacked.You trust all your servers, but they’re on an insecurenetwork.You don’t trust some of your servers.You don’t trust all of your servers.Bitcoin comparison?

Discussion

How can you hack a Raft cluster?

Page 228: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Byzantine failures

You trust all your servers, but one gets hacked.You trust all your servers, but they’re on an insecurenetwork.You don’t trust some of your servers.You don’t trust all of your servers.Bitcoin comparison?

Discussion

How can you hack a Raft cluster?

Page 229: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Byzantine failures

You trust all your servers, but one gets hacked.You trust all your servers, but they’re on an insecurenetwork.You don’t trust some of your servers.You don’t trust all of your servers.Bitcoin comparison?

Discussion

How can you hack a Raft cluster?

Page 230: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Byzantine failures

You trust all your servers, but one gets hacked.You trust all your servers, but they’re on an insecurenetwork.You don’t trust some of your servers.You don’t trust all of your servers.Bitcoin comparison?

Discussion

How can you hack a Raft cluster?

Page 231: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Byzantine failures

You trust all your servers, but one gets hacked.You trust all your servers, but they’re on an insecurenetwork.You don’t trust some of your servers.You don’t trust all of your servers.Bitcoin comparison?

Discussion

How can you hack a Raft cluster?

Page 232: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Byzantine failures

You trust all your servers, but one gets hacked.You trust all your servers, but they’re on an insecurenetwork.You don’t trust some of your servers.You don’t trust all of your servers.Bitcoin comparison?

Discussion

How can you hack a Raft cluster?

Page 233: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Other problems?

Can Raft be made to work in a distributed system whenpeers are constantly leaving and joining?Anything else?

Page 234: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Other problems?

Can Raft be made to work in a distributed system whenpeers are constantly leaving and joining?Anything else?

Page 235: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Raft issues

Other problems?

Can Raft be made to work in a distributed system whenpeers are constantly leaving and joining?Anything else?

Page 236: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Meetup Wrap-up

Shameless plug

Page 237: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Meetup Wrap-up

Shameless plug

Space Monkey!

Distributed Hash TablesConsensus algorithmsReed SolomonMonitoring and sooo much dataSecurity and cryptography engineering

Page 238: Utah Distributed Systems Meetup and Reading Group - Raft · Raft Introduction Abstract Raft is a consensus algorithm for managing a replicated log. Equivalent to Paxos in operation,

Raft

Meetup Wrap-up

Shameless plug

Space Monkey!

Come work with us!