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

Event Sourcing in Laravel (Full Stack Ghent)

Event Sourcing in Laravel (Full Stack Ghent)

Freek Van der Herten

April 10, 2019
Tweet

More Decks by Freek Van der Herten

Other Decks in Programming

Transcript

  1. Getting started with
    event sourcing in Laravel

    View Slide

  2. About me
    Freek Van der Herten
    Partner & developer at Spatie
    @freekmurze
    murze.be
    ohdear.app

    View Slide

  3. Spatie
    Laravel, front-end development
    Since 2003
    9 awesome human beings

    View Slide

  4. Open Source 

    Software

    View Slide

  5. We create a lot of it
    ± 200 packages on Packagist
    ± 2,000,000 downloads a month
    ± 30,000,000 total downloads
    All Postcardware!

    View Slide

  6. Highlights
    Popular
    laravel-backup
    laravel-medialibrary
    laravel-permission
    New
    laravel-query-builder
    laravel-blade-x

    View Slide

  7. https://spatie.be/open-source

    View Slide

  8. https://spatie.be/open-source/postcards

    View Slide

  9. Let's talk about
    event sourcing

    View Slide

  10. Talk overview
    Theory
    Projectors demo
    Aggregates demo

    View Slide

  11. Theory

    View Slide

  12. Traditional application
    Write data in database
    An update means overwriting the old data
    The old data cannot be accessed anymore

    View Slide

  13. APPLICATION
    DATABASE
    TABLE
    value X

    View Slide

  14. APPLICATION
    DATABASE
    TABLE
    value X
    value Y

    View Slide

  15. Event Sourced Application
    The application will fire off events
    Events will get written in a dedicated store
    Events are passed to consumers that create projections
    Aggregate, Aggregate Root...

    View Slide

  16. APP EVENTS
    Event
    Event 1

    View Slide

  17. APP EVENTS
    Event
    Event 1
    Event 2

    View Slide

  18. APP EVENTS
    Event
    Event 1
    Event 2
    Event 3

    View Slide

  19. APP
    CONSUMER
    EVENTS
    PROJECTION
    Event
    Event 1
    Event 2
    Event 3

    View Slide

  20. APP
    CONSUMER
    CONSUMER 2
    EVENTS
    PROJECTION
    Event
    Event 1
    Event 2
    Event 3
    ANOTHER PROJECTION

    View Slide

  21. APP
    CONSUMER
    CONSUMER 2
    EVENTS
    PROJECTION
    Event
    Event 1
    Event 2
    Event 3
    ANOTHER PROJECTION

    View Slide

  22. APP
    CONSUMER
    CONSUMER 2
    EVENTS
    PROJECTION
    Event
    Event 1
    Event 2
    Event 3
    Event 4
    ANOTHER PROJECTION

    View Slide

  23. Event Sourced Application
    Auditing requirements
    Extra reports needed
    Recording the unhappy path
    There is some setup required

    View Slide

  24. Laravel 

    Event Projector

    View Slide

  25. Laravel Event Projector
    Package made by Spatie
    Aggregates, Projectors & Reactors
    Beautifully integrated into Laravel
    Easy to get started with

    View Slide

  26. https://docs.spatie.be/laravel-event-projector

    View Slide

  27. Demo

    View Slide

  28. Aggregates

    View Slide

  29. View Slide

  30. View Slide

  31. View Slide

  32. View Slide

  33. View Slide

  34. View Slide

  35. Demo

    View Slide

  36. In closing

    View Slide

  37. Summary
    Laravel Event Projector
    Easy to use package to get started with event sourcing
    Projectors
    Replay capabilities
    Aggregates

    View Slide

  38. Writes are harder, reads are easier

    View Slide

  39. Event sourcing makes the easy things harder…
    …and the harder things easier
    — Frank De Jonge

    View Slide

  40. Larabank
    github.com/spatie/larabank-traditional
    github.com/spatie/larabank-event-projector
    github.com/spatie/larabank-event-projector-aggregates
    github.com/spatie/larabank-eventsauce

    View Slide

  41. Resources
    kickstarter.engineering/event-sourcing-made-simple-4a2625113224
    github.com/spatie/laravel-event-projector
    github.com/eventsaucephp/eventsauce
    github.com/prooph

    View Slide

  42. Thank you!
    speakerdeck.com/freekmurze/event-sourcing-full-stack-ghent
    spatie.be/open-source
    murze.be
    ohdear.app

    View Slide