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 State — user and artist entities.
Anatomy of an event
| Part | Description |
|---|---|
| Type | SCREAMING_SNAKE_CASE, past tense — ARTIST_FOLLOWED, not FOLLOW_ARTIST |
state | Which entity type owns this event |
entity_expr | Resolves entity ID from payload — usually event.user_id |
payload | Fields 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: stringShow 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: stringNaming
| Do | Don’t |
|---|---|
ARTIST_FOLLOWED | FOLLOW_ARTIST |
SHOW_ANNOUNCED | ANNOUNCE_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:
- Timeline — Decision Log: rule trace and emits
- Ledger — Ledger Events: committed patches
Concert app so far
concert-app/
app.causet
states/
user.state.causet
artist.state.causet
events/
follow.events.causet
show.events.causetNext steps
- Your First Intent —
FOLLOW_ARTISTandANNOUNCE_SHOW - Events — naming, metadata, versioning