KEMBAR78
Paxos and Raft Distributed Consensus Algorithm | PDF
Paxos &	Raft
Distributed	Consensus	Algorithm
Eric	FU			2017-5-11
Leslie	Lamport
• Lamport is	best	known	for	his	seminal	work	
in distributed	systems and	as	the	initial	
developer	of	the	document	preparation	
system LaTeX
• Microsoft	Research
• New	York
Paxos
• Processors	operate	at	arbitrary	speed.
• Processors	may	experience	failures.
• Processors	can	send	messages	to	any	other	processor.
• Messages	are	sent	asynchronously	and	may	take	
arbitrarily	long	to	deliver.
• Messages	may	be	lost,	reordered,	or	duplicated.
• Messages	are	delivered	without	corruption
There is only one consensus protocol, and that's Paxos –
all other approaches are just broken versions of Paxos
– Mike Burrows
Concept
Roles
• Proposer
• Acceptor
• Learner
Quorums
• {A,B,C},	{A,C,D},	{A,B,D},	{B,C,D}	
while	U	=	{A,B,C,D}
Proposal	Number:	N
Agreed	Value:	V
Phase	1
a) A	proposer	selects	a	proposal	number	n and	sends	a	prepare	
request	with	number	n	to	a	majority	of	acceptors.
b) If	an	acceptor	receives	a	prepare	request	with	number	n greater	
than	that	of	any	prepare	request	to	which	it	has	already	responded,	
then	it	responds	to	the	request	with	a	promise	not	to	accept	any	
more	proposals	numbered	less	than	n and	with	the	highest-
numbered	proposal	(if	any)	that	it	has	accepted.
Phase	1
Phase	2
a) If	the	proposer	receives	a	response	to	its	prepare	requests	
(numbered	n)	from	a	majority	of	acceptors,	then	it	sends	an	accept	
request	to	each	of	those	acceptors	for	a	proposal	numbered	n	with	
a	value	v ,	where	v is	the	value	of	the	highest-numbered	proposal	
among	the	responses,	or	is	any	value	if	the	responses	reported	no	
proposals.
b) If	an	acceptor	receives	an	accept	request	for	a	proposal	numbered	
n,	it	accepts	the	proposal	unless	it	has	already	responded	to	a	
prepare	request	having	a	number	greater	than	n.
Phase	2
Demo!
https://github.com/renquinn/Paxos-Demo
Raft
• Raft	is	a	consensus	algorithm	that	is	
designed	to	be	easy	to	understand
• equivalent	to	Paxos in	fault-tolerance	
and	performance
• Decomposed	into	relatively	
independent	subproblems
• cleanly	addresses	all	major	pieces	
needed	for	practical	systems.
Replicated	State	Machine
• Replicated	state	machines	are	
typically	implemented	using	a	
replicated	log
• The	consensus	module	on	a	
server	receives	commands	from	
clients	and	adds	them	to	its	log
• Once	commands	are	properly	
replicated,	each	server’s	state	
machine	processes	them	in	log	
order
Subproblems
• Leader	election:	a	new	leader	must	be	chosen	when	an	existing	
leader	fails.
• Log	replication:	the	leader	must	accept	log	entries	
• Safety:	if	any	server	has	applied	a	particular	log	entry	to	its	state	
machine,	then	no	other	server	may	apply	a	different	command	for	
the	same	log	index.
Leader	Election
Log	Replication
Demo!
http://thesecretlivesofdata.com/raft/
Thanks!

Paxos and Raft Distributed Consensus Algorithm