Skip to content

Chronicle decision-read costs and limits

A decision read lets Cratis Chronicle reject a write when the facts behind an eligible read model have changed. It folds events on demand and carries a guard to the append; it does not lock the facts while you decide. Compare that read cost with an append-time constraint or eventual repair before choosing how a rule should hold.

For projection-backed models, the .NET decision-read client reconstructs the model instead of using its stored instance. For each attempt it:

  1. Probes two tails in parallel: the unfiltered log boundary, including its mutation epoch, and a tail narrowed to the model’s event types, source and optional stream.
  2. Requests a fresh fold in an isolated session, then starts session dehydration without waiting for it before returning.
  3. Retries if the fold stopped short of the narrowed tail or ran past the log boundary, up to three attempts in total.

On the final attempt, a fold that remains behind the narrowed tail is refused with FoldIncomplete. A fold that ran ahead keeps the earlier boundary so the append guard can resolve the race.

On first use, the client also lists the kernel’s read-model and projection definitions to check agreement with the client’s definition. At commit, the kernel validates the guards on the serialized append path; that check needs no separate client round trip. An append without your own guard still gets the default optimistic check: the client captures a tail at append time and the kernel validates it when writing. This protects the window between that tail read and the write, not a decision made earlier. The first append into a scope is unchecked unless configured otherwise.

Mechanism Round trips Work per read Grows with
Constraint No application read required Checks the invariant inside the append Constraint and index work
Explicit scope One tail call to capture the position Validates the filter at commit Filter and storage query cost
Materialized plain read One read request Reads the stored instance, which may lag Stored instance size
Passive plain read One read request Folds the key’s matching history Matching events replayed
Decision read Two sequential round-trip stages per attempt, up to three attempts, plus definition loading on first use Probes tails and folds matching history; session dehydration is asynchronous Matching events, reads and retries

The two stages for a decision read are the parallel tail probes, then the fold request. Reading three models sequentially incurs three reads. Measure the full command path, including retries, rather than treating a decision read as a cached query.

Measure the full read-and-commit path with your model and event history. Compare it with the same append without a read, and record the number of models read, matching events replayed and retries observed. The call sequence above explains where time is spent; it does not predict latency for your deployment.

An append condition checks whether matching events arrived after a captured position. A .NET decision read also captures a mutation epoch, the event sequence’s counter for revisions and redactions. The kernel refuses its guard if that counter changed or the read captured a mutation in progress. This check is sequence-wide, so a revision outside the read’s filter can also cause a conflict. An explicit scope without an epoch has only the append-position check; see Concurrency for those scopes.

A decision read and its guard apply to the event log, and one unit of work cannot span event sequences. Values held elsewhere, such as an external service or another store, do not become protected just because you read them during the command. Record the relevant fact as an event before relying on a log guard.

A plain read, or a read under an Advisory allowance, contributes no guard. A [Unprotected] read in Arc is the same. A guard detects a matching append regardless of which writer made it, but protects only the decision that carries it. Every writer deciding on the rule needs protection; use a constraint when the kernel must enforce the invariant for every append.

A conflict report identifies the read model and key whose guard failed. When the kernel reports a matching event, it also gives that event’s type and sequence number; the event can belong to another read merged into the same guard. A mutation-epoch conflict need not identify a matching append.

In a host that uses read protection, the frame belongs to one unit of work and follows one asynchronous flow. Enrollment on another unit inside it is refused with ReadProtectionUnitMismatch.

“Silent” means the rule can fail with no error and no failed result.

Situation What happens Silent or loud What to do
You ignore the AppendResult A constraint or concurrency rejection is a result, not an exception. The write is lost Silent Always check IsSuccess, then the specific violations
You commit the request’s unit of work after the response starts The ASP.NET Core middleware cannot change an already-started response to report the conflict Silent to the caller Call IUnitOfWorkCompletionFeature.CommitAsync() before you respond
You take a decision read through the unit of work, then call plain eventLog.Append The append is immediate and takes no part in the unit of work, so the guard never applies Silent Stage with eventLog.Transactional.Append, or use GetDetached with AppendMany(guardedBy:)
A scope has no sequence number and no ExpectingNoMatchingEvent() The kernel skips it Silent. ConcurrencyCheckPerformed is false Build scopes with a position, and assert ConcurrencyCheckPerformed in tests
You capture the tail after you read the facts Events appended in between are not guarded Silent Capture the tail first, or use a decision read
The first append into a scope Not checked by default, so two concurrent creators both pass Silent Use a constraint, ExpectingNoMatchingEvent(), or a decision read: it guards an absent model too. See the first append
You use a plain read for the decision It guards nothing Silent See the table above
The decision-read model has no Id property, or its shape is refused DecisionReadRefused, with a reason Loud Fix the model. Check with Admit<T>() in a test
The read model is keyed on a different event source than the one where the facts are written The model is empty or partial, and the guard watches the wrong source Silent Append every fact the rule needs on the source you read
New keys can join the set the rule counts over A key nobody read is in nobody’s guard Silent Model the rule on one key that carries the facts
A projection definition changes after admission, or required facts live in another sequence The event filter does not become a guard for the new definition or the other sequence Silent Coordinate definition changes with command producers, and keep the rule’s facts in the guarded sequence
A writer decides on the same rule without a guard A guard detects its event whoever wrote it, but the unguarded writer’s own decision is not protected and can break the rule Silent Guard every writer that decides on the rule, or use a constraint, which the kernel checks for every append
A conflict The append is rejected and nothing is written. Chronicle does not re-decide for you Loud Read again, reconsider the rule and submit the new decision
A constraint index needs recovery Constraint enforcement depends on index readiness and repair Operational Follow the constraint recovery guidance rather than resubmitting blindly
A constraint across namespaces or event sequences Constraints do not span them Silent Design the unique value per namespace
Non-.NET writers append GUID event source IDs in another casing or format The decision read’s key no longer matches Silent Use lowercase canonical form in every writer
A long or hot key Reads get slower and conflicts more likely. Results are not wrong Slow Shorten the key’s history
A repair reactor triggers an irreversible side effect A compensating event cannot undo it Silent Repair with events only, and make the repair safe to run twice
Your tests never interleave a competing append The race is never exercised Silent Append a competing event between the read and the guarded append, and assert the conflict. For Arc commands see the pitfalls

A storage retry is different from retrying a business decision. After a duplicate sequence number, the kernel renumbers the append and validates concurrency scopes again before retrying; it does not rerun constraint validation on that path. If the result is a decision conflict, load fresh facts and evaluate the rule again.

Use Choosing how a rule holds to select a mechanism, then adapt a scenario. Before using a model for a command decision, check the decision-read assumptions. Concurrency covers the explicit scope API.