Skip to content

Choose a Chronicle event source id

An event source id groups the events for one entity within a Chronicle event sequence. For an order, use the same order identifier when appending its placement, payment, and cancellation events. Every appended event has one event source id; changing it puts the new event in a different group.

Choose a stable, non-sensitive value. Event source ids are stored as plaintext metadata, so do not use a secret or personal data as the id. Use a surrogate identifier and keep personal values in protected event content instead; see Personal data in events.

Internally, Chronicle represents all event source identifiers as plain strings. This keeps the server and storage layer simple and schema-independent: the server does not need to know whether your identifier is a Guid, an integer, or a domain concept. Any type you use on the client side is serialized to its string representation before it reaches the server.

In .NET, the EventSourceId record wraps a string value and provides implicit conversions from both string and Guid. You can pass either directly where the API expects an EventSourceId:

using Cratis.Chronicle.Events;
public static class EventSourceIdConversionExamples
{
public static void FromGuid()
{
// From a Guid — common for aggregate-style identifiers
EventSourceId id = Guid.NewGuid();
}
public static void FromString()
{
// From a string — useful for natural keys
EventSourceId id = "order-42";
}
public static void Generated()
{
// Generate a new random identifier
EventSourceId id = EventSourceId.New();
}
}

View C# snippet source on GitHub

The Unspecified sentinel value signals the absence of a meaningful identifier and corresponds to an empty string. Use it when an identifier is structurally required but contextually irrelevant.

In .NET, EventSourceId<T> keeps the identifier’s underlying type in your client code, then converts it to the string-backed EventSourceId for the server. Use it when callers should work with a domain identifier instead of passing strings through every layer:

using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
// A strongly-typed domain concept
public record EventSourceIdCustomerId(Guid Value) : EventSourceId<Guid>(Value)
{
public static EventSourceIdCustomerId New() => new(Guid.NewGuid());
}
[EventType]
public record EventSourceIdOrderPlaced(EventSourceIdCustomerId CustomerId, decimal Total);
public class EventSourceIdOrderService(IEventLog eventLog)
{
public Task PlaceOrder(decimal total)
{
var customerId = EventSourceIdCustomerId.New();
// The typed identifier converts implicitly to EventSourceId — no manual conversion needed
return eventLog.Append(customerId, new EventSourceIdOrderPlaced(customerId, total));
}
}

View C# snippet source on GitHub

The implicit conversion lets you pass the typed value directly to IEventLog.Append or another API expecting EventSourceId. The client-side type helps distinguish domain identifiers; it does not change how Chronicle groups their stored string values.

When you use EventSourceId<T> in a command or query parameter, the Arc ProxyGenerator uses the underlying type T to determine the generated TypeScript type. The generic wrapper does not become a separate frontend identifier type.

See Arc type mapping for details on how proxy generation works and how to configure it.

When one operation changes two entities, give each entity its own event and event source id, then commit the events together with Appending many. A transfer, for example, records a withdrawal for one account and a deposit for the other. Tags cannot stand in for a second event source id in a consistency check.

Dynamic Consistency Boundary in Chronicle explains how one decision can guard several event sources. To declare the kind of event source and its named streams, continue with Event sources and streams.