Skip to content

Chronicle event source questions and pitfalls

Event source definitions in Cratis Chronicle give appends and observer filters a shared set of names without rewriting stored events. Use these answers when choosing whether to add a definition or diagnosing an unexpected filter or concurrency result.

What is the difference between an event source, a stream and a tag?

Section titled “What is the difference between an event source, a stream and a tag?”

An event source is one instance of a kind of thing, such as one account. Its EventSourceId identifies the instance; its event source type identifies the kind and comes from the definition’s name. A stream is a named part of that history, such as one month’s transactions, identified by an event stream type and an event stream id.

A tag is a label on an event that you can filter by. Event source and stream values can narrow a concurrency scope, the set of events checked for conflicting writes. Tags cannot. See Event source and Appending with tags.

Can an event belong to two event sources or two streams?

Section titled “Can an event belong to two event sources or two streams?”

No. Each event has one event source id and one stream. A fact that concerns two entities is written as one event per event source, in one atomic append. See Append for several event sources and Dynamic Consistency Boundary in Chronicle.

Is the event source id part of the definition?

Section titled “Is the event source id part of the definition?”

No. The definition declares the kind, while each append supplies the instance’s id. One account definition serves all accounts; you do not create a new definition for each account.

Skip it when:

  • One history and one guard per entity are enough. Plain appends with an event source id need nothing else.
  • The rule is a unique value or a create-once rule. A constraint enforces it for every writer, with or without a definition.
  • The streams would be created from data you do not control. A definition declares streams ahead of time. Stream ids can vary freely, but stream types are a closed list.
  • You need the unit of work’s Transactional appends to use the declared names. They take the routing values directly.

What happens when I rename an event source or a stream?

Section titled “What happens when I rename an event source or a stream?”

The definition’s names are written on every event, so a rename is a data change, not a refactoring:

  • Events already stored keep the old event source type and event stream type. Observers that filter on the new name do not see them.
  • The kernel keeps the old registration, because stored events refer to it. Registering the new name adds a second definition.
  • If you rename a stream inside a definition, the registered definition is replaced. Appends to the old stream name are rejected, but stored events keep it.
  • Closures follow their declared dimensions. By default, [ClosesStream] uses the event source id, stream type and stream id, so renaming the event source type alone does not bypass a closure. Renaming the stream type addresses a different scope. If you customize the closing dimensions, check which renamed values participate. See Close a stream.

For a wording change, keep the stored name and put the new wording in Description. If new events must use a new name, plan how observers will handle both names for as long as they need the old history.

Can a stream turn off its event source’s concurrency dimensions?

Section titled “Can a stream turn off its event source’s concurrency dimensions?”

No. A stream with None inherits the event source’s dimensions. Declare the dimensions you want on the stream. See Concurrency.

Why did two concurrent first appends both succeed?

Section titled “Why did two concurrent first appends both succeed?”

The first append into a scope has nothing to compare with, so the kernel skips the check by default. Turn on CheckFirstAppendIntoAScope, or use ExpectingNoMatchingEvent() for one append. See The first append into a scope.

Why did my batch throw IncompatibleConcurrencyScopesForEventSource?

Section titled “Why did my batch throw IncompatibleConcurrencyScopesForEventSource?”

The batch needs different guards for one event source id, but the connected kernel does not advertise concurrency-scope-conjunctions. Upgrade the kernel to keep the guards separate and validate them atomically. A deliberately broader explicit scope is an alternative when it covers the whole decision. See A batch that needs two guards.

Why does my observer not see events I appended?

Section titled “Why does my observer not see events I appended?”

Observers match the stored event source type and event stream type, not the C# definition type. Check that the append names the intended stream: an append without one uses the default stream type and will not match a filter for a named stream. Compare the spelling and casing of both stored names with the filter. If the events predate a move to definitions, follow Migrate from string routing; Filter observers explains the matching rules.

Does a definition limit which event types I can append?

Section titled “Does a definition limit which event types I can append?”

No. It carries no list of event types. Any event type can be appended through any definition.

Can I use a secret or personal data as an event source id?

Section titled “Can I use a secret or personal data as an event source id?”

No. Event source ids are stored in plaintext and cannot be encrypted. See Event source id and Concurrency.

Does a definition replace a decision read?

Section titled “Does a definition replace a decision read?”

No. A definition supplies a default guard for an append. A decision read builds a guard from the state you read to make a decision, such as whether a withdrawal stays within a monthly limit. Use them together when the rule depends on that state. See Dynamic Consistency Boundary.

Start with Event sources and streams if you are choosing a structure for your histories. For concrete scope choices, use Scenarios; for discovery, registration and kernel checks, read How it works.