Bloom: A Language For Disorderly
Distributed Programming
Christopher Meiklejohn
Wicked Good Ruby ’13
Sunday, October 13, 13

cmeiklejohn / @cmeik
My Name is My Name
Sunday, October 13, 13

What do you do?
Sunday, October 13, 13

Sunday, October 13, 13

Sunday, October 13, 13

Sunday, October 13, 13

What did you do?
Sunday, October 13, 13

Sunday, October 13, 13

Sunday, October 13, 13

UC Berkeley
Sunday, October 13, 13

BOOM
Sunday, October 13, 13

The Outline
Sunday, October 13, 13

Theory, language.
The Outline
Sunday, October 13, 13

von Neumann
Sunday, October 13, 13

Instructions, mutable state, executed in order.
von Neumann
Sunday, October 13, 13

Imposes a total order.
von Neumann
Sunday, October 13, 13

Disorderly actors
Sunday, October 13, 13

Allow disorder and races; illusion of total order.
Disorderly actors
Sunday, October 13, 13

The idea behind transactions; serializability.
Disorderly actors
Sunday, October 13, 13

Tricky to scale.
Disorderly actors
Sunday, October 13, 13

Scaling
Sunday, October 13, 13

Multiple machines; sharing computation.
Scaling
Sunday, October 13, 13

CAP Theorem
Sunday, October 13, 13

Consistency, availability, partition tolerance.
CAP Theorem
Sunday, October 13, 13

Negative result: linearizability impossible.
CAP Theorem
Sunday, October 13, 13

Whoa, Theory!
Sunday, October 13, 13

Distributed computing
Sunday, October 13, 13

The “new normal”.
Distributed computing
Sunday, October 13, 13

Order is di!cult to impose.
Distributed computing
Sunday, October 13, 13

Synchronization; coordination.
Distributed computing
Sunday, October 13, 13

FLP result; delays, partitions, partial writes.
Distributed computing
Sunday, October 13, 13

Inverse methods; commutative operations.
Distributed computing
Sunday, October 13, 13

ACID 2.0
Sunday, October 13, 13

Associativity, commutativity, idempotence.
ACID 2.0
Sunday, October 13, 13

(X · Y) · Z = X · (Y · Z)
ACID 2.0: Associativity
Sunday, October 13, 13

X · Y = Y · X
ACID 2.0: Commutativity
Sunday, October 13, 13

X · X = X
ACID 2.0: Idempotence
Sunday, October 13, 13

Associativity, commutativity, idempotence.
ACID 2.0
Sunday, October 13, 13

Familiar?
Sunday, October 13, 13

Bounded Join Semilattices
Sunday, October 13, 13

Partially ordered set; least upper bound; ACI.
Bounded Join Semilattices
Sunday, October 13, 13

Objects grow over time; merge computes LUB.
Bounded Join Semilattices
Sunday, October 13, 13

Monotonic and con"uent; convergent.
Bounded Join Semilattices
Sunday, October 13, 13

Map into another via monotone functions.
Bounded Join Semilattices
Sunday, October 13, 13

Examples.
Bounded Join Semilattices
Sunday, October 13, 13

b a c
a, b a, c
a, b, c
Set; merge function: union.
b, c
Sunday, October 13, 13

3 5 7
5 7
7
Increaing natual; merge function: max.
Sunday, October 13, 13

F F T
F T
T
Booleans; merge function: or.
Sunday, October 13, 13

x <= y montone f(x) <= f(y)
Sunday, October 13, 13

Sunday, October 13, 13

CvRDT examples.
Sunday, October 13, 13

[ [{1, a}], [] ] [ [{1, a}], [] ]
Sunday, October 13, 13

[ [{1, a}], [] ] [ [{1, a}], [] ]
[ [{1, a}], [{1, a}] ]
[ [{1, a}], [{1, a}] ]
Sunday, October 13, 13

[ [{1, a}], [] ] [ [{1, a}], [] ]
[ [{1, a}], [{1, a}] ]
[ [{1, a}], [{1, a}] ]
[ [{1, a}, {2, a}], [{1, a}] ]
Sunday, October 13, 13

[ [{1, a}], [] ] [ [{1, a}], [] ]
[ [{1, a}], [{1, a}] ]
[ [{1, a}], [{1, a}] ]
[ [{1, a}, {2, a}], [{1, a}] ]
[ [{1, a}, {2, a}], [{1, a}] ]
Sunday, October 13, 13

[ [{1, a}], [] ] [ [{1, a}], [] ]
Sunday, October 13, 13

[ [{1, a}], [] ] [ [{1, a}], [] ]
[ [{1, a}, {2, b}], [] ]
Sunday, October 13, 13

[ [{1, a}], [] ] [ [{1, a}], [] ]
[ [{1, a}, {2, b}], [] ]
[ [{1, a}], [{1, a}] ]
Sunday, October 13, 13

[ [{1, a}], [] ] [ [{1, a}], [] ]
[ [{1, a}, {2, b}], [] ]
[ [{1, a}], [{1, a}] ]
[ [{1, a}, {2, b}], [{1, a}] ]
Sunday, October 13, 13

Just data; what about computation?
Bounded Join Semilattices
Sunday, October 13, 13

