Runtime
The causet-runtime-service is the write-path engine. It receives intents, runs your rules, appends events to the ledger, and publishes to Kafka. Everything in the write path flows through it.
What the runtime does
For each intent submitted:
- Validate input — required fields, type checking against the action’s
input:schema. - Resolve IR — load the active compiled IR (
causet.runtime.json) for this fork fromcauset-saas-cloud. The IR is cached in memory and refreshed on deploy. - Acquire cursor lock — acquire a per-entity, per-stream cursor lock for the target entity. This serializes processing for a given entity — concurrent intents for the same entity are queued, not parallelized.
- Load entity snapshot — read the current entity state from
entity_snapshots. This is the input to rule evaluation. - Run preflight rules — evaluate conditions, run lookups, reject if any rule fires a
reject. - Run core rules — evaluate mutations, build the new entity state, queue emitted events.
- Run side_effects rules — build fan-out events, submitted intents, scheduled actions.
- Append to ledger — write all emitted events to
ledger_events. This is synchronous — the write path does not proceed until the ledger write succeeds. - Update entity snapshot — write the new entity state to
entity_snapshots. - Publish to Kafka — publish projection events to
causet.projection-events.v1. - Release cursor lock — release the per-entity lock.
Steps 8 and 9 commit the ledger and the entity snapshot. Step 10 publishes the event that projections consume. Consistency and concurrency.
Intent submitted (gRPC or HTTP)
│
▼
Input validation
│
▼
IR resolution (active version for fork)
│
▼
Cursor acquire (per-entity lock)
│
▼
Entity snapshot load
│
▼
Preflight rules ──► reject? ──► 4xx to caller
│
▼
Core rules (mutations + emit queue)
│
▼
Side_effects rules (fan-out queue)
│
▼
Ledger append (Postgres, synchronous)
│
▼
Snapshot update (Postgres)
│
▼
Kafka publish (causet.projection-events.v1)
│
▼
Cursor release
│
▼
Response to callerPer-entity cursor lock
The cursor lock is the runtime’s ordering guarantee. For a given entity (identified by entity type + entity ID), only one intent processes at a time. Concurrent intents for the same entity are serialized by the cursor.
This means:
- Entity state is always consistent within a single entity’s stream.
- You cannot have race conditions between two intents that modify the same entity.
- High-throughput concurrent writes to the same entity will queue — design your entity granularity accordingly.
Cross-entity concurrency is unconstrained. Two intents for different entities run in parallel.
Determinism guarantee
The runtime guarantees:
Same entity state + same intent input = same events produced.
This is not aspirational — it is enforced by design. Rules cannot:
- Read wall-clock time (
now()is not available in expressions) - Generate random values
- Call external services
- Read from any source other than the loaded entity snapshot and the intent input
This determinism is what makes Replay safe. If you need to replay entity history, you get the same events every time.
IR version resolution
Each fork has an active IR version. When you deploy a new release, the causet-saas-cloud service updates the active IR version for that fork. The runtime polls for version changes and hot-reloads the IR without downtime.
The IR artifacts (causet.runtime.json and causet.projections.json) are stored on S3. The runtime fetches them at startup and on version change.
Entity snapshots
The entity_snapshots table in the causet PostgreSQL database stores the current materialized state of every known entity. It is an optimization — the runtime does not re-apply the full event history on every intent. Instead, it loads the snapshot, applies the current intent’s rules, and writes the updated snapshot.
Snapshots can be rebuilt from the ledger if needed. See Replay.
gRPC entity browser
The runtime exposes a gRPC server on port 9090 for debugging. It allows you to inspect entity state directly without going through the query service.
# Inspect entity state
grpcurl -plaintext \
-d '{"entity_type":"show","entity_id":"show-pj-brooklyn-2026"}' \
localhost:9090 \
causet.EntityBrowser/GetEntityThis returns the raw entity snapshot — the same state the runtime uses when evaluating rules. Useful for debugging why a preflight rejected an intent.
What the runtime guarantees
Guaranteed:
- Events are appended to the ledger before the intent response is returned.
- Per-entity processing is serialized — no entity-level race conditions.
- Rules are deterministic — same inputs produce same events.
- Failed intents (rejection, validation error, rule error) do not produce ledger entries.
Not guaranteed:
- At-most-once delivery to Kafka — Kafka publish is at-least-once after ledger append. The projection worker must be idempotent.
- Exactly-once projection processing — the projection worker may replay events. See Idempotency.
- Instant projection consistency — projection tables lag behind the ledger.
Configuration
The runtime is configured via environment variables:
| Variable | Description |
|---|---|
CAUSET_DB_URL | R2DBC connection URL for the causet PostgreSQL database |
KAFKA_BOOTSTRAP_SERVERS | Kafka broker addresses |
KAFKA_TOPIC_PROJECTION_EVENTS | Topic name (default: causet.projection-events.v1) |
S3_BUCKET_IR_ARTIFACTS | S3 bucket for IR artifacts |
CAUSET_SAAS_CLOUD_URL | URL of the causet-saas-cloud service for IR version resolution |
GRPC_PORT | gRPC port for entity browser (default: 9090) |
HTTP_PORT | HTTP port for intent submission (default: 8085) |
The runtime uses R2DBC (reactive) for all database access — no JDBC. This is an architectural choice for non-blocking throughput under concurrent intent load.
Production notes
Entity granularity affects throughput. The cursor lock serializes writes per entity. If your application has a hot entity (e.g. a global counter or a shared inventory item), all writes to that entity queue behind each other. Design entity IDs to distribute write load — e.g. per-user rather than per-application for user-scoped state.
IR hot-reload is non-disruptive. The runtime can reload the IR for a fork without dropping in-flight intents. In-flight intents complete under the old IR version; new intents pick up the new version.
The ledger is your recovery path. If the snapshot database is lost or corrupted, snapshots can be rebuilt from the ledger. The ledger itself (being append-only) is durable as long as PostgreSQL is healthy.