Choose an Arc consistency scenario
Choose a Cratis Arc consistency scenario by what must remain true when commands run at the same time. The examples below show which reads and writes belong together, the guard that checks for conflicting changes, and the limits of that protection.
If you have not chosen a mechanism, start with the decision matrix. How it works explains the one-line guard notation used in the examples.
Fully idiomatic Arc
Section titled “Fully idiomatic Arc”For a new command, start with the rule closest to yours. Most examples let Arc protect read-model parameters under read protection On; the stream and numbering pages explain when a direct read is needed.
| Rule | Mechanism | Page |
|---|---|---|
| A book cannot be borrowed when no copy is left | A read model parameter and a validator | One entity |
| One library card per member. A username is unique | [Unique] on an event or a property |
Unique and once |
| A member may hold three loans, and the last copy of a book | Two read models, one batch | Two entities |
| A course has capacity and a student has a limit | Two read models, two events, atomic | Two entities |
| At most 5000 may be withdrawn per account per month | Per-stream read model, or a stream read directly in Handle() with a reasoned ARCCHR0040 suppression |
One stream |
| A report is approved once per owner per month | A stream decision | One stream |
| Steps of a process happen in order and a finished process accepts nothing more | A stream with declared concurrency, and a closed stream | Process stream |
| Invoice numbers have no gaps and no duplicates | A numbering source read directly in Handle() with a reasoned ARCCHR0040 suppression |
Gapless numbers |
| Many rules over one lifecycle | An aggregate root | Aggregate lifecycle rules |
| Do not overwrite a title change the user did not see | An explicit scope with the revision the editor loaded | Editing conflict |
| A hint, a repairable violation, an external price, or a long-lived source | Leave advisory reads unguarded, or reshape the data that needs protection | Advisory reads and shorter histories |
Choose a stream or source model
Section titled “Choose a stream or source model”| Rule lives in… | Use |
|---|---|
| Folded state of one stream on the command’s own route | Per-stream model |
| State built from the entity’s whole history, such as a balance | Whole-source model, which folds events across the source’s streams. Combining it with a per-stream model gives a whole-source guard |
| “Has fact X happened in this short stream?”, without a model | Stream decision |
| Lifecycle rules across the whole entity | Aggregate, without reads of the same source |
| Another month or another source | IDecisionReads stream overload directly in Handle(), with a reasoned ARCCHR0040 suppression linked to the tracking feature |
| Uniqueness across sources | Constraint |
Less idiomatic and Chronicle direct
Section titled “Less idiomatic and Chronicle direct”If existing code injects Chronicle services or runs outside Arc commands, check these pages before relying on automatic protection. They show which paths can participate in a guarded commit and which are refused under On.
| You write | Page |
|---|---|
An injected IEventLog, IReadModels in Handle(), several event sources, controllers |
Less idiomatic Arc |
IEventStore, IEventLog and IDecisionReads in endpoints, controllers and services |
Chronicle used directly |
Operating it
Section titled “Operating it”| You want | Page |
|---|---|
Move an existing application from Off to On |
Adopting read protection |
| Understand and fix a refusal | Refusals |
| Test that a rule holds under concurrency | Test the race |
Conventions
Section titled “Conventions”- The command’s subject id is a type derived from
EventSourceId, for examplepublic record Isbn(string Value) : EventSourceId(Value);. Arc uses it as the event source id, so no[Key]is needed. - References to other entities are
ConceptAs<T>, unless the command appends to that entity too. - A state rule goes in a
CommandValidator<T>with the read model as a constructor parameter.Handle()returns the events. - Examples on one page share one namespace, so the types declared in an earlier example are visible to later ones.