LearnYour First Event

Your First Event

Continuing the concert app: events are past-tense facts appended to the ledger. Register every event type before referencing it in intents or projections.

Project: Set up with causet init and choose Concert app. Open events/ in your project.

Prerequisite: Your First Stateuser and artist entities.


Anatomy of an event

PartDescription
TypeSCREAMING_SNAKE_CASE, past tense — ARTIST_FOLLOWED, not FOLLOW_ARTIST
stateWhich entity type owns this event
entity_exprResolves entity ID from payload — usually event.user_id
payloadFields you declare; runtime adds type, ts, entity_id

Never declare type, ts, or entity_id in payload — the runtime sets those.


Follow events (user stream)

# events/follow.events.causet
events:
  ARTIST_FOLLOWED:
    state: user
    entity_expr: event.user_id
    payload:
      user_id:   string
      artist_id: string
 
  ARTIST_UNFOLLOWED:
    state: user
    entity_expr: event.user_id
    payload:
      user_id:   string
      artist_id: string

Show events (artist stream)

# events/show.events.causet
events:
  SHOW_ANNOUNCED:
    state: artist
    entity_expr: event.artist_id
    payload:
      artist_id: string
      show_id:   string
      venue:     string
      date:      string
      title:     string

Naming

DoDon’t
ARTIST_FOLLOWEDFOLLOW_ARTIST
SHOW_ANNOUNCEDANNOUNCE_SHOW

Events describe what happened, not commands.


How events reach the ledger

Events are emitted by intents — clients submit intents, not raw events. See Your First Intent.

At commit time the runtime appends to ledger_events, updates the entity snapshot, and publishes to Kafka for projection workers.


Verify in the ledger

After submitting FOLLOW_ARTIST or ANNOUNCE_SHOW:


Concert app so far

concert-app/
  app.causet
  states/
    user.state.causet
    artist.state.causet
  events/
    follow.events.causet
    show.events.causet

Next steps