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

KanDDDinsky 2017 - The Dark Side of Event Sourcing: Managing Data Conversion

KanDDDinsky 2017 - The Dark Side of Event Sourcing: Managing Data Conversion

Evolving software systems often includes data schema changes, and those cause the need for data conversion. This is no different in event sourced systems.
Converting data between schemas while continuing the operation of the system is a challenge.
In this talk, we will look at the possible conversion operations, the techniques to execute them, and strategies for deployment with zero-downtime.
We will look at the possibilities and the trade-offs for designing and implementing upgrades for event sourced systems.

Michiel Overeem

October 20, 2017
Tweet

More Decks by Michiel Overeem

Other Decks in Technology

Transcript

  1. Copyright Nasa Goddard
    Michiel Overeem
    @michielovereem

    View Slide

  2. AFAS Software
    400+ employees
    10.000+ organizations

    View Slide

  3. AFAS Profit
    HRM, CRM, finance, order
    management, project management

    View Slide

  4. Model-Driven
    Generate a customized
    application with
    standardized software

    View Slide

  5. Management
    Zero downtime upgrades

    View Slide

  6. daptable
    odel-based
    and
    ser-specific
    oftware
    cosystems
    A
    M
    U
    S
    E

    View Slide

  7. Copyright Nasa Goddard

    View Slide

  8. How can an event sourced system be upgraded efficiently
    when the (implicit) event schema changes?

    View Slide

  9. Sources

    View Slide

  10. Structure of an Event Store
    Store
    A (distributed)
    collection of streams.
    An ordered list of events
    Stream
    An ordered list of
    events.
    Event
    A name, attributes with
    values, and metadata.

    View Slide

  11. The schema is implicit and hidden!
    Which streams are known in the system?
    Which events are allowed in which streams?
    Which attributes are allowed in which events?

    View Slide

  12. Webshop EventStore
    Customer Stream
    ShoppingCart Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    ShoppingCartCreated { … }
    ArticleRemovedFromChart { … }
    ArticleAddedToChart { … }

    View Slide

  13. Change will happen
    “An software system written to
    perform some real-world activity
    must be continually adapted or it
    becomes progressively less
    satisfactory”
    Lehman’s law of continuing change

    View Slide

  14. Add attribute to event
    Customer Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }

    View Slide

  15. Add attribute to event
    Customer Stream
    CustomerSignedUp { …, newsletter: }
    UpgradedCustomerToPremiumService { … }

    View Slide

  16. Customer Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    Add event to stream

    View Slide

  17. Customer Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    OptInOnNewsLetter { … }
    Add event to stream

    View Slide

  18. Newsletter Stream
    CreateNewsletter { … }
    PublishNewsletter { … }
    Add stream to store

    View Slide

  19. Customer Stream
    CustomerSignedUp { …, firstName: ,
    surName: }
    UpgradedCustomerToPremiumService { … }
    CustomerSignedUp { …, fullName: }
    Split attribute

    View Slide

  20. Customer Stream
    CustomerSignedUp { …, firstName: ,
    surName: }
    UpgradedCustomerToPremiumService { … }
    Split attribute

    View Slide

  21. Customer Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    CustomerSignedUp { …, newsletter: }
    Split events

    View Slide

  22. Customer Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    OptInOnNewsLetter { … }
    Split events

    View Slide

  23. Customer Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    OptInOnNewsLetter { … }
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    Split streams

    View Slide

  24. CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    Customer Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    NewsletterSubscription Stream
    OptInOnNewsLetter { … }
    Split streams

    View Slide

  25. Store level operations
    Add / remove streams
    Merge streams / split / … streams
    Stream level operations
    Add / remove events
    Merge events / split / … events
    Event level operations
    Add / update / remove attributes
    Merge attributes / split / … attributes
    The operations

    View Slide

  26. How can we execute these operations?

    View Slide

  27. Always extend
    Customer Stream
    CustomerSignedUp { … }
    UpgradedCustomerToPremiumService { … }
    CustomerSignedUp_V2 { … }

    View Slide

  28. Our codebase
    would only grow.
    Blue Cross Blue Shield Tower under construction in Chicago, by Photogonal, wikipedia.org

    View Slide

  29. CustomerSignedUp {
    “customerId”: …,
    “fullName”: …
    }
    Weak schema & serialization
    CustomerSignedUp {
    “customerId”: …,
    “firstName”: …,
    “surName”: …
    }

    View Slide

  30. CustomerSignedUp {
    “customerId”: …,

    }
    Weak schema & serialization

    View Slide

  31. If-then-else explosion?
    pexels.com

    View Slide

  32. Upcasting

    View Slide

  33. Upcasters
    Upcasting

    View Slide

  34. CustomerSignedUp {
    “customerId”: …,
    “fullName”: …
    }
    Upcasting
    CustomerSignedUp {
    “customerId”: …,
    “firstName”: …,
    “surName”: …
    }
    CustomerSignedUp {
    “customerId”: …,
    “firstName”: …,
    “surName”: …,
    “newsletter”: …
    }
    Upcaster
    Upcaster

    View Slide

  35. Upcasters
    Upcasting

    View Slide

  36. Runtime overhead?
    pexels.com

    View Slide

  37. Think about the order of upgrading components!

    View Slide

  38. View Slide

  39. View Slide

  40. View Slide

  41. View Slide

  42. View Slide

  43. Do we need immutability?
    Copyright Stephen Cairns

    View Slide

  44. Data Information

    View Slide

  45. Upcasters
    Lazy transformation

    View Slide

  46. Upcasters
    Lazy transformation

    View Slide

  47. When will this be done?

    View Slide

  48. In place transformation

    View Slide

  49. In place transformation

    View Slide

  50. Not for the faint of heart?

    View Slide

  51. Copy and transform

    View Slide

  52. Copy and transform

    View Slide

  53. Copy and transform

    View Slide

  54. Slow?

    View Slide

  55. Store
    A (distributed)
    collection of streams.
    An ordered list of events
    Store level
    Stream level
    Event level
    Add / remove streams
    Merge streams / split / … streams
    Should we perform all operations at runtime?

    View Slide

  56. Let’s put all these operations together!

    View Slide

  57. Event operations
    Stream operations
    Store operations
    simple
    Store operations
    complex
    Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place
    transformation
    Copy and transform

    View Slide

  58. Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place transformation
    Copy and transformation
    Functional
    suitability
    +/-
    -
    +/-
    +/-
    +
    +

    View Slide

  59. Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place transformation
    Copy and transformation
    Maintainability
    -
    +/-
    +/-
    +/-
    +
    +

    View Slide

  60. Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place transformation
    Copy and transformation
    Performance
    efficiency
    +
    +
    +
    +/-
    +/-
    -

    View Slide

  61. Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place transformation
    Copy and transformation
    Reliability
    +
    +
    +
    -
    -
    +

    View Slide

  62. Event operations
    Stream operations
    Store operations
    simple
    Store operations
    complex
    Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place
    transformation
    Copy and transform

    View Slide

  63. Can we execute this upgrade with zero downtime?
    Copyright SpaceX

    View Slide

  64. Event operations
    Stream operations
    Store operations
    simple
    Store operations
    complex
    Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place
    transformation
    Copy and transform
    These techniques
    are executed
    within the
    application
    These techniques
    need a separate
    stage

    View Slide

  65. Application deployments strategies

    View Slide

  66. Big Flip

    View Slide

  67. Big Flip

    View Slide

  68. Big Flip

    View Slide

  69. Big Flip

    View Slide

  70. Big Flip

    View Slide

  71. Big Flip

    View Slide

  72. Big Flip Blue / Green

    View Slide

  73. Big Flip Blue / Green

    View Slide

  74. Big Flip Blue / Green

    View Slide

  75. Big Flip Blue / Green

    View Slide

  76. Big Flip Blue / Green

    View Slide

  77. Big Flip Blue / Green Rolling Upgrade

    View Slide

  78. Big Flip Blue / Green Rolling Upgrade

    View Slide

  79. Big Flip Blue / Green Rolling Upgrade

    View Slide

  80. Event operations
    Stream operations
    Store operations
    simple
    Store operations
    complex
    Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place
    transformation
    Copy and transform
    Big Flip
    Blue / Green
    Rolling Upgrade

    View Slide

  81. Database deployments strategies

    View Slide

  82. Blue / Green

    View Slide

  83. Blue / Green

    View Slide

  84. Blue / Green

    View Slide

  85. Blue / Green

    View Slide

  86. Blue / Green Expand & Contract

    View Slide

  87. Blue / Green Expand & Contract

    View Slide

  88. Blue / Green Expand & Contract

    View Slide

  89. Event operations
    Stream operations
    Store operations
    simple
    Store operations
    complex
    Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place
    transformation
    Copy and transform
    Big Flip
    Blue / Green
    Rolling Upgrade
    Expand & Contract
    Blue / Green

    View Slide

  90. Event operations
    Stream operations
    Store operations
    simple
    Store operations
    complex
    In place
    transformation
    Copy and transform
    Big Flip
    Blue / Green
    Rolling Upgrade
    Expand & Contract
    Blue / Green

    View Slide

  91. Event operations
    Stream operations
    Store operations
    simple
    Store operations
    complex
    In place
    transformation
    Copy and transform
    Big Flip
    Blue / Green
    Rolling Upgrade
    Expand & Contract
    Blue / Green

    View Slide

  92. Event operations
    Stream operations
    Store operations
    simple
    Store operations
    complex
    Always extend
    Weak schema
    Upcasting
    Lazy transformation
    In place
    transformation
    Copy and transform
    Big Flip
    Blue / Green
    Rolling Upgrade
    Expand & Contract
    Blue / Green
    Mix & Match!

    View Slide

  93. What about the projections?

    View Slide

  94. View Slide

  95. How to keep your clients in sync?

    View Slide

  96. It depends. Your context. Your solution.

    View Slide

  97. Throw away with a reason
    It is an option!

    View Slide

  98. Time can be of help
    Expirations?

    View Slide

  99. You might not be Google
    Small enough to replay?

    View Slide

  100. Domain design helps
    Design and test before production

    View Slide

  101. Read our paper for more
    en
    And more is coming!

    View Slide

  102. Recommended!

    View Slide

  103. Copyright Nasa Goddard
    Michiel Overeem
    @michielovereem

    View Slide