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 full-size slide

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

    View full-size slide

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

    View full-size slide

  4. Open Source 

    Software

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. Let's talk about
    event sourcing

    View full-size slide

  10. Talk overview
    Theory
    Projectors demo
    Aggregates demo

    View full-size slide

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

    View full-size slide

  12. APPLICATION
    DATABASE
    TABLE
    value X

    View full-size slide

  13. APPLICATION
    DATABASE
    TABLE
    value X
    value Y

    View full-size slide

  14. 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 full-size slide

  15. APP EVENTS
    Event
    Event 1

    View full-size slide

  16. APP EVENTS
    Event
    Event 1
    Event 2

    View full-size slide

  17. APP EVENTS
    Event
    Event 1
    Event 2
    Event 3

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  23. Laravel 

    Event Projector

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. Writes are harder, reads are easier

    View full-size slide

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

    View full-size slide

  29. 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 full-size slide

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

    View full-size slide

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

    View full-size slide