Actor Model
An actor is a single-threaded owner of state. It owns part of a node's in-memory data and processes one message at a time. This means that the code in an actor doesn't need locks. This page shows where a request waits in a node. It also explains why work on one key can't race with other work on the same key.
Kahuna builds its actors on the Nixie actor library. Actors also define the ownership boundaries for locks and key/value entries, and for proposals and background persistence.
What Actors Provide
Actors give Kahuna these properties.
- Single-message-at-a-time execution for each worker.
- Predictable ownership of in-memory maps and B-trees.
- Backpressure through actor mailboxes and bounded request admission.
- Separate pools for ephemeral and persistent objects.
- A clean split of request routing from proposal handling and state mutation.
Manager Layer
KahunaManager creates the main subsystems.
LockManagerKeyValuesManagerSequencerManagerTransactionCoordinatorBackgroundWriterActor- the selected
IPersistenceBackend
The managers find partition leaders and forward remote requests. They also choose the right actor ring or router.
Lock Actors
LockManager starts separate fixed rings for ephemeral and persistent lock actors.
ephemeral-lock-*persistent-lock-*
Like key/value routing, a LockActorRing resolves the owning actor by consistent hash at the call site. This means that a lock request reaches its actor directly. It doesn't go through the mailbox of a router actor.
LockActor stores lock state in memory, in a dictionary keyed by resource name. It processes lock operations, for example acquire and release. Each actor processes one message at a time. This means that lock ownership and fencing-token updates are serialized for the resources routed to that actor.
Persistent locks queue dirty state to BackgroundWriterActor after committed changes.
Key/Value Actors
KeyValuesManager starts separate fixed rings for ephemeral and persistent key/value actors.
ephemeral-keyvalue-*persistent-keyvalue-*
KeyValueActor stores an ordered in-memory B-tree of KeyValueEntry values. It also tracks this state.
- Write intents for individual keys
- Prefix write intents for bucket reads
- Range locks and range-oriented routing state
- Active proposals
- Recent revisions
- MVCC entries
Consistent-hash routing sends operations for the same key or bucket to the same actor in a worker set. Key/value routing resolves the target actor directly at the call site. It doesn't use a separate router actor. This means that the hot path doesn't need an extra mailbox hop, and the key-to-actor mapping doesn't change.
Each key/value actor can also reject ordinary user messages when its bounded inbox is full. Kahuna maps that rejection to retryable MustRetry backpressure. Control messages are exempt, for example proposal completions and flush acknowledgements. This means that a hot-key flood can't strand work that is already in flight.
Replication Submission
Persistent lock mutations and persistent key/value mutations both use the shared partition write aggregator.
For a direct persistent key/value write or a persistent lock mutation, the owning KeyValueActor or LockActor validates the mutation and installs the replication intent. It then serializes the log record and submits a compact request to the aggregator. The aggregator performs the Raft ReplicateEntries call outside the actor mailbox. It then sends the completion back to the owning actor.
A local actor can accept a request that changes durable state, but this doesn't commit the request. The mutation must first be replicated and committed through Raft.
The diagram follows a persistent write through these actors, from the manager to the materialized backend.
Transaction Coordination
The transaction coordinator owns transaction-wide state. However, participant work goes through the key/value actors that own the affected keys and ranges.
For interactive transactions, the coordinator records the transaction state. Examples are confirmed effects and read observations, and optional durable decision metadata. Background actors handle the long-running maintenance paths.
TransactionReaperActorcloses and rolls back abandoned sessions when it can do so safely.PreparedIntentRecoveryActorsettles or presume-aborts durable prepared intents on partitions this node currently leads.
Background Writer
BackgroundWriterActor is a dedicated actor for materialized persistence. Lock and key/value actors enqueue dirty items, and the background writer flushes them in batches. This means that request actors don't wait for each backend write.
The background writer also tracks partitions that need checkpoints after dirty objects are flushed. For durable transaction decisions, checkpointing must persist completion receipts and coordinator decision snapshots before advancing the write-ahead log (WAL) retention floor for the relevant partition.