Events

What is an Event?

In DDD meaning

Domain Event: a data structure representing one domain change

An event is something that has happened in the past

  • It's a fact
  • It's a struct
  • It's a mutation

Issues: naming

  • Past tense
    • ItemAdded
    • ProductOrdered
    • InvoiceEmailChanged
  • Noun(s) + verb
    • Mutated thing + action
  • Use Domain Language

Issues: granularity

TL;DR

It's tricky

Small

  • AddressChanged
  • EmailChanged
  • FirstNameChanged

Big

  • ProfileChanged
  • More flexibility
  • Less "ifs" in event handlers but more "ifs" in command handlers
  • Better language
  • Possibly many events to handle after a single request
  • Requires routing for handling
  • Complex actions = heavy methods
  • Fragile for changes and nulls
  • Redundant data on small changes

Essential details

  • every related aggregate id
  • timestamp
  • version number
  • mutated data

Bonus thoughts

  • You don't need DDD to start emitting events
  • You don't need CQRS to start emitting events
  • You don't need handlers to start emitting events
  • audit log of changes
  • force to think about domain
    • language
    • transactions
    • triggers

Questions?

Made with Slides.com