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

Convergent Replicated Data Types

Convergent Replicated Data Types

Patrick Van Stee

December 14, 2012
Tweet

More Decks by Patrick Van Stee

Other Decks in Programming

Transcript

  1. Convergent
    Replicated
    Data Types

    View full-size slide

  2. @vanstee
    [email protected]
    Patrick Van Stee

    View full-size slide

  3. “Structuring
    data so conflict
    resolution is
    automatic”

    View full-size slide

  4. Dynamo
    Trade consistency
    for availability and
    partition tolerance

    View full-size slide

  5. Node 1 Node 2
    { a: “200” } { a: “-3000” }
    :(

    View full-size slide

  6. Node 1 Node 2
    { a: “200” } { a: “-3000” }
    { a: “200”, a: “-3000” }
    Riak

    View full-size slide

  7. CRDT
    •Counter
    •Set
    •Graph
    •List
    •Tree

    View full-size slide

  8. CRDT
    •Counter
    •Set
    •Graph
    •List
    •Tree

    View full-size slide

  9. Counter
    •Can only be increased
    •Merge: use largest value

    View full-size slide

  10. Chat Room
    Karma
    Fault-Tolerant
    Distributed

    View full-size slide

  11. Serious Business
    { SB[PVS]: 0}
    Serious Coding
    { SB[PVS]: 1} # PVS++
    { SC[PVS]: 0}
    { SC[PVS]: 5} # PVS += 5
    { SB[PVS]: 2} # PVS++
    Merge
    { SB[PVS]: 2, SC[PVS]: 5} { SB[PVS]: 1, SC[PVS]: 5}
    { SB[PVS]: 2, SC[PVS]: 5}
    { PVS: 7}

    View full-size slide

  12. What about
    decrements?
    Use separate counters
    for positive and negative.
    Take the difference for
    the result.

    View full-size slide

  13. Serious Business
    { SB[PVS+]: 0, SB[PVS-]: 0 }
    Serious Coding
    { SB[PVS+]: 1, SB[PVS-]: 0 } # PVS++
    { SB[PVS+]: 0, SB[PVS-]: 0 }
    { SB[PVS+]: 5, SB[PVS-]: 0 } # PVS += 5
    { SB[PVS+]: 1, SB[PVS-]: 1 } # PVS--
    Merge
    { PVS+: 6, PVS-: 1 } { PVS+: 6, PVS-: 0 }
    { PVS+: 6, PVS-: 1 }
    { PVS: 5 }

    View full-size slide

  14. Set
    •Can only be added to
    •Merge: take the union

    View full-size slide

  15. Serious Business
    { PVS: [ ] }
    Serious Coding
    { PVS: [] } { PVS: [] }
    { PVS: [ ] }
    Merge
    { PVS: [ , ] }
    { PVS: [ , ] }
    { PVS: [ , , ] }
    { PVS: [ , , ] }

    View full-size slide

  16. Hold on, Can
    we remove
    stuff?
    Use separate sets for added
    and removed elements.

    View full-size slide

  17. Serious Business
    { PVS+: [ ], PVS-: [] }
    Serious Coding
    { PVS+: [], PVS-: [] } { PVS+: [], PVS-: [] }
    { PVS+: [ ], PVS-: [] }
    Merge
    { PVS+: [ , ], PVS-: [ ] }
    { PVS+: [ ], PVS-: [ ] }
    { PVS+: [ , ], PVS-: [] }
    { PVS+: [ , ], PVS-: [ ] }
    { PVS: [ ] }

    View full-size slide

  18. But wait,
    we can only
    remove once?

    View full-size slide

  19. U-Set
    •Append unique values
    to all set members
    •Garbage collection
    becomes an issue

    View full-size slide

  20. basho/riak_dt
    Demo

    View full-size slide

  21. Use Cases
    •Like button
    •Page Views
    •Shopping Cart

    View full-size slide

  22. Reference
    •INRIA paper
    •basho/riak_dt
    •RICON talk

    View full-size slide

  23. Beginning
    Ruby on Rails
    Course
    bignerdranch.com/classes/beginning_ruby_on_rails

    View full-size slide