Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false...

71
Bloom: Big Systems, Small Programs Neil Conway UC Berkeley

Transcript of Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false...

Page 1: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Bloom:

Big Systems, Small Programs

Neil Conway UC Berkeley

Page 2: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Distributed Computing

Page 3: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Programming Languages

Page 4: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Optimization

Loop unrolling

Register allocation

Data prefetching

Function inlining

Global coordination, waiting

Caching, indexing

Replication, data locality

Partitioning, load balancing

Page 5: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Warnings

Undeclared variables

Type mismatches

Sign conversion mistakes

Replica divergence

Inconsistent state

Deadlocks

Race conditions

Page 6: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Debugging

Stack traces

Log files, printf

gdb  

Full stack visualization, analytics

Consistent global snapshots

Provenance analysis

Page 7: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Developer productivity is a major unsolved problem in distributed computing.

Page 8: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

We can do better! … provided we’re willing to make changes.

Page 9: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Design Principles

Page 10: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,
Page 11: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Centralized Computing

•  Predictable latency •  No partial failure •  Single clock •  Global event order

Page 12: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Taking Order For Granted

Data (Ordered) array of bytes

Compute (Ordered) sequence of instructions

Global event order

Page 13: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Distributed Computing

•  Unpredictable latency •  Partial failures •  No global event order

WAN

DCDC

DC DC

Page 14: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Alternative #1: Enforce global event order at all nodes (“Strong Consistency”)

Page 15: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Alternative #1: Enforce global event order at all nodes (“Strong Consistency”) Problems: •  Availability (CAP) •  Latency

Page 16: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Alternative #2: Ensure correct behavior for any network order (“Weak Consistency”)

Page 17: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Alternative #2: Ensure correct behavior for any network order (“Weak Consistency”) Problem: With traditional languages, this is very difficult.

Page 18: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

The “ACID 2.0” Pattern

Associativity:

X ○ (Y ○ Z) = (X ○ Y) ○ Z “batch tolerance”

Commutativity:

X ○ Y = Y ○ X “reordering tolerance”

Idempotence:

X ○ X = X “retry tolerance”

Page 19: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

“When I see patterns in my programs, I consider it a sign of trouble … [they are a sign] that I'm using abstractions that aren't powerful enough.”

—Paul Graham

Design Patterns

Theorems

Language & Tool Support

Page 20: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Bounded Join Semilattices

A triple hS,t,?i such that: – S is a set – t is a binary operator

(“least upper bound”) •  Induces a partial order on

S: x ·S y if x t y = y •  Associative, Commutative,

and Idempotent

– 8x 2 S: ? t x = x

Page 21: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Bounded Join Semilattices

Lattices are objects that grow over time. An interface with an ACID 2.0 merge() method – Associative – Commutative –  Idempotent

Page 22: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Time

Set (Merge = Union)

Increasing Int (Merge = Max)

Boolean (Merge = Or)

{a}{b} {c}

{a,b} {b,c} {a,c}

{a,b,c}

5

5 7

7

3 7 false false

false

true

true

true

Page 23: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

CRDTs: Convergent Replicated Data Types – e.g., registers, counters,

sets, graphs, trees

Implementations: – Statebox – Knockbox – riak_dt

Page 24: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Lattices represent disorderly data. How can we represent disorderly computation?

Page 25: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

f : S→T is a monotone function iff: 8a,b 2 S : a ·S b ) f(a) ·T f(b)

Page 26: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Time

Set (Merge = Union)

Increasing Int (Merge = Max)

Boolean (Merge = Or)

size() >= 3

Monotone function: set → increase-int

Monotone function: increase-int → boolean

{a}{b} {c}

{a,b} {b,c} {a,c}

{a,b,c}

2

3

1

false

true

false

Page 27: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Consistency As Logical Monotonicity

Page 28: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Asynchronous Messaging

Lattices + Monotone

Logic

No Risk ofInconsistency

Page 29: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Asynchronous Messaging

Non-Monotone

Logic

PossibleInconsistency

Insert Coordination (Paxos, Zk, …)

Page 30: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Asynchronous Messaging

Non-Monotone

Logic

PossibleInconsistency

Insert Coordination (Paxos, Zk, …)

Page 31: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Case Study

Page 32: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Client

Cart Replica

Cart Replica

Cart Replica

Add/RemoveItems

CheckoutRequest

LazyReplication

CheckoutResponse

Page 33: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Client

Cart Replica

Cart Replica

Cart Replica

