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

CraftConf 2016 - Building Scalable Stateful Services

CraftConf 2016 - Building Scalable Stateful Services

The Stateless Service design principle has become ubiquitous in the tech industry for creating horizontally scalable services. However our applications do have state, we just have moved all of it to caches and databases. Today as applications are becoming more data intensive and request latencies are expected to be incredibly low, we’d like the benefits of stateful services, like data locality and sticky consistency. In this talk I will address the benefits of stateful services, how to build them so that they scale, and discuss distributed and scalable services in the real world that implement these techniques successfully.

Caitie McCaffrey

April 29, 2016
Tweet

More Decks by Caitie McCaffrey

Other Decks in Technology

Transcript

  1. Building Scalable Stateful Services
    Craft Conf 2016

    View full-size slide

  2. Caitie McCaffrey
    Distributed Systems Engineer
    @caitie
    caitiem.com

    View full-size slide

  3. Stateless Services
    Service

    View full-size slide

  4. Stateless Services
    Service

    View full-size slide

  5. Stateless Services
    Service
    Service

    View full-size slide

  6. Stateless Services
    Service
    Service

    View full-size slide

  7. Stateless Services
    Service
    Service

    View full-size slide

  8. Stateless Services
    Service Service
    Service

    View full-size slide

  9. Stateless Services
    Service Service
    Service

    View full-size slide

  10. Stateless Services
    Service Service
    Service

    View full-size slide

  11. Stateless Services
    Service Service
    Service
    Service

    View full-size slide

  12. Stateless Services
    Service Service
    Service
    Service

    View full-size slide

  13. Stateless Services
    Service Service
    Service
    Service

    View full-size slide

  14. Stateless Services
    Service Service
    Service
    Service Service

    View full-size slide

  15. Stateless Services
    Service Service
    Service
    Service Service

    View full-size slide

  16. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  17. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  18. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  19. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  20. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  21. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  22. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  23. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  24. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  25. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  26. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  27. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  28. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  29. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  30. Data Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  31. Overview
    Benefits
    Building
    Real World
    Caution

    View full-size slide

  32. Data Locality
    For Low Latency & Data Intensive Services

    View full-size slide

  33. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  34. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  35. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  36. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  37. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  38. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  39. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  40. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  41. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  42. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  43. Function Shipping Paradigm
    Service
    Service
    Service

    View full-size slide

  44. Sticky Connections
    & Consistency
    Additional Available Consistency Models

    View full-size slide

  45. Sticky Connections

    View full-size slide

  46. Sticky Connections

    View full-size slide

  47. Linearizable
    Sequential
    Causal
    Pipelined Random
    Access Memory
    Read Your
    Write
    Monotonic
    Read
    Monotonic
    Write
    Write From
    Read
    Consistency
    Models
    CP Consistency
    AP Consistency

    View full-size slide

  48. Linearizable
    Sequential
    Causal
    Pipelined Random
    Access Memory
    Read Your
    Write
    Monotonic
    Read
    Monotonic
    Write
    Write From
    Read
    CP Consistency
    AP Consistency
    AP Consistency
    w/ Sticky Connections
    Consistency
    Models

    View full-size slide

  49. - Werner Vogel 2007
    “Whether or not read-your-write, session and monotonic
    consistency can be achieved depends in general on the
    "stickiness" of clients to the server that executes the
    distributed protocol for them… Using sessions, which are
    sticky, makes this explicit and provides an exposure level
    that clients can reason about.”

    View full-size slide

  50. Building Sticky Connections
    For Low Latency & Data Intensive Services

    View full-size slide

  51. Building Sticky Connections

    View full-size slide

  52. Building Sticky Connections

    View full-size slide

  53. Persistent Connections
    Load Balancing Problems
    No Stickiness Once
    Connection Breaks
    Problems

    View full-size slide

  54. Persistent Connections
    Load Balancing Problems
    No Stickiness Once
    Connection Breaks
    Problems

    View full-size slide

  55. Routing Logic
    • Cluster Membership
    • Work Distribution
    Problems to Solve

    View full-size slide

  56. Routing Logic
    • Cluster Membership
    • Work Distribution
    Problems to Solve

    View full-size slide

  57. Routing Logic
    • Cluster Membership
    • Work Distribution
    Problems to Solve

    View full-size slide

  58. Cluster Membership
    Dynamic
    Static

    View full-size slide

  59. Static Cluster Membership
    Machine Outage means
    Partial Service Outage
    Downtime to Add Capacity

    View full-size slide

  60. Static Cluster Membership
    Machine Outage means
    Partial Service Outage
    Downtime to Add Capacity

    View full-size slide

  61. Static Cluster Membership
    Machine Outage means
    Partial Service Outage
    Downtime to Add Capacity

    View full-size slide

  62. Dynamic Cluster Membership
    Fault Tolerance

    View full-size slide

  63. Dynamic Cluster Membership
    Fault Tolerance

    View full-size slide

  64. Dynamic Cluster Membership
    Fault Tolerance

    View full-size slide

  65. Dynamic Cluster Membership
    Fault Tolerance

    View full-size slide

  66. Dynamic Cluster Membership
    Fault Tolerance

    View full-size slide

  67. Dynamic Cluster Membership
    Gossip
    Protocols
    Consensus
    Systems
    Availability vs Consistency

    View full-size slide

  68. Consensus Systems
    for Consistency
    Paxos ETCD
    Zookeeper Raft

    View full-size slide

  69. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  70. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  71. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  72. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  73. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  74. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  75. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  76. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  77. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  78. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  79. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  80. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  81. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  82. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  83. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  84. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  85. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  86. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  87. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  88. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  89. Gossip Protocols
    for Availability
    • Assumes Non-Reliable Networks
    • Information Dissemination
    • Pairwise Communication

    View full-size slide

  90. Work Distribution
    Consistent
    Hashing
    Distributed
    Hash Tables
    Random
    Placement

    View full-size slide

  91. Random Placement
    Write
    Anywhere
    Read from
    Everywhere

    View full-size slide

  92. Random Placement
    Write
    Anywhere
    Read from
    Everywhere

    View full-size slide

  93. Random Placement
    Write
    Anywhere
    Read from
    Everywhere

    View full-size slide

  94. Random Placement
    Write
    Anywhere
    Read from
    Everywhere

    View full-size slide

  95. Random Placement
    Write
    Anywhere
    Read from
    Everywhere

    View full-size slide

  96. Random Placement
    Write
    Anywhere
    Read from
    Everywhere

    View full-size slide

  97. Random Placement
    Write
    Anywhere
    Read from
    Everywhere

    View full-size slide

  98. Consistent Hashing
    Deterministic
    Placement
    Node A
    Node B
    Node C
    NodeD
    Consistent Hashing & Random Trees:
    Distributed caching protocols for
    relieving hot spots on the World
    Wide Web

    View full-size slide

  99. Distributed Hash Table
    Non- Deterministic
    Placement
    Node B
    Node A
    Node C

    View full-size slide

  100. Distributed Hash Table
    Non- Deterministic
    Placement
    Node B
    Node A
    Node C

    View full-size slide

  101. Distributed Hash Table
    Non- Deterministic
    Placement
    Node B
    Node A
    Node C

    View full-size slide

  102. Distributed Hash Table
    Non- Deterministic
    Placement
    Node B
    Node A
    Node C

    View full-size slide

  103. Distributed Hash Table
    Non- Deterministic
    Placement
    Node B
    Node A
    Node C

    View full-size slide

  104. Stateful Services
    In the Real World

    View full-size slide

  105. Scuba is a fast, scalable,
    distributed, in-memory database
    built at Facebook. It is the workhorse
    behind code regression analysis &
    bug report, revenue, and
    performance debugging
    Fan-out request to all
    machines in the cluster
    Compose Results
    Return Results and
    Completeness

    View full-size slide

  106. Scuba is a fast, scalable,
    distributed, in-memory database
    built at Facebook. It is the workhorse
    behind code regression analysis &
    bug report, revenue, and
    performance debugging
    Fan-out request to all
    machines in the cluster
    Compose Results
    Return Results and
    Completeness

    View full-size slide

  107. Scuba is a fast, scalable,
    distributed, in-memory database
    built at Facebook. It is the workhorse
    behind code regression analysis &
    bug report, revenue, and
    performance debugging
    Fan-out request to all
    machines in the cluster
    Compose Results
    Return Results and
    Completeness

    View full-size slide

  108. Twitter Nuthatch is a
    temporal set indexing service.
    Helps resolve glob queries in
    metric names. Static Cluster
    Membership
    +
    Hashing

    View full-size slide

  109. Twitter Nuthatch is a
    temporal set indexing service.
    Helps resolve glob queries in
    metric names. Static Cluster
    Membership
    +
    Hashing

    View full-size slide

  110. Twitter Nuthatch is a
    temporal set indexing service.
    Helps resolve glob queries in
    metric names. Static Cluster
    Membership
    +
    Hashing

    View full-size slide

  111. Uber Ringpop is an open-
    source Node.js library that brings
    application-layer sharding to
    many of their dispatching
    platform services.
    Swim Gossip Protocol
    Consistent Hashing
    +

    View full-size slide

  112. Uber Ringpop is an open-
    source Node.js library that brings
    application-layer sharding to
    many of their dispatching
    platform services.
    Swim Gossip Protocol
    Consistent Hashing
    +

    View full-size slide

  113. Uber Ringpop is an open-
    source Node.js library that brings
    application-layer sharding to
    many of their dispatching
    platform services.
    Swim Gossip Protocol
    Consistent Hashing
    +

    View full-size slide

  114. Orleans Cluster
    Orleans is a runtime and
    Programming model for building
    distributed systems based on the
    Actor Model from the eXtreme
    Computing Group at MSR
    Gossip Protocol
    Consistent Hashing
    +
    +
    Distributed Hash Table
    Actor
    Actor
    Actor
    Actor
    Actor

    View full-size slide

  115. Orleans Cluster
    Orleans is a runtime and
    Programming model for building
    distributed systems based on the
    Actor Model from the eXtreme
    Computing Group at MSR
    Gossip Protocol
    Consistent Hashing
    +
    +
    Distributed Hash Table
    Actor
    Actor
    Actor
    Actor
    Actor

    View full-size slide

  116. Orleans Cluster
    Orleans is a runtime and
    Programming model for building
    distributed systems based on the
    Actor Model from the eXtreme
    Computing Group at MSR
    Gossip Protocol
    Consistent Hashing
    +
    +
    Distributed Hash Table
    Actor
    Actor
    Actor
    Actor
    Actor

    View full-size slide

  117. Orleans Cluster
    Orleans Distributed Hash Table

    View full-size slide

  118. Orleans Cluster
    Orleans Distributed Hash Table

    View full-size slide

  119. Orleans Cluster
    Orleans Distributed Hash Table

    View full-size slide

  120. Orleans Cluster
    Orleans Distributed Hash Table

    View full-size slide

  121. Orleans Cluster
    Orleans Distributed Hash Table

    View full-size slide

  122. Orleans Cluster
    Orleans Distributed Hash Table

    View full-size slide

  123. Orleans Cluster
    Orleans Distributed Hash Table

    View full-size slide

  124. Orleans Cluster
    Orleans Distributed Hash Table

    View full-size slide

  125. Caution
    Stateful Services Ahead

    View full-size slide

  126. Unbounded
    Data Structures
    Implicit Assumptions
    are the Killer of
    Distributed Systems

    View full-size slide

  127. Memory Management
    Get Ready to Make Friends with the Garbage Collector Profiler

    View full-size slide

  128. Reloading
    State
    • First Connection
    • Recovering From Crashes
    • Deploying New Code

    View full-size slide

  129. Fast Restarts at Facebook
    “Our Key Observation is that we can
    decouple the memory lifetime from the
    process lifetime. When we shutdown a
    server for a planned upgrade.”

    View full-size slide

  130. Conclusion
    Data Locality & Available Consistency
    Cluster Membership & Work Distribution
    Successful Stateful Real World Systems
    Caution: Some New Challenges

    View full-size slide

  131. Thank You
    Kyle Kingsbury
    Chris Meiklejohn
    Tom Santero
    Ines Sombra
    @Caitie

    View full-size slide

  132. https://github.com/CaitieM20/ScalingStatefulServices
    @Caitie
    Questions

    View full-size slide