Read consistency
The entity snapshot and a named query are different reads.
The snapshot is the state committed with the intent. A named query reads a projection table. The projection worker updates that table after the commit.
A consistency token asks one follow-up query for that entity to include the cursor from the commit. The behavior below is what the query service implements. Current support is listed in What runs today?.
Two reads
| Read | What it returns | When it moves |
|---|---|---|
| Entity snapshot | State committed with the intent | In the runtime commit |
| Named query, no token | Projection rows, possibly from Redis | After the worker applies the event, and after any cache TTL |
| Named query, token, flag on | That entity’s projection row once its watermark has reached the token cursor | Same worker apply. A miss is 409 and is not cached |
| Named query, token, flag off | The ordinary query, including cache | The header does not change the read |
consistency: read_your_writes on the query only matters when the flag is on. Without it, a token on a list or a join is rejected.
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 SaaS response includes cursor and consistencyToken. An async accept has no cursor yet, so it has no token. A rejected intent has no token. Side-effect, fraud, and moderation intents are separate cursors and are not inside this token.
Send the token as X-Causet-Consistency on:
GET /v1/platforms/{platform}/applications/{application}/forks/{fork}/q/{queryName}POST .../forks/{fork}/reference/queries/{queryName}/run
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: 1read_your_writes and entity_local both mean one entity and no join. The inputs must contain the token’s stream id and entity id as values. The stream id on the token is the bare state name (counter), not counter_stream.
When the flag is on
The worker writes projection_entity_watermarks 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. The gate reads that row. It does not wait inside the query. A miss returns immediately.
| Status | error | When |
|---|---|---|
| 200 | Watermark is READY, the projection version matches, and ledger_cursor is at least the token cursor | |
| 400 | VALIDATION_ERROR | Bare min cursor, malformed token, join or non-entity-local query, or inputs that are not the token’s stream and entity |
| 401 | UNAUTHORIZED | Signature failed, or the token is for another platform, application, or fork |
| 409 | PROJECTION_NOT_VISIBLE | No ready watermark, version mismatch, or the watermark cursor is still behind |
The 409 body includes cursor and Projection is not visible through cursor N. Retry the same request. When you stop retrying, show that error. Do not substitute the untokened query. That call can still be cached.
There is no server timeout that turns a miss into 200. A statement timeout elsewhere is still a 500, and that is a different failure.
Scope
- The token applies to one entity query. A list, a join, or a different entity returns 400.
- A 200 means the watermark cursor is at least the token cursor.
- Saga prepare, commit apply, genesis import, fork clone, and surgical replay advance cursors outside the allocation row the recovery scan uses.
- If the projection event for an allocated cursor never arrives, the query stays at 409.
- With min-cursor reads disabled, the header is ignored and the ordinary query path runs, including cache.
What the counter example showed
examples/read-consistency in the Causet repo was run against a dev stack where the min-cursor flag was on.
| Check | What happened |
|---|---|
| Multi-entity | The token’s counter returned 200. The same token on another id returned 400. list_counters returned 400. |
| One-shot read | The row was already visible and matched the commit. That run did not observe a 409. |
| Later cursor | Cursor 2 became visible at value 1, then cursor 3 at value 2. |
| Newer token | After two adds, the later token returned the later value. |
Those checks did not crash the worker, and they did not exercise the recovery scan. A cursor that never gets applied stays 409.
Next steps
- Consistency and concurrency — commit versus projection visibility
- Replay and recovery — which operations re-run effects
- Caching — token reads skip Redis only when the flag is on