ConceptsConsistency Guarantees

Consistency

There are two reads. The entity snapshot is updated in the commit the sync response waited for. A named query reads a projection table the worker fills in after that commit.

ACCEPTED means the ledger and the snapshot committed. Read the snapshot or the timeline for that commit. Read a named query for the projection.

Two reads

ReadWhat it returnsWhen it moves
Entity snapshotState committed with the intentIn the runtime commit
Named query, no tokenProjection rows, possibly from cacheAfter the worker applies the event
Named query with a tokenThat entity’s projection row once its watermark has reached the token cursorA miss is 409 and is not cached

Intents for one entity run one at a time. Rules read the entity snapshot. They do not read the projection.

Token from a sync write

POST /v1/platforms/{platform}/applications/{application}/intents/execute with "mode": "sync".

When the intent is COMMITTED and the cursor is greater than 0, the response includes cursor and consistencyToken. An async accept has no cursor yet, so it has no token. A rejected intent has no token.

Send the token as X-Causet-Consistency on the query. A bare X-Causet-Min-Cursor header is 400. The cursor has to come from the signed token.

The query

queries:
  get_counter:
    from: counter_view
    consistency: read_your_writes
    input:
      counter_id: { type: string, required: true }
      stream_id: { type: string, required: true }
    where:
      counter_id: { eq: input.counter_id }
      stream_id: { eq: input.stream_id }
    limit: 1

read_your_writes and entity_local both mean one entity and no join. The inputs contain the token’s stream id and entity id. The stream id on the token is the bare state name (counter), not counter_stream.

What the query service returns

The worker writes the watermark in the same database transaction as the projection change. The stored cursor is the greatest cursor applied for that stream, entity, projection, and version. An older apply cannot move it backward. A miss returns immediately. The query does not wait.

StatuserrorWhen
200Watermark is READY, the projection version matches, and ledger_cursor is at least the token cursor
400VALIDATION_ERRORBare min cursor, malformed token, join or other entity, or inputs that are not the token’s stream and entity
401UNAUTHORIZEDSignature failed, or the token is for another platform, application, or fork
409PROJECTION_NOT_VISIBLENo ready watermark, version mismatch, or the watermark cursor is still behind

Read the query again on 409. The intent already committed. The header, the flag, and the crash cases are in Read consistency.

What to use

You needRead
The entity that just committedcauset inspect state or the entity API
The order of commitscauset inspect timeline
A list, a dashboard, or a lookupA named query
That one entity’s projection row to include this commitThe consistency token on that query