ADD{! : 2," : 1}

Page 34: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Client

Cart Replica

Cart Replica

Cart Replica

ADD{! : 2, " : 1}

Page 35: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Client

Cart

Replica

Cart

Replica

Cart

Replica

REMOVE

{! : 1}

Page 36: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Client

Cart Replica

Cart Replica

Cart Replica

CHECKOUTREQUEST

RESPONSE

Page 37: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Questions

1.  Will cart replicas eventually converge? –  “Eventual Consistency”

2.  What will client observe on checkout? –  Goal: checkout reflects all session activity

3.  To achieve #1 and #2, how much ordering is required?

Page 38: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

if  kvs[x]  exists:      old  =  kvs[x]      kvs.delete(x)      if  old  >  c          kvs[x]  =  old  –  c  

if  kvs[x]  exists:      old  =  kvs[x]      kvs.delete(x)  else      old  =  0  kvs[x]  =  old  +  c  

Design #1: Mutable State

Add(item x, count c): Remove(item x, count c):

Non-monotonic!

Page 39: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Client

Cart Replica

Cart Replica

Cart Replica

Add/RemoveItems

CheckoutRequest

LazyReplication

Conclusion: Every operation might require coordination!

Non-monotonic!

Page 40: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Design #2: “Disorderly”

Add(item x, count c):

Add  x,c  to  add_log  

Remove(item x, count c):

Add  x,c  to  del_log  

Checkout():

Group  add_log  by  item  ID;  sum  counts.    Group  del_log  by  item  ID;  sum  counts.    For  each  item,  subtract  deletes  from  adds.  Non-monotonic!

Page 41: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Client

Cart Replica

Cart Replica

Cart Replica

Add/RemoveItems

CheckoutRequest

LazyReplication

Conclusion: Replication is safe; might need to coordinate on checkout

Monotonic

Page 42: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Takeaways

•  Avoid: mutable state update Prefer: immutable data, monotone growth

•  Major difference in coordination cost! – Coordinate once per operation vs.

Coordinate once per checkout

•  We’d like a type system for monotonicity

Page 43: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Language Design

Page 44: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Disorderly Programming

•  Order-independent: default

•  Order dependencies: explicit

•  Order as part of the design process

•  Tool support – Where is order

needed? Why?

Page 45: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

The Disorderly Spectrum

ASM

C

Java

Lisp, ML

Haskell

SQL, LINQ, Datalog

Bloom

High-level “Declarative” Powerful optimizers

Page 46: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Bloom ≈ declarative agents

Processes that communicate via asynchronous message passing

Each process has a local database

Logical rules describe computation and communication (“SQL++”)

Page 47: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Each agent has a database of values that changes over time. All values have a location and timestamp.

Page 48: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

left-hand-side <= right-hand-side

If RHS is true (SELECT  …)

Then LHS is true (INTO  lhs)

When and where is the LHS true?

Page 49: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Temporal Operators

1.  Same location, same timestamp

2.  Same location, next timestamp

3.  Different location, non-deterministic timestamp

<=  

<+  <-­‐  

<~  

Computation

Persistence Deletion

Communication

Page 50: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Bloom Rulesatomic, local, deterministic

ReceiveNetwork

Messages

EmitNetwork

Messages

Apply State Updates

Observe Compute Act

Page 51: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Our First Program: PubSub

Page 52: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Publisher

Publisher

Hub

Subscriber

Subscriber

Subscriber

Page 53: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  Hub      include  Bud        state  do          channel  :subscribe,  [:@addr,  :topic,  :client]          channel  :pub,              [:@addr,  :topic,  :val]          channel  :event,          [:@addr,  :topic,  :val]          table      :sub,              [:addr,  :topic]      end        bloom  do          sub      <=  subscribe  {|s|  [s.client,  s.topic]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.addr,  p.topic,  p.val]          }      end  end  

Ruby DSL

Page 54: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  Hub      include  Bud        state  do          channel  :subscribe,  [:@addr,  :topic,  :client]          channel  :pub,              [:@addr,  :topic,  :val]          channel  :event,          [:@addr,  :topic,  :val]          table      :sub,              [:addr,  :topic]      end        bloom  do          sub      <=  subscribe  {|s|  [s.client,  s.topic]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.addr,  p.topic,  p.val]          }      end  end  

State declarations

Page 55: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  Hub      include  Bud        state  do          channel  :subscribe,  [:@addr,  :topic,  :client]          channel  :pub,              [:@addr,  :topic,  :val]          channel  :event,          [:@addr,  :topic,  :val]          table      :sub,              [:addr,  :topic]      end        bloom  do          sub      <=  subscribe  {|s|  [s.client,  s.topic]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.addr,  p.topic,  p.val]          }      end  end  

Rules

Page 56: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  Hub      include  Bud        state  do          table      :sub,              [:client,  :topic]          channel  :subscribe,  [:@addr,  :topic,  :client]          channel  :pub,              [:@addr,  :topic,  :val]          channel  :event,          [:@addr,  :topic,  :val]      end        bloom  do          sub      <=  subscribe  {|s|  [s.client,  s.topic]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.addr,  p.topic,  p.val]          }      end  end  

Persistent state: set of subscriptions

Schema

