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.
How the server works
Section titled “How the server works”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.
The EventSourceId type
Section titled “The EventSourceId type”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(); }}Kotlin does not support this workflow yet.Java does not support this workflow yet.Elixir does not support this workflow yet.TypeScript does not support this workflow yet.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.
The generic EventSourceId<T>
Section titled “The generic EventSourceId<T>”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 conceptpublic 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)); }}import io.cratis.chronicle.concepts.EventSourceIdimport io.cratis.chronicle.concepts.appendimport io.cratis.chronicle.eventSequences.IEventLogimport io.cratis.chronicle.events.EventTypeimport java.util.UUID
// A strongly typed domain concept, stored as a string on the wire.data class EventSourceIdCustomerId(val value: String) : EventSourceId { override fun value(): String = value
companion object { fun new() = EventSourceIdCustomerId(UUID.randomUUID().toString()) }}
@EventTypedata class EventSourceIdOrderPlaced(val customerId: EventSourceIdCustomerId, val total: Double)
class EventSourceIdOrderService(private val eventLog: IEventLog) { suspend fun placeOrder(total: Double) { val customerId = EventSourceIdCustomerId.new() eventLog.append(customerId, EventSourceIdOrderPlaced(customerId, total)) }}import io.cratis.chronicle.IEventStore;import io.cratis.chronicle.concepts.EventSourceId;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.java.BlockingEventStore;import java.util.UUID;
// A strongly typed domain concept, stored as a string on the wire.record EventSourceIdCustomerId(String value) implements EventSourceId { static EventSourceIdCustomerId newId() { return new EventSourceIdCustomerId(UUID.randomUUID().toString()); }}
@EventTyperecord EventSourceIdOrderPlaced(EventSourceIdCustomerId customerId, double total) {}
class EventSourceIdOrderService { private final BlockingEventStore store;
EventSourceIdOrderService(IEventStore store) { this.store = new BlockingEventStore(store); }
void placeOrder(double total) { var customerId = EventSourceIdCustomerId.newId(); store.getEventLog().append(customerId, new EventSourceIdOrderPlaced(customerId, total)); }}Elixir does not support this workflow yet.TypeScript does not support this workflow yet.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.
Frontend proxy generation
Section titled “Frontend proxy generation”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.
One event source id per event
Section titled “One event source id per event”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.