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

DomCode 2017 - The Dark Side of Event Sourcing

DomCode 2017 - The Dark Side of Event Sourcing

"Event sourcing is easy!" they said. "Just record all of your user events" they said. "They're always useful." they said. So you did. You kept all the events. All of them. And now that you have them, there's just one question on your mind: How the heck do I manage all of it?!

Fear not. This month, two speakers we have. Powerful event wizards they are. Speak about the Dark Side of Event Sourcing they will. Remember: Collection leads to storage. Storage leads to maintenance. Maintenance leads to legacy. Legacy...leads to suffering.

Michiel Overeem

March 28, 2017
Tweet

More Decks by Michiel Overeem

Other Decks in Technology

Transcript

  1. Lead Software Architect @ AFAS Software PhD Candidate @ University

    Utrecht @michielovereem Software Architect @ AFAS Software @martenspoor
  2. How can an event sourced system be upgraded efficiently when

    the (implicit) event schema changes? Operations Techniques Strategies
  3. Event sourcing Event BankAccountCreated (accountId: 1234567, balance: 0, owner: Michiel);

    accountId balance owner 1234567 0 Michiel Current state Event sourcing
  4. Event sourcing Event BankAccountCreated (accountId: 1234567, balance: 0, owner: Michiel);

    DepositPerformed (accountId : 1234567, amount: 100, balance: 100); accountId balance owner 1234567 100 Michiel Current state Event sourcing
  5. Event sourcing Event BankAccountCreated (accountId: 1234567, balance: 0, owner: Michiel);

    DepositPerformed (accountId : 1234567, amount: 100, balance: 100); WithdrawalPerformed (accountId: 1234567, amount: 50, balance: 50); accountId balance owner 1234567 50 Michiel Current state Event sourcing
  6. Event sourcing Event BankAccountCreated (accountId: 1234567, balance: 0, owner: Michiel);

    DepositPerformed (accountId : 1234567, amount: 100, balance: 100); WithdrawalPerformed (accountId: 1234567, amount: 50, balance: 50); OwnerChanged (accountId: 1234567, newOwner: Marten); accountId balance owner 1234567 50 Marten Current state Event sourcing
  7. The structure of an Event Store type Attribute = (string,

    System.Object) type Event = (string, Attribute[]) type EventStream = (string, (DateTime, Event[])[] type EventStore = EventStream[]
  8. But there is also a schema Which streams are known

    in the system? Which events are allowed in which streams? Which attributes are allowed in which events?
  9. Split attribute in event CustomerSignedUp FullName: string We chose the

    wrong attributes for name CustomerSignedUp FirstName: string SurName: string
  10. Split event in stream We created events that were to

    large OptInOnNewsLetter CustomerSignedUp
  11. Split streams We found new streams Customer Stream CustomerSignedUp PriviligeUpgraded

    … Newsletter subscribers Stream OptInOnNewsLetter … …
  12. 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 How can we change it?
  13. How to execute these operations? Data upgrade Application upgrade Executed

    by Basic & Complex Event Basic & Complex Stream Basic & Complex Store Techniques Strategies
  14. Multiple versions: always extend Webshop EventStore Customer Stream ShoppingCart Stream

    CustomerSignedUp PriviligeUpgraded … AddedToChart ChangedQuantity …
  15. Multiple versions: always extend Webshop EventStore Customer Stream ShoppingCart Stream

    CustomerSignedUp PriviligeUpgraded … AddedToChart ChangedQuantity … CustomerSignedUp_V2
  16. Weakening the schema Which attributes can occure in which events?

    Which events can occure in which streams? Which streams can originate in the system?
  17. Webshop EventStore Customer Stream ShoppingCart Stream CustomerSignedUp PriviligeUpgraded … Upcasters:

    Evolve the events AddedToChart ChangedQuantity … CustomerSignedUp_V2
  18. Webshop EventStore 2 Stream boundaries: sharding Webshop EventStore 1 Customer

    Stream ShoppingCart Stream CustomerSignedUp PriviligeUpgraded … AddedToChart ChangedQuantity …
  19. How to execute these other operations? Techniques Data upgrade Application

    upgrade Executed by Executed by Basic & Complex Event Basic & Complex Stream Basic Store Complex Store Lazy transformation Upcasting Multiple versions Weak schema Strategies
  20. Multiple versions Weak schema Upcasters Lazy transformation In place transformation

    Copy and transformation +/- - +/- +/- + + Operation completeness
  21. Multiple versions Weak schema Upcasters Lazy transformation In place transformation

    Copy and transformation - +/- +/- +/- + + Maintainability
  22. Multiple versions Weak schema Upcasters Lazy transformation In place transformation

    Copy and transformation + + + +/- +/- - Performance efficiency
  23. Copyright SpaceX Data upgrade Application upgrade Executed by Executed by

    Basic & Complex Event Basic & Complex Stream Basic Store Complex Store Lazy transformation Upcasting Multiple versions Weak schema In place transfor- mation Copy and transfor- mation But how to deploy them? Strategies
  24. Combining everything into a framework Data upgrade Deployed with Executed

    by Executed by Data upgrade Application upgrade Lazy transformation Upcasting In place transfor- mation Multiple versions Copy and transfor- mation Basic & Complex Event Basic & Complex Stream Basic Store Complex Store Big Flip Rolling Upgrade Blue-Green Expand- Contract Blue- Green Deployed with Combined with Weak schema
  25. What’s next? 1. Do interviews. Interested? Contact me! https://goo.gl/forms/7tuBKW39EPkWnZLG3 2.

    Write a follow up paper with more information. 3. Publish the experiences in some form.