Composability desired.
Bounded Join Semilattices
Sunday, October 13, 13

CALM Theorem
Sunday, October 13, 13

Consistency as Logical Monotonicity
CALM Theorem
Sunday, October 13, 13

Consistent given async; all monotone functions.
CALM Theorem
Sunday, October 13, 13

Identify non-monotone functions.
CALM Theorem
Sunday, October 13, 13

Disorderly Programming
Sunday, October 13, 13

Order-independent, explicit order-dependent.
Disorderly Programming
Sunday, October 13, 13

Prototype language: Bloom
Disorderly Programming
Sunday, October 13, 13

Bloom
Sunday, October 13, 13

Based in a logic called Dedalus.
Bloom
Sunday, October 13, 13

Disorderly language.
Bloom
Sunday, October 13, 13

Lattices and mappings between lattices.
Bloom
Sunday, October 13, 13

Highlights non-monotonicity.
Bloom
Sunday, October 13, 13

Operational model.
Bloom
Sunday, October 13, 13

Local clock; local execution; local state.
Bloom
Sunday, October 13, 13

Timestepped execution.
Bloom
Sunday, October 13, 13

Local updates; system events; network.
Sunday, October 13, 13

Bloom rules; merge functions.
Sunday, October 13, 13

Network; next.
Sunday, October 13, 13

Chat server.
Bloom
Sunday, October 13, 13

module ChatProtocol
state do
channel :connect, [:@addr, :client] => [:nick]
channel :mcast
end
end
examples/chat/chat_protocol.rb
Sunday, October 13, 13

class ChatServer
include Bud
include ChatProtocol
state { table :nodelist }
bloom do
nodelist <= connect.map { |c| [c.client, c.nick] }
mcast <~ (mcast * nodelist).pairs { |m,n| [n.key, m.val] }
end
end
examples/chat/chat_server.rb
Sunday, October 13, 13

Lattices; monotonic functions.
Bloom
Sunday, October 13, 13

class ChatServer
include Bud
include ChatProtocol
state do
table :nodelist
channel :disconnect
end
bloom do
nodelist <= connect.map { |c| [c.client, c.nick] }
mcast <~ (mcast * nodelist).pairs { |m,n| [n.key, m.val] }
nodelist <- disconnect.map { |c| [c.client, c.nick] }
end
end
examples/chat/chat_server.rb
Sunday, October 13, 13

Non-monotonic; not eventually consistent.
Bloom
Sunday, October 13, 13

bloom do
mcast <~ stdio do |s|
[@server, [ip_port, @nick,
Time.new.strftime("%I:%M.%S"), s.line]]
end
stdio <~ mcast { |m| [pretty_print(m.val)] }
end
examples/chat/chat.rb
Sunday, October 13, 13

KV Store.
Bloom
Sunday, October 13, 13

module BasicKVS
include KVSProtocol
state do
table :kvstate, [:key] => [:value]
end
bloom :mutate do
kvstate <+ kvput {|s| [s.key, s.value]}
kvstate <- (kvstate * kvput).lefts(:key => :key)
end
bloom :get do
temp :getj <= (kvget * kvstate).pairs(:key => :key)
kvget_response <= getj do |g, t|
[g.reqid, t.key, t.value]
end
end
bloom :delete do
kvstate <- (kvstate * kvdel).lefts(:key => :key)
end
end
kvs/kvs.rb
Sunday, October 13, 13

module ReplicatedKVS
include KVSProtocol
include MulticastProtocol
include MembershipProtocol
import BasicKVS => :kvs
bloom :local_indir do
kvs.kvdel <= kvdel
kvs.kvget <= kvget
kvget_response <= kvs.kvget_response
end
bloom :puts do
# if I am the master, multicast store requests
mcast_send <= kvput do |k|
unless member.include? [k.client]
[k.reqid, ["put", [@addy, k.key, k.reqid, k.value]]]
end
end
kvs.kvput <= mcast_done do |m|
if m.payload[0] == "put"
m.payload[1]
end
end
# if I am a replica, store the payload of the multicast
kvs.kvput <= pipe_out do |d|
if d.payload.fetch(1) != @addy and d.payload[0] == "put"
d.payload[1]
end
end
end
bloom :dels do
mcast_send <= kvdel do |k|
unless member.include? [k.client]
[k.reqid, ["del", [@addy, k.key, k.reqid]]]
end
end
kvs.kvdel <= mcast_done do |m|
if m.payload[0] == "del"
m.payload[1]
end
end
kvs.kvdel <= pipe_out do |d|
if d.payload.fetch(1) != @addy and d.payload[0] == "del"
d.payload[1]
end
end
end
end
kvs/kvs.rb
Sunday, October 13, 13

CALM Analysis
Sunday, October 13, 13

Label asynchronous, non-monotonic.
CALM Analysis
Sunday, October 13, 13

Identify where coordination is needed.
CALM Analysis
Sunday, October 13, 13

The Conclusion
Sunday, October 13, 13

Prototype language.
The Conclusion
Sunday, October 13, 13

https://github.com/bloom-lang/bud
https://github.com/bloom-lang/bud-sandbox
Thanks! Questions?
Sunday, October 13, 13