CQRS & Event Sourcing in OLX

CQRS & Event Sourcing in OLX

33d8f6c5f5c8b940ff4d6422a5f32b02?s=128

Łukasz Szymański

May 16, 2016
Tweet

Transcript

  1. CQRS Event Sourcing in OLX

  2. CQRS

  3. you can use a different model to update information than

    the model you use to read information http://martinfowler.com/bliki/CQRS.html „
  4. Command Query Responsibility Segregation

  5. Command Query Responsibility Segregation

  6. new AddCredits($userId, $amount); Command

  7. Command new AddCredits($userId, $amount); Query new GetCredits($userId);

  8. Event Sourcing

  9. http://www.martinfowler.com/eaaDev/EventSourcing.html „ ensures that all changes to application state are

    stored as a sequence of events
  10. Not just can we query these events, we can also

    use the event log to reconstruct past states http://www.martinfowler.com/eaaDev/EventSourcing.html „
  11. Commad Event Model Event Storage Event Bus Command Handler Listeners

    Read Storage Read Model Query
  12. Commad Event Model Event Storage Event Bus Command Handler Listeners

    Read Storage Read Model Query Critical section - use transaction
  13. Commad Event Model Event Storage Event Bus Command Handler Listeners

    Read Storage Read Model Query Critical section - use transaction Treat like temporary cache
  14. That’s all

  15. E-Wallet Credits; Invoices; Refunds

  16. Wallet Credits Bonus Credits Refund Credits EXPIRE: X DAYS EXPIRE:

    X DAYS EXPIRE: X DAYS INVOICE: YES/NO INVOICE: YES/NO INVOICE: YES/NO
  17. Wallet Credits Bonus Credits Refund Credits EXPIRE: NEVER EXPIRE: 90

    DAYS EXPIRE: 90 DAYS INVOICE: YES INVOICE: NO INVOICE: YES
  18. Opis walleta w Polsce specyfikacja komenty enventy Commands

  19. Add Wallet Credits Add Bonus Credits Add Refund Credits

  20. Sub Wallet Credits Sub Bonus Credits Sub Refund Credits SubCredits

  21. Opis walleta w Polsce specyfikacja komenty enventy Events

  22. Wallet CreditsWasAdded Bonus CreditsWasAdded Refund CreditsWasAdded

  23. Wallet CreditsWasSubtracted Bonus CreditsWasSubtracted Refund CreditsWasSubtracted

  24. specyfikacja komenty enventy 7 commands 6 events

  25. specyfikacja komenty enventy What about other stuff?

  26. Commad Event Model Event Storage Event Bus Command Handler Listeners

    Read Storage Read Model Query ?
  27. Broadway komponenty Broadway https://github.com/qandidate-labs/broadway

  28. Auditing log whether commands were successful or not

  29. CommandHandling Provides the interface and a CommandHandler base class for

    handling events
  30. Domain domain abstractions of the Broadway framework including the aggregate

    root, domain messages and domain events.
  31. EventDispatcher The component provides an event dispatcher interface and a

    simple implementation
  32. EventHandling provides interfaces for an event bus and event listeners,

    but also an implementation of a simple event bus and an event bus that will record published events
  33. EventSourcing Provides base classes for event sourced aggregate roots and

    entities, an event sourced repository implementation and testing helpers.
  34. EventStore implementation based on doctrine/dbal to store events in a

    relational database and an in-memory implementation that is useful for using in tests
  35. ReadModel provides storage for your read models, a projector implementation

    to create read models from event streams and testing helpers.
  36. Repository Component providing an abstraction of the storage of aggregates.

  37. Serializers provides a simple serializer interface and a serializer implementation

    based on "handwritten" serializers
  38. Commad Event Model Event Storage Event Bus Command Handler Listeners

    Read Storage Read Model Query Broadway
  39. Adding Wallet Credits

  40. None
  41. None
  42. Credits Query

  43. None
  44. None
  45. Lessons Learned

  46. Small Steps Don’t try to CQRS/EventSource everything

  47. Keep It Simple Avoid names like BonusCreditsWasSubtractedBecauseAdminHitSubtractBonusCr editsInAdminPanelEvent

  48. Event Storming is not that easy as it sounds

  49. It’s not RDBM Remember about analysts

  50. Code changes Events handle changes to data, what about changes

    to code?
  51. Synchronize Remember about synchronizing read layer - especially after fail

  52. Commad Event Model Event Storage Event Bus Command Handler Listeners

    Read Storage Read Model Query Critical section - use transaction
  53. Performance is not an issue - for this case

  54. Timezone Agnostic Implement your own EventStore if you want timezone

    aware records
  55. Our Team

  56. Paid Features

  57. Next challenge Open source Paid Features libraries with Hexagonal Architecture

    in mind
  58. Team Lead PHP Dev Junior PHP Dev You ?

  59. Łukasz Szymański Development Team Lead at @szymanskilukasz http://szymanskilukasz.github.io/ https://www.linkedin.com/in/szymanskilukasz https://twitter.com/szymanskilukasz