Skip to content

Cratis Chronicle event sources and streams

An event source is the thing whose history you record in Cratis Chronicle, such as a bank account or a shopping cart. An event source definition names that kind of thing and declares its streams and default concurrency dimensions, the fields that determine which appends can conflict. Append through the definition to reuse those names and concurrency settings across callers.

A stream is a named part of that history. An account might separate Onboarding from Transactions, then use a stream id to identify each month’s transactions. The definition keeps the stream names in one place. The client validates the selected stream before sending an append, and the kernel checks the routing against the registered definition. You can still append without a definition; the plain APIs accept routing values and derive a default concurrency scope.

using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.EventSources;
[EventType]
public record MoneyDeposited(decimal Amount);
[EventSource("Account", Description = "A customer's bank account", Concurrency = ConcurrencyDimensions.EventSourceId)]
[EventStream("Onboarding", Description = "Opening the account and verifying the customer")]
[EventStream(
"Transactions",
Description = "Deposits and withdrawals, one stream per month",
Concurrency = ConcurrencyDimensions.EventSourceId | ConcurrencyDimensions.EventStreamType | ConcurrencyDimensions.EventStreamId)]
public class AccountEventSource : IEventSource;
public static class Deposits
{
public static Task<AppendResult> Deposit(IEventLog eventLog, EventSourceId accountId, decimal amount, string month) =>
eventLog.Append<AccountEventSource>(
accountId,
new MoneyDeposited(amount),
eventStream: "Transactions",
eventStreamId: month);
}

View C# snippet source on GitHub

AccountEventSource carries the declaration; Chronicle never creates an instance of it. The deposit goes to one account’s Transactions stream, with the month as the stream id. Those three values define its concurrency scope. If two deposits capture the same tail and then write to that account and month, the second conflicts with the first. A deposit to another month does not match that scope. The first append into an empty scope is unchecked by default.

Four routing values identify where an event belongs. The definition supplies the source type and stream type; the caller supplies the instance ids.

Term What it is Where it comes from
EventSourceId The instance, such as one account The caller, on every append
Event source type (EventSourceType) The kind of event source, such as Account The definition’s name
Event stream type (EventStreamType) A named process of the event source, such as Transactions The name of a stream the definition declares
Event stream id (EventStreamId) One instance of a stream, such as 2026-04 The caller. Chronicle imposes no format

Each event also records the name of the definition it was appended through, in EventContext.EventSource. It is empty for events that were appended without a definition.

A definition-derived guard covers all event types in the selected source or stream. Use it when every append in that range can affect the same decision. For a rule that depends on only some event types, a decision read supplies a narrower condition based on the model you read.

The definition does not hold entity state or list the event types it owns. Routing belongs to the append, so the same event type can be appended through different definitions. Each event has exactly one event source and at most one stream.

Use one when:

  • Events of one kind of entity are written from several places and the routing strings must agree.
  • An entity has independent sub-histories, such as one stream per month, per author or per process step, and you want writers on different sub-histories not to conflict.
  • You want observers that handle only one stream.
  • You want to close one stream and keep the rest of the entity open. See Close a stream.

Skip it when every event of an entity can share one history and one guard. The plain append APIs are still valid and need no definition. See Questions and pitfalls.

Event source definitions are supported by the .NET, Kotlin, TypeScript and Elixir clients. The Kotlin, TypeScript, Elixir and Python packages under Source/Clients in this repository only hold generated kernel contracts. The examples in this section use .NET. Other clients have their own declaration and append APIs, and their concurrency behavior differs. Use their repositories for client-specific syntax and Where the clients differ for append and concurrency differences. The Workbench lists definitions registered with the kernel.

You want to Read
Declare an event source and its streams Define an event source
Write events through a definition Append through a definition
Choose what conflicts with what Concurrency
End a stream Close a stream
Let a reactor or reducer see one stream Filter observers
Move from [EventSourceType] and [EventStreamType] strings Migrate from string routing
See complete examples Scenarios
Understand registration, metadata and scope production How it works
Use a definition with a decision model and an append condition Dynamic Consistency Boundary
Find a quick answer or a pitfall Questions and pitfalls

Start with Define an event source to name your source and its streams, then append through it. For the underlying identity model, read Event source. Dynamic Consistency Boundary in Chronicle explains how definitions work with decision models and append conditions.