Getting started with event sourcing in Laravel

Getting started with event sourcing in Laravel

A1b4b398630bbd32b77a82cbc37fae9a?s=128

Freek Van der Herten

March 27, 2019
Tweet

Transcript

  1. 2.

    About me Freek Van der Herten Partner & developer at

    Spatie @freekmurze https://murze.be https://ohdear.app
  2. 3.

    Spatie Since 2003 Websites, applications and webshops Team 9 awesome

    human beings Specialisation Laravel, front-end development
  3. 5.

    We create a lot of it ± 200 packages on

    Packagist ± 2,000,000 downloads a month ± 30,000,000 total downloads All Postcardware!
  4. 11.
  5. 12.

    Traditional application Write data in database An update means overwriting

    the old data The old data cannot be accessed anymore
  6. 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...
  7. 22.
  8. 25.

    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
  9. 27.
  10. 29.

    Eventsauce Package made by Frank De Jonge Focuses on aggregates

    Framework agnostic Separate Laravel bindings package available Very powerful, adds complexity
  11. 34.

    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
  12. 35.

    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
  13. 36.

    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
  14. 37.

    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
  15. 38.

    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
  16. 39.
  17. 41.

    Summary Laravel Event Projector Easy to use package to get

    started with projections Hooks into Laravel's native events Replay capabilities No aggregates
  18. 42.

    Summary EventSauce Framework agnostic Support for aggregates, process modelling No

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