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

Getting started with event sourcing in Laravel

Getting started with event sourcing in Laravel

Freek Van der Herten

March 27, 2019
Tweet

More Decks by Freek Van der Herten

Other Decks in Programming

Transcript

  1. About me Freek Van der Herten Partner & developer at

    Spatie @freekmurze https://murze.be https://ohdear.app
  2. Spatie Since 2003 Websites, applications and webshops Team 9 awesome

    human beings Specialisation Laravel, front-end development
  3. We create a lot of it ± 200 packages on

    Packagist ± 2,000,000 downloads a month ± 30,000,000 total downloads All Postcardware!
  4. Traditional application Write data in database An update means overwriting

    the old data The old data cannot be accessed anymore
  5. 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...
  6. Laravel Event Projector Package made by Spatie It's not full

    event sourcing, it focuses on projections Beautifully integrated into Laravel Easy to get started with
  7. Eventsauce Package made by Frank De Jonge Focuses on aggregates

    Framework agnostic Separate Laravel bindings package available Very powerful, adds complexity
  8. AGGREGATE ROOT REPOSITORY ABC-123 Subtract 1000 11:12 AM UUID PAYLOAD

    TIME APP Subtract $1000 RETRIEVE Subtract $1000 AGGREGATE ROOT ACCOUNTS CONSUMER -$1000 (empty) PERSIST
  9. AGGREGATE ROOT REPOSITORY ABC-123 Subtract 1000 11:12 AM UUID PAYLOAD

    TIME APP RETRIEVE Subtract $750 AGGREGATE ROOT ACCOUNTS -$1000 CONSUMER Subtract $750 Subtract $1000 PERSIST
  10. AGGREGATE ROOT REPOSITORY ABC-123 Subtract 1000 11:12 AM ABC-124 Subtract

    750 01:17 PM UUID PAYLOAD TIME APP RETRIEVE Subtract $750 AGGREGATE ROOT ACCOUNTS -$1750 CONSUMER Subtract $750 Subtract $1000 PERSIST
  11. AGGREGATE ROOT REPOSITORY ABC-123 Subtract 1000 11:12 AM ABC-124 Subtract

    750 01:17 PM UUID PAYLOAD TIME APP RETRIEVE AGGREGATE ROOT ACCOUNTS -$1750 CONSUMER Subtract $1250 Subtract $1000 Subtract $750 Subtract $1250 More Money Needed PERSIST
  12. AGGREGATE ROOT REPOSITORY ABC-123 Subtract 1000 11:12 AM ABC-124 Subtract

    750 01:17 PM ABC-125 Subtract 1250 05:51 PM ABC-126 More Money Needed 05:51 PM UUID PAYLOAD TIME ACCOUNTS APP CONSUMER CONSUMER 2 PROPOSED LOANS Subtract $1250 -$3000 RETRIEVE PERSIST Subtract $1000 Subtract $750 Subtract $1250 More Money Needed AGGREGATE ROOT
  13. Summary Laravel Event Projector Easy to use package to get

    started with projections Hooks into Laravel's native events Replay capabilities No aggregates
  14. Summary EventSauce Framework agnostic Support for aggregates, process modelling No

    replay capabilities out of the box https://github.com/spatie/laravel-eventsauce