Page 57: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  Hub      include  Bud        state  do          table      :sub,              [:client,  :topic]          channel  :subscribe,  [:@addr,  :topic,  :client]          channel  :pub,              [:@addr,  :topic,  :val]          channel  :event,          [:@addr,  :topic,  :val]      end        bloom  do          sub      <=  subscribe  {|s|  [s.client,  s.topic]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.addr,  p.topic,  p.val]          }      end  end  

Network input, output

Destination address

Page 58: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  Hub      include  Bud        state  do          table      :sub,              [:client,  :topic]          channel  :subscribe,  [:@addr,  :topic,  :client]          channel  :pub,              [:@addr,  :topic,  :val]          channel  :event,          [:@addr,  :topic,  :val]      end        bloom  do          sub      <=  subscribe  {|s|  [s.client,  s.topic]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.client,  p.topic,  p.val]          }      end  end  

Remember subscriptions

Page 59: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  Hub      include  Bud        state  do          table      :sub,              [:client,  :topic]          channel  :subscribe,  [:@addr,  :topic,  :client]          channel  :pub,              [:@addr,  :topic,  :val]          channel  :event,          [:@addr,  :topic,  :val]      end        bloom  do          sub      <=  subscribe  {|s|  [s.client,  s.topic]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.client,  p.topic,  p.val]          }      end  end  

Send events to subscribers

Join (as in SQL) Join key

Page 60: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Subscribe To

Topic

Publish To

Topic

Result

Stream

Join On

Topic

Persistent State

Ephemeral Events

“Push-Based”

Page 61: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Subscribe To

Topic

Publish To

Topic

Result

Stream

Join On

Topic

Ephemeral Events

Persistent State

“Pull-Based”

Page 62: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  Hub      include  Bud        state  do          table      :sub,              [:client,  :topic]                  channel  :subscribe,  [:@addr,  :topic,  :client]          channel  :pub,              [:@addr,  :topic,  :val]          channel  :event,          [:@addr,  :topic,  :val]      end        bloom  do          sub      <=  subscribe  {|s|  [s.client,  s.topic]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.client,  p.topic,  p.val]          }      end  end  

Page 63: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  HubPull      include  Bud        state  do          table      :pub,              [:topic,  :val]          channel  :publish,      [:@addr,  :topic,  :val]          channel  :sub,              [:@addr,  :topic,  :client]          channel  :event,          [:@addr,  :topic,  :val]      end        bloom  do          pub      <=  publish  {|p|  [p.topic,  p.val]}          event  <~  (pub  *  sub).pairs(:topic  =>  :topic)  {|p,s|              [s.client,  p.topic,  p.val]          }      end  end  

Page 64: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Suppose we keep only the most recent message for each topic (“last writer wins”).

Publish → Put Subscribe → Get Event → Reply Pub → DB Topic → Key

Rename:

Page 65: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  KvsHub      include  Bud        state  do          table      :db,                [:key,  :val]          channel  :put,              [:@addr,  :key,  :val]          channel  :get,              [:@addr,  :key,  :client]          channel  :reply,          [:@addr,  :key,  :val]  end        bloom  do          db        <+  put  {|p|  [p.key,  p.val]}          db        <-­‐  (db  *  put).lefts(:key  =>  :key)          reply  <~  (db  *  get).pairs(:key  =>  :key)  {|d,g|              [g.client,  d.key,  d.val]          }      end  end  

Update = delete + insert

Page 66: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Get From

Key

Put To

Key

Result

Stream

Join On

Key

Non-Monotone!

Page 67: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Get From

Key

Put To

Key

Result

Stream

Join On

Key

Non-Monotone!

Page 68: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

class  KvsHub      include  Bud        state  do          table      :db,                [:key,  :val]          channel  :put,              [:@addr,  :key,  :val]          channel  :get,              [:@addr,  :key,  :client]          channel  :reply,          [:@addr,  :key,  :val]  end        bloom  do          db        <+  put  {|p|  [p.key,  p.val]}          db        <-­‐  (db  *  put).lefts(:key  =>  :key)          reply  <~  (db  *  get).pairs(:key  =>  :key)  {|d,g|              [g.client,  d.key,  d.val]          }      end  end  

Page 69: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Takeaways

Bloom: •  Concise, high-level programs •  State update, asynchrony, and non-

monotonicity are explicit in the syntax

Design Patterns: •  Communication vs. Storage •  Queries vs. Data •  Push vs. Pull

Actually not so different!

Page 70: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Conclusion

Traditional languages are not a good fit for modern distributed computing

Principle: Disorderly programs for disorderly networks

Practice: Bloom – High-level, disorderly, declarative – Designed for distribution

Page 71: Systems, · ACID 2.0 merge() method – Associative ... {a,b} {b,c} {a,c} {a,b,c} 5 5 7 7 3 7 false false false true true true. CRDTs: Convergent Replicated Data Types – e.g., registers,

Thank You!

Twitter: @neil_conway

gem  install  bud  http://www.bloom-lang.net

Peter Alvaro Emily Andrews Peter Bailis David Maier

Bill Marczak Joe Hellerstein Sriram Srinivasan

Collaborators: