Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud....

86
Consistency without consensus: CRDTs in production at SoundCloud

Transcript of Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud....

Page 1: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Consistency without consensus: CRDTs in production at SoundCloud

Page 2: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Consistency without consensus: CRDTs in production at SoundCloud

Page 3: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Me

Some guy Embedded, sensor networks

Distributed systems SoundCloud infrastructure

Page 4: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Theory

Page 5: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Distributed programming

“The art of solving the same problem that you can solve on a single computer

using multiple computers.” —book.mixu.net

Page 6: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Distributed programming

“Generally a bad idea, best avoided.”

—me

Page 7: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

>>> x = 1

>>> print x

1

Page 8: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

$ curl -XPOST -d'{"val": 1}' http://db/vars/x

HTTP 502 Bad Gateway

$ curl -XGET http://db/vars/x

HTTP 503 Service Unavailable

Page 9: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Idioms

Page 10: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

1980s — RPC

Page 11: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

1990s — CORBA

Page 12: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

2000 — CAP

Page 13: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Partition tolerance

“The system continues to operate despite message loss due to network

and/or node failure.” —book.mixu.net

Page 14: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Partitiontolerance

Consistency Availability

CP AP

Page 15: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

CPChubby, Doozer — Paxos

ZooKeeper — Zab

Consul, etcd — Raft

? — Viewstamped Replication

Page 16: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

APCassandra

Riak

Mongo

Couch

Page 17: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Message failureDelayed

Dropped

Delivered out-of-order

Duplicated

Page 18: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

CALM principleConsistency

As

Logical

Monotonicity

Page 19: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

ACID 2.0Associative

Commutative

Idempotent

Distributed, sure, whatever

Page 20: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

CRDTConflict-free

Replicated

Data

Type

Page 21: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Increment-onlycounter

Page 22: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

A'

A → A'

Page 23: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

+

(1 + 2) + 3 = 1 + (2 + 3)

1 + 2 = 2 + 1

1 + 1 ≠ 1

Page 24: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

( 1 ∪ 2 ) ∪ 3 = 1 ∪ ( 2 ∪ 3 )

1 ∪ 2 = 2 ∪ 1

1 ∪ 1 = 1

Page 25: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }

Page 26: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }

123

Page 27: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123

Page 28: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123

Page 29: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123

123

Page 30: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123

123

Page 31: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123

123456

Page 32: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123

123, 456456

Page 33: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123

123, 456

Page 34: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123, 456

123, 456

Page 35: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123, 456

123, 456

Page 36: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Read

{123, 456} ∪ {123} ∪ {123, 456} = {123, 456}

{123, 456} ∆ {123} ∆ {123, 456} = {456}

Page 37: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123

123, 456

123, 456

456

Page 38: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123, 456

123, 456

123, 456

Page 39: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123, 456

123, 456

123, 456

Page 40: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

{ }{ }

{ }123, 456

123, 456

123, 456

Page 41: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Interlude — Bending the problem

Page 42: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

CRDTs in production

Page 43: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,
Page 44: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

EventTimestamp

Actor

Verb

Thing

Page 45: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Event2014-04-01T15:16:17.187Z

snoopdogg

reposted

theeconomist/election-day

Page 46: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Fan out on write

༼⍢༽ ●

●●●● (•ི̛ᴗ•̛)ྀ

●●● ༼•͟ ͜ •༽

●●●●● (ಠ_ಠ)

Page 47: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Fan in on read

༼⍢༽ •••••

(•ི̛ᴗ•̛)ྀ

༼•͟ ͜ •༽

(ಠ_ಠ)

[¬º-°] •••

••••••

Page 48: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Unique events — use a set

G-set — can’t delete

2P-set — add, remove once

OR-set — storage overhead

Page 49: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

A wild set appears

Page 50: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Roshi set

S+ { A/1 B/2 C/3 }

S– { D/4 }

S { A B C }

Page 51: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Roshi setS = actor’s outbox keysnoopdogg·outbox

A/B/C/D = actor+verb+thingsnoopdogg·repost·theeconomist/election-day

1/2/3 = timestamp2014-04-01T15:16:17.187Z

Page 52: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Reading is easy

Page 53: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Writing is interesting

Page 54: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Insert• If either key+ or key– already contains element,

and the existing score >= score,no-op and exit.

• Insert (element, score) into add set key+.

• Delete (element) from remove set key–.

Page 55: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Delete• If either key+ or key– already contains element,

and the existing score >= score,no-op and exit.

• Insert (element, score) into add set key–.

• Delete (element) from remove set key+.

Page 56: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Example

Page 57: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 }

S– { C/3 }

Page 58: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 }

S– { C/3 }

Insert D/4

Page 59: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Insert D/4

Page 60: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Page 61: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Insert D/4

Page 62: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Insert D/4

Page 63: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Page 64: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Delete D/3

Page 65: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Delete D/3

Page 66: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Page 67: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 }

Delete D/5

Page 68: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 D/4 }

S– { C/3 D/5 }

Delete D/5

Page 69: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 }

S– { C/3 D/5 }

Page 70: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 }

S– { C/3 D/5 }

Delete D/6

Page 71: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 }

S– { C/3 D/6 }

Delete D/6

Page 72: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

S+ { A/1 B/2 }

S– { C/3 D/6 }

Page 73: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Making it real

Page 74: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,
Page 75: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

PoolCluster

Page 76: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

PoolCluster

PoolCluster

PoolCluster

Farm

Page 77: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Writing is easy

Page 78: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Reading is interesting

Page 79: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

PoolCluster

PoolCluster

PoolCluster

Farm

Page 80: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

PoolCluster

PoolCluster

PoolCluster

Farm

Page 81: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

ClusterCluster Cluster

{A B C} {A C} {A B C}

∪ = {A B C}

∆ = {B}

Page 82: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

PoolCluster

PoolCluster

PoolCluster

Farm

Page 83: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

github.com/soundcloud/roshi

Page 84: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

In conclusion,

Page 85: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Consistency without consensus = CRDT.

Embrace your invariants.

Maybe bend your problem, not your solution.

Page 86: Consistency without consensus: CRDTs in production at ... · CRDTs in production at SoundCloud. Consistency without consensus: CRDTs in production at SoundCloud. Me Some guy Embedded,

Thanks!

soundcloud.com/jobs@peterbourgon

☞ ☜