Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

My first year with event sourcing-symfonycon


Published on

Over the last couple of years, I have heard of Event sourcing but didn't really know where to start until I did a tutorial at DPC '17. After having some basic information it was time to start a Hackathon and after that something production worthy. In this talk I will try to give the best information to get started and to know some of the problems you can face if you begin event-sourcing.

Published in: Software
  • Be the first to comment

My first year with event sourcing-symfonycon

  1. 1. My first year with event-sourcing And a little bit about tracking your beer Tim Huijzers
  2. 2. Tim Huijzers Dragem or Webbaard Developer @ Founder of DeventerPHP Usergroup
  3. 3. First Try ● Limited knowledge ● No experience ● No ES framework ● Doomed from the start
  4. 4. Second Try ● Limited knowledge ● Limited experience ● New Framework ● New DI manager ● New ES Framework ● Doomed To Fail
  5. 5. Third Try ● Some knowledge ● Some experience ● Known framework ● known database ● known ES framework ● Still doomed
  6. 6. BeerWarehouse
  7. 7. Why use Event Sourcing
  8. 8. CRUD
  9. 9. We will save a new entry in our system because we just bought it and will store it in the fridge for later.
  10. 10. If we change the location the system only knows about that location.
  11. 11. We drank it so it’s not in the system anymore
  12. 12. We want to keep a history of everything we drank.
  13. 13. I want to know when I drank this in my history.
  14. 14. But that’s only for new beers.
  15. 15. Events
  16. 16. Same Information as before + Explicit action about what happened
  17. 17. Make Small Events
  18. 18. Removed Location and changed name because in the real world you might not know this yet.
  19. 19. When returning home I put the beer in my fridge
  20. 20. I need room in my fridge so I take it out. Using the same Event
  21. 21. And at last a event about when I consumed it.
  22. 22. Crud ● I know what beer I have. ● I know when it was consumed. ● I know where it is. Event-Sourcing ● I know what beer I have. ● I know when it was consumed. ● I know where it is. ● I know where it was before. ● I know when it was moved. ● I know where it was at any point in time ● I know how many times it was moved. ● I know when it was added to the system. ● I know what else was moved in that day.
  23. 23. “Every software program relates to some activity or interest of its user.” Eric Evans, Domain-Driven Design: Tackling Complexity in the Heart of Software
  24. 24. When To Use Event Sourcing
  25. 25. ● You need an audit log ● You like scalability ● You want to separate the read and write of an application ● You want to replay event on a dev machine to get an accurate situation of what the state was at a point in time. ● You want reporting but don’t know what yet. ● You are done with mapping objects to tables
  26. 26. When NOT To Use Event Sourcing
  27. 27. ● You only need a simple CRUD system. ● You are processing a lot of personal data. ● You just want to query a lot of things on the DB ● You are starting on a big project for production
  28. 28. Event Sourcing in code
  29. 29. Prooph
  30. 30.
  31. 31. Command
  32. 32. Command Handler
  33. 33. Aggregate
  34. 34. Event
  35. 35. Back to the Aggregate
  36. 36. Think About Side Effects
  37. 37. What about Symfony?
  38. 38. Structuring your application
  39. 39. Understanding the DB
  40. 40. How many beers do I have?
  41. 41. How many different styles do I have?
  42. 42. How many beers have I drank last 30 days?
  43. 43. Projection
  44. 44. A Projection allows you to loop through all event (past and present) and build your own views. ● Read Model ○ Define the data you would like to use. ● Projection ○ Loops through the events and applies that data to your view ● Finder ○ Helps you find data from that view.
  45. 45. Pitfalls
  46. 46. Refactoring is harder, think about your architecture
  47. 47. Versioning ● Change an Event but support the old version ● Make a new Event ● Make the Event right from the start
  48. 48. Something wrong with the event
  49. 49. Event are immutable, So don’t change them ● Try solving it another way first. ● Correct errors with new events ● Try a upcaster ● Make a new stream and fill it with mutated events (and test) ● Change the events in the database
  50. 50. But what if I have like 100 trillion gazillion events?
  51. 51. Snapshots
  52. 52. You Do Not Need Snapshots From The start
  53. 53. Trigger on Event Count
  54. 54. Pure Event Sourcing Is Not A Holy Grail
  55. 55. Do Not Save Personal Data In Events
  56. 56. Make Projections For All You Lists
  57. 57. Try It In A Hackathon First
  58. 58. Most Of The Time Your DB Is Not Holy
  59. 59. What Now?
  60. 60.
  61. 61. Source
  62. 62. Other Tools ● Broadway ○ No Upcaster, ○ No Snapshots, ○ No Replaying ● Axon ○ Upcasting by MessageFactory, ○ Snapshots by Trigger on event count, ○ Replaying by Example code for replay ● Akka ○ Upcasting by Event Adapter, ○ Snapshots decided by actor, ○ Replaying
  63. 63. Thanks, Any Questions? Example code from talk on: Slides of this talk on notulist: