TTL and soft delete
This page is part of the documentation for Orleans.Lattice 10.5.0 (release line 10.5), built 2026-12-05. It is also published as markdown, with every table and list, at ttl-and-soft-delete.md, and llms.txt lists every page.Entries can expire on their own, and a deleted tree can be recovered inside its retention window.
Transcript
TTL and soft delete
Atomic writes showed how related changes become visible as a whole. Here, we ask how data goes away: on its own, or by mistake.
This is TTL and soft delete: entries can expire on their own, and a deleted tree can be recovered inside its retention window.
Entries that expire
A session should not live for ever. Write it with a time to live, here thirty minutes.
The silo turns that duration into an absolute expiry time, so a client with a skewed clock does not move it.
Once that time passes, the entry is gone from every read. A get returns nothing, an existence check says false, and scans and counts skip it.
Refresh and reaping
Expiry follows the write that wins. A later write replaces the entry as usual, and a winning plain write without a time to live clears the expiry.
On a CRDT entry, expiries merge by taking the later one, so a refresh only ever extends it.
An expired entry is not deleted straight away. Compaction reaps it after the tombstone grace period, so a lagging peer cannot bring it back.
Soft delete
Deleting a whole tree is a soft delete. The tree becomes inaccessible at once: its reads and writes throw.
But its data is not gone. It is kept for a retention window, seventy-two hours by default, before it is purged.
Recovery
Inside that window, recovering the tree makes it accessible again, with all the data it held before the delete.
Once the purge has started, it is too late; and once the purge is complete, the data is gone.
Where next
Next on Build: Going durable. The links are on this episode's page in the documentation.
The code on screen
The episode writes a session with a thirty-minute time to live, then deletes a tree and recovers it inside its retention window. The snippets are compiled with the rest of the documentation.
var session = new User("alice", 1);
await lattice.SetAsync("session:42", session, TimeSpan.FromMinutes(30));
var tree = grainFactory.GetGrain<ILattice>("my-tree");
await tree.DeleteTreeAsync();
var tree = grainFactory.GetGrain<ILattice>("my-tree");
await tree.RecoverTreeAsync();
// Tree is accessible again - all data from before the delete is restored.
byte[]? value = await tree.GetAsync("customer-123");
Where next
- Next on Build: Going durable
- The pages it introduces: TTL