Upgrade to Pro — share decks privately, control downloads, hide ads and more …

State and the distributed data structures

State and the distributed data structures

In this talk I present the concept of CRDTs, data structures which allow to replicate the state in a distributed system with guaranteed eventual consistency.

Properties of CRDTs (particularly the state-based ones) ensure that despite of failing nodes and network partitions, the state of all replicas will eventually converge to the same value. I try to focus on high-level requirements and caveats rather than code examples and specific implementations, although you’ll find them here as well.

The talk was presented for the first time at ElixirConf EU 2018.

Arkadiusz Gil

April 16, 2018
Tweet

More Decks by Arkadiusz Gil

Other Decks in Technology

Transcript

  1. Example merge({1, 2}, {3}) #=> {1, 2, 3} compare({1, 2,

    3}, {1, 2}) #=> true compare({1, 2, 3}, {3}) #=> true
  2. TOMBSTONES @type t :: {Set.t(), Set.t()} def add({s, t}, el)

    do {Set.union(s, {el}), t} end def remove({s, t}, el) do {s, Set.union(t, {el})} end
  3. a = {{}, {}} |> add(1) #=> {{1}, {}} b

    = a |> add(2) #=> {{1, 2}, {}} c = b |> remove(1) #=> {{1, 2}, {1}}
  4. a = {{}, {}} |> add(1) #=> {{1}, {}} b

    = a |> add(2) #=> {{1, 2}, {}} c = b |> remove(1) #=> {{1, 2}, {1}} compare(b, a) = true compare(c, b) = true
  5. def compare({s1, t1}, {s2, t2}) do Set.super_or_eq?(s1, s2) and Set.super_or_eq?(t1,

    t2) end def merge({s1, t1}, {s2, t2}) do {Set.union(s1, s2), Set.union(t1, t2)} end
  6. s = {{}, {}} |> add(1) #=> {{1}, {}} element?(s,

    1) #=> true element?(s, 2) #=> false
  7. s = {{}, {}} |> add(1) #=> {{1}, {}} |>

    add(2) #=> {{1, 2}, {}} element?(s, 1) #=> true element?(s, 2) #=> true
  8. s = {{}, {}} |> add(1) #=> {{1}, {}} |>

    add(2) #=> {{1, 2}, {}} |> remove(1) #=> {{1, 2}, {1}} element?(s, 1) #=> false element?(s, 2) #=> true
  9. s = {{}, {}} |> add(1) #=> {{1}, {}} |>

    add(2) #=> {{1, 2}, {}} |> remove(1) #=> {{1, 2}, {1}} |> add(1) #=> {{1, 2}, {1}} element?(s, 1) #=> false element?(s, 2) #=> true
  10. REFERENCES •A comprehensive study of Convergent and Commutative Replicated Data

    Types •Conflict-free Replicated Data Types •Delta State Replicated Data Types •Phoenix 1.2 and Beyond •Efficient State-based CRDTs by Delta-Mutation