Skip to content

Getting a Single Instance

When you need one read model and correctness matters more than query latency, read it by key from the event store. Chronicle rebuilds the instance from the events that feed that read model, so the result reflects the events that have been appended up to that call.

Use this path for command-side decisions, read-after-write flows, and diagnostic tools. Use materialized read models when the same data is read frequently by lists, dashboards, or user interfaces that need paging.

When you ask Chronicle for one read model instance, the client sends the read model type and key to the kernel. Chronicle resolves the projection or reducer that owns that read model, replays the relevant events, applies compliance release rules when needed, and returns the current shape for that key.

This makes the read strongly consistent. The cost is replay: longer histories take longer to rebuild than a materialized lookup.

The read model type must already be registered by the client, either as a model-bound projection, a declarative projection, or the read model produced by a reducer.

AccountInfo? account = await eventStore.ReadModels.GetInstanceById<AccountInfo>(accountId);
if (account is not null)
{
Console.WriteLine($"{account.Name}: {account.Balance:C}");
}

Each client names the operation in its own idiom, but the inputs are the same: the read model type and the read model key.

If no events have produced that read model key, clients return their normal “not found” shape: null, nil, or an empty result depending on the language. Treat that as “no state exists yet,” not as a projection failure.

If the read model type itself is unknown, that is a configuration error. Register the projection, reducer, or read model before querying it.

Use a single-instance replay when:

  • A command needs the exact current state before making a decision.
  • You append an event and immediately need to read the state it creates.
  • A debugging or audit tool needs deterministic state from the event log.
  • The event history for that key is short enough that replay cost is acceptable.

Prefer a materialized read model when:

  • The same data is read often.
  • The history for each key can grow large.
  • You need paging, sorting, or database-native filtering.
  • Eventual consistency is acceptable.