Skip to content

Orleans Journaling overview

Orleans Journaling is an experimental persistence model that records mutations to durable values and collections in an ordered per-grain journal. When a grain activates, Orleans replays that journal to reconstruct its in-memory state. A single write can persist changes from multiple durable states owned by the grain.

A journaling grain derives from DurableGrain and receives named durable states through keyed dependency injection. Orleans currently provides:

Mutations update the activation’s in-memory state and add encoded operations to its pending journal buffer. Await WriteStateAsync at the application durability point. The returned task completes after the storage provider acknowledges the append or snapshot replacement.

Each named state has a stable stream identity within the grain journal. Keep those names stable across deployments so recovery can bind stored operations to the intended state.

  1. During activation setup, Orleans reads the journal in order and replays each state stream.
  2. Grain code synchronously mutates durable values and collections during a grain turn.
  3. WriteStateAsync gathers pending operations for the grain and submits one atomic journal append or replacement to storage.
  4. The storage provider can request compaction when its configured size or row threshold is reached. The next write creates a snapshot of the current durable states and atomically replaces the journal.
  5. A later activation replays the latest snapshot and subsequent operations to restore the same durable state.

For the detailed guarantees, see Runtime behavior and consistency.

JSON Lines is the default write format. Each line contains a state stream identifier and one encoded operation. Configure source-generated JsonSerializerContext metadata for journaled key, value, and state types when using trimming or Native AOT.

The earlier Orleans binary format remains registered so deployments can read existing data. Providers store the journal format key with the journal. When the configured write format differs from the stored format, recovery uses the stored reader and the next write snapshots the journal in the configured format.

See Configure Journaling for format and migration guidance.

Orleans offers two separate journal-oriented programming models:

ModelApplication state modelPersistence coordination
Orleans JournalingMutable durable values and collections on DurableGrainOne per-grain journal managed by Microsoft.Orleans.Journaling
Orleans Event SourcingApplication-defined events applied to JournaledGrain<TState, TEvent>Log-consistency providers confirm, persist, and synchronize events

Choose Journaling when evaluating operation-based persistence for built-in mutable state structures. Choose Event Sourcing when domain events, event history, and the supported log-consistency programming model are application requirements.