Revisions
A revision is a key's version number. Each write increases it. This means that you can tell whether a key changed since you read it, and you can see its earlier values. A revision is similar to a version column that a SQL application checks for optimistic concurrency. However, Kahuna maintains the revision for all keys and can also return older values.
- Update safely under concurrency. Write only if the key is at the revision that you read (compare-and-set). This means that two clients can't silently overwrite each other's changes.
- Detect changes cheaply. Compare a stored revision number with the current one. You don't need to compare the values.
- Look back in time. Read earlier values of a key for audits and postmortems. Earlier values also help you debug how a system reached a bad state, or roll back a bad configuration change.
SET and DELETE advance the revision, including writes staged in a transaction. EXTEND changes the expiry but doesn't advance the revision. Reads don't change it. The counter is for one key. It doesn't order writes across keys, and it doesn't replace the commit timestamp (HLC). It is also separate from Raft leader terms and from fencing tokens.
How Revisions Advance
Keys are always created at revision r0.
set `example` 'value1'
r0 set 17ms
Each change to the key increases the revision, first to r1 and then to r2.
set `example` 'value2'
r1 set 12ms
set `example` 'value3'
r2 set 9ms
Deletes also allocate a revision. The delete writes a tombstone (a marker that records the delete). This means that historical reads before the delete can find the previous value. Point-in-time recovery can also find it.
delete `example`
r3 deleted 8ms
set `example` 'value4'
r4 set 10ms
When you query a key, you can see its current revision. Reads don't change the revision.
get `example`
r4 value4 10ms
get `example`
r4 value4 9ms
Skipping Historical Revisions
Some workloads need only the latest value. For example, a cache can overwrite the same key often and not read older versions. In that case, use SET ... NOREV to skip the historical revision record for that write.
set `cache/user/1001` '{"name":"Ada"}' ex 60000 norev
r0 set 8ms
set `cache/user/1001` '{"name":"Ada Lovelace"}' ex 60000 norev
r1 set 7ms
NOREV doesn't freeze the revision counter. The current revision advances as usual, and latest reads return the new value. Compare-revision operations also protect conditional updates as usual. However, the revision from a NOREV write isn't archived for GET ... AT <revision> or historical snapshot reads.
Use normal SET when you need history, for example for audits or point-in-time reads. Use SET ... NOREV when lower memory and disk write amplification matters more than old values.
Querying Previous Revisions
Kahuna can query an archived revision while that revision is retained.
get `example` at 0
r0 value1 11ms
get `example` at 1
r1 value2 13ms
AT Revision vs AS OF Timestamp
Kahuna has two kinds of historical read.
AT <revision>reads one exact archived revision for a key.AS OF <timestamp>reads the value that was visible at a specific HLC snapshot time.
Use AT when you know the exact revision that you want. Use AS OF to select revisions committed at or before a time T. The result depends on retained history and safe-time fences. Current TTL filtering also applies.
In Kahuna Script, AS OF works with the read commands in this example.
get `example` at 1
get `example` as of 1718392012345
exists `example` as of 1718392012345
get by bucket `services` as of 1718392012345
scan by prefix `services/auth` as of 1718392012345
The .NET and TypeScript clients take the snapshot time as snapshotMs on point reads and scans. For more information, see the Key/Value API Reference. If you don't pass a timestamp, prefix and range scans read the current committed view page by page.
AS OF is especially useful for debugging incidents and reconstructing historical state. You can also use it for consistent read-only scripts on an older snapshot.
Snapshot timestamps must be non-zero. AT and AS OF cannot be combined on the same statement.
For long-lived historical views, use snapshot holds to keep the required persistent revisions from being pruned while the view remains active.
Retention
Old revisions aren't stored forever. Retention depends on the durability of the key.
- Ephemeral keys are stored only in the memory of the partition leader. Only a limited number of recent revisions is retained. Under memory pressure, an ephemeral key that wasn't accessed recently can be evicted.
- Persistent keys are stored on disk. History is retained according to the configured count and age limits, and according to snapshot holds. Revisions aren't kept unconditionally.
Learn more in Durability Levels.
Age retention preserves the newest revision committed before the cutoff, and all newer revisions. Other retention limits and hold protection also apply. For example, with a one-hour window, a value written two hours ago and replaced one minute ago is needed for a read five minutes ago. RocksDB and SQLite keep that boundary value. They don't remove it based only on its creation time. Cleanup deletes older rows first. This means that a bounded pass doesn't leave holes in retained history.
Historical Read Limits
A historical read can wait for a live writer, or it can return a retryable MustRetry. It doesn't answer from incomplete history. Also, AS OF doesn't freeze expiration. For the exact rules, see fixed-timestamp reads. For how EXTEND and other mutations at the same revision are ordered, see committed intents and newer heads.
A persistent AS OF read below the durable pruned-history floor of the backend returns SnapshotTooOld (116). This applies to point reads and existence checks, and to scans. The floor applies across the backend, even if a particular key has older rows. A failed scan page is returned as an error, and an incomplete scan isn't presented as a success. A retry with the same old timestamp doesn't restore history. Use a newer timestamp, or report that the requested historical view is unavailable. Acquire a snapshot hold before you rely on a long-lived view.