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

Data corrupting architectures we know and love

Data corrupting architectures we know and love

There’s an old distributed systems adage, “You can have a second computer when you learn how to use the first one.” When it comes to data-access patterns, most of our favorite patterns are unsafe on a single computer. Most of our applications assume a concurrency model where all access is serialized. What happens when that mental model meets distributed data?

Sean Allen reviews data race and corruption problems that exist on single-machine systems and shows how we’ve transferred many of those patterns over to distributed systems and distributed state. You’ll learn the basics of data races, deadlocks, and problems in even the simplest of our concurrent data access patterns and how our existing scaling patterns replicate the same issues across multiple machines, increasing the potential problems, as well as designs that can alleviate them.

Sean T Allen

May 18, 2019
Tweet

More Decks by Sean T Allen

Other Decks in Technology

Transcript

  1. WE KNOW AND LOVE
    DATA CORRUPTING ARCHITECTURES

    View full-size slide

  2. VP OF ENGINEERING @ WALLAROO LABS
    MEMBER OF THE PONY CORE TEAM
    AUTHOR OF “STORM APPLIED”
    CHICHARRONES LOVER
    @SEANTALLEN
    @WALLAROOLABS
    @PONYLANG
    SEAN T. ALLEN

    View full-size slide

  3. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    TODAY’S TOPICS INCLUDE…
    ▸ Data corruption
    ▸ Concurrency
    ▸ Data races
    ▸ Shared values
    ▸ Atomic operations

    View full-size slide

  4. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    GENERALIZATIONS
    AHEAD

    View full-size slide

  5. OUR MOST POPULAR ARCHITECTURES
    CAN BE TRACED TO WEB
    APPPLICATIONS.
    Sean T. Allen
    DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE

    View full-size slide

  6. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    DATABASE
    WEB APP

    View full-size slide

  7. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    A BIT MORE DETAILED…
    REQUEST
    to the
    APPLICATION
    on to the
    DATABASE
    back to the
    APPLICATION
    and out as a
    RESPONSE

    View full-size slide

  8. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    WE COULD GET MORE DETAILED STILL…
    REQUEST
    to the
    APPLICATION
    on to the
    DATABASE
    back to the
    APPLICATION
    and out as a
    RESPONSE
    (WEB BROWSER)
    to the
    (WEB SERVER + DEVELOPER CODE)
    on to the
    DATABASE
    back to the
    (WEB SERVER + DEVELOPER CODE)
    and out as a
    (WEB BROWSER)

    View full-size slide

  9. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    OUR
    SIMPLE WEB APP IS
    A DISTRIBUTED SYSTEM

    View full-size slide

  10. DISTRIBUTED SYSTEMS AREN’T HARD.
    THEY’RE EASY*.
    Sean T. Allen
    DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    * sometimes

    View full-size slide

  11. DISTRIBUTED SYSTEMS AREN’T HARD.
    THEY’RE EASY*.
    CONCURRENCY IS THE HARD PART.
    Sean T. Allen
    DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    * sometimes

    View full-size slide

  12. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    SOME JUSTIFICATION
    AHEAD

    View full-size slide

  13. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    DATABASE
    WEB APP

    View full-size slide

  14. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    DATABASE
    WEB APP

    View full-size slide

  15. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    DATABASE
    WEB APP

    View full-size slide

  16. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    AN EXAMPLE
    APPLICATION

    View full-size slide

  17. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    THE PAGES SERVED COUNTER
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return new value to the user

    View full-size slide

  18. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    THE PAGES SERVED COUNTER
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return original value to the user
    SPOT THE
    DATA CORRUPTION?

    View full-size slide

  19. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    THE PAGES SERVED COUNTER
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return new value to the user

    View full-size slide

  20. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    THE PAGES SERVED COUNTER
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return original value to the user
    LET’S ADD SOME
    CONCURRENCY

    View full-size slide

  21. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    THE PAGES SERVED COUNTER
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return new value to the user
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return new value to the user

    View full-size slide

  22. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    THE PAGES SERVED COUNTER
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return original value to the user
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return original value to the user
    WHAT’S THE FINAL VALUE?
    1?
    2?

    View full-size slide

  23. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    WE DON’T
    KNOW

    View full-size slide

  24. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    THE PAGES SERVED COUNTER
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return new value to the user
    ‣ Read current value from the database
    ‣ Add one to update it
    ‣ Write new value to the database
    ‣ Return new value to the user

    View full-size slide

  25. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Read current value from the database 0
    ‣ Read current value from the database 0
    ‣ Add one to update it 1
    ‣ Add one to update it 1
    ‣ Write new value to the database 1
    ‣ Write new value to the database 1
    ‣ Return new value to the user 1
    ‣ Return new value to the user 1
    Request A Request B

    View full-size slide

  26. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Read current value from the database 0
    ‣ Add one to update it 1
    ‣ Write new value to the database 1
    ‣ Return new value to the user 1
    ‣ Read current value from the database 1
    ‣ Add one to update it 2
    ‣ Write new value to the database 2
    ‣ Return new value to the user 2
    Request A Request B

    View full-size slide

  27. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Read current value from the database 0
    ‣ Add one to update it 1
    ‣ Write new value to the database 1
    ‣ Read current value from the database 1
    ‣ Return new value to the user 1
    ‣ Add one to update it 2
    ‣ Write new value to the database 2
    ‣ Return new value to the user 2
    Request A Request B

    View full-size slide

  28. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Read current value from the database 0
    ‣ Add one to update it 1
    ‣ Write new value to the database 1
    ‣ Read current value from the database 1
    ‣ Return new value to the user 1
    ‣ Add one to update it 2
    ‣ Write new value to the database 2
    ‣ Return new value to the user 2
    Request A Request B

    View full-size slide

  29. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Read current value from the database 0
    ‣ Add one to update it 1
    ‣ Write new value to the database 1
    ‣ Read current value from the database 1
    ‣ Return new value to the user 1
    ‣ Add one to update it 2
    ‣ Write new value to the database 2
    ‣ Return new value to the user 2
    Request A Request B

    View full-size slide

  30. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    WE’RE EXPERIENCING
    A DATA RACE

    View full-size slide

  31. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    RECIPE FOR A DATA RACE
    ▸ A shared value
    ▸ Concurrency
    ▸ At least one writer changing the shared value
    ▸ Non-atomic operations

    View full-size slide

  32. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    OUR DATABASE IS
    A SHARED VALUE

    View full-size slide

  33. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    CONCURRENCY:
    WE HAVE TWO REQUESTS

    View full-size slide

  34. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    WHOLE LOTTA
    WRITING
    GOING ON

    View full-size slide

  35. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    OUR INCREMENTING
    ISN’T ATOMIC

    View full-size slide

  36. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    AN OPERATION IS ATOMIC IF IT’S
    ISOLATED FROM OTHER
    OPERATIONS HAPPENING AT THE
    SAME TIME.

    View full-size slide

  37. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Read current value from the database 0
    ‣ Read current value from the database 0
    ‣ Add one to update it 1
    ‣ Add one to update it 1
    ‣ Write new value to the database 1
    ‣ Write new value to the database 1
    ‣ Return new value to the user 1
    ‣ Return new value to the user 1
    Request A Request B

    View full-size slide

  38. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Read current value from the database 0
    ‣ Read current value from the database 0
    ‣ Add one to update it 1
    ‣ Add one to update it 1
    ‣ Write new value to the database 1
    ‣ Write new value to the database 1
    ‣ Return new value to the user 1
    ‣ Return new value to the user 1
    Request A Request B

    View full-size slide

  39. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Increment current value 1
    ‣ Increment current value 2
    ‣ Read new value 2
    ‣ Read new value 2
    ‣ Return new value to the user 2
    ‣ Return new value to the user 2
    Request A Request B

    View full-size slide

  40. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ‣ Increment current value 1
    ‣ Increment current value 2
    ‣ Read new value 2
    ‣ Read new value 2
    ‣ Return new value to the user 2
    ‣ Return new value to the user 2
    Request A Request B

    View full-size slide

  41. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    MORE CONCURRENCY
    MORE PROBLEMS

    View full-size slide

  42. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  43. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  44. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  45. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  46. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    DATABASE VALUE
    IS 1

    View full-size slide

  47. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  48. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  49. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  50. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    DATABASE VALUE
    INCREASED TO 2

    View full-size slide

  51. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  52. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    0
    0
    1
    1
    1 2
    Request A
    Request B
    Request C

    View full-size slide

  53. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    DATABASE VALUE
    DECREASED TO 1

    View full-size slide

  54. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    WE’RE EXPERIENCING
    LAST WRITE WINS

    View full-size slide

  55. LAST WRITE WINS MEANS “SOME
    WRITES LOSE”.
    Sean Cribbs & Russell Brown
    DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE

    View full-size slide

  56. LAST WRITE WINS IS A FANCY NAME
    FOR “LET’S CORRUPT SOME DATA”.
    Sean T. Allen
    DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE

    View full-size slide

  57. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    OUR MOST POPULAR
    ARCHITECTURES FOR SCALING

    View full-size slide

  58. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    THESE PROBLEMS
    ARE EVERYWHERE

    View full-size slide

  59. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    “SERVERLESS”

    View full-size slide

  60. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    “FUNCTIONS AS
    SERVICE”

    View full-size slide

  61. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    “STATELESS”

    View full-size slide

  62. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    “SHARED NOTHING”

    View full-size slide

  63. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ALL FEATURE
    DATABASE AS A SHARED VALUE
    AND CONCURRENT WRITES

    View full-size slide

  64. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    ALL HAVE
    DATA CORRUPTION
    BAKED INTO THE CORE ARCHITECTURE

    View full-size slide

  65. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    WHAT
    CAN WE DO?

    View full-size slide

  66. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    RECIPE FOR A DATA RACE: CHANGE AT LEAST ONE
    ▸ A shared value
    ▸ Concurrency
    ▸ At least one writer changing the shared value
    ▸ Non-atomic operations

    View full-size slide

  67. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    STORED PROCEDURES
    AND
    TRANSACTIONS

    View full-size slide

  68. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    DISTRIBUTED
    TRANSACTIONS

    View full-size slide

  69. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    SYNCHRONIZE
    DATA ACCESS

    View full-size slide

  70. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    CONSENSUS
    ALGORITHMS

    View full-size slide

  71. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    CONCURRENCY
    FRIENDLY DATA STRUCTURES

    View full-size slide

  72. DATA CORRUPTING ARCHITECTURES WE KNOW AND LOVE
    COMMUNICATE
    OPERATIONS
    NOT

    VALUES

    View full-size slide

  73. GITHUB.COM/
    SEANTALLEN/DATA-
    CORRUPTING-
    ARCHITECTURES
    LEARN MORE

    View full-size slide