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 Slide

  2. @vanstee
    [email protected]
    Patrick Van Stee

    View Slide

  3. “Structuring
    data so conflict
    resolution is
    automatic”

    View Slide

  4. Dynamo
    Trade consistency
    for availability and
    partition tolerance

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  10. Chat Room
    Karma
    Fault-Tolerant
    Distributed

    View 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 Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

  18. But wait,
    we can only
    remove once?

    View Slide

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

    View Slide

  20. basho/riak_dt
    Demo

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide