Event

An Event describes something that happened. They are named in passed tense. For instance UserCreated. In Sequent Events are simple data objects with logical names describing what happened. In Sequent Events subclass from Sequent::Event. By subclassing from Sequent::Event you get 2 extra attributes: aggregate_id and sequence_number. Both form the unique key of an Event. Events are stored in the EventStore.

An example of an Event in Sequent:

class UserNameSet < Sequent::Event
  attrs name: String
end

To declare attributes you need to use the attrs keyword and provide it with a list of key value pairs containing the name and Type of the attribute.

You can of course add multiple attributes to an Event

class UserNameSet < Sequent::Event
  attrs firstname: String, lastname: String
end

You can also use attrs multiple times like

class UserNameSet < Sequent::Event
  attrs firstname: String
  attrs lastname: String
end

The attrs will respect inheritance hierachies.

You can also use ValueObject in Events.

class Name < Sequent::ValueObject
  attrs firstname: String, lastname: String
end

class UserNameSet < Sequent::Event
  attrs name: Name
end

Out of the box Sequent provides a whole set of Types you can use for defining your attribtutes.

Recommendations:
  • Keep Events small.
  • When an attribute changes use the same event. This makes it easier to keep track of state changes for instance in Projectors or Workflows etc.
  • Keep events as flat as possible. Overly nested ValueObject might seem to remove duplication, but is not always practical in usage.

Renaming Events: When running in production and you decide to rename an Event you must also update all EventRecords for this Event’s type.

Renaming attributes in Events: Since Events are stored as JSON in the EventStore renaming attributes in Events will break deserializing. If you want to change an attributes name anyway ensure you also update all Events in your EventStore as well.