Skip to content

(2.14) Linearizable read leases#7748

Open
MauriceVanVeen wants to merge 1 commit intomainfrom
maurice/linearizable-lease
Open

(2.14) Linearizable read leases#7748
MauriceVanVeen wants to merge 1 commit intomainfrom
maurice/linearizable-lease

Conversation

@MauriceVanVeen
Copy link
Member

This PR implements leader leases to ensure linearizable reads for parts of the JS API, like MsgGet, but does NOT include APIs like DirectGet currently. Ensuring an old leader (that can't refresh the lease) doesn't answer read requests after its lease expires.

This is safe based on the "LeaseGuard: Raft Leases Done Right" paper describing using the Raft log to renew the leader lease. Although we don't use the 'inherited lease reads' and 'deferred writes' optimizations, since any changes depend on the former ones being applied (especially for a stream).

Although the paper describes needing to take clock uncertainty/skew into account, in "5.3. Leases without bounded-uncertainty clocks" it describes using local timers instead. Since we use Go's monotonic clock with a lease timeout that equals the minimum election timeout, this has minimal to no impact on our current Raft implementation in terms of when elections take place.

This PR adds a "noop-entry" to be able to write and renew the leader lease. Since this entry is otherwise empty, this poses no backward-compatibility issues either. An old server version will know how to handle it without issue, that is: 'do nothing except store it in the log', which is intended.

Relates to nats-io/nats-architecture-and-design#390

Signed-off-by: Maurice van Veen github@mauricevanveen.com

@MauriceVanVeen MauriceVanVeen force-pushed the maurice/linearizable-lease branch 3 times, most recently from 5c383ae to f3a27bb Compare January 21, 2026 10:32
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
@MauriceVanVeen MauriceVanVeen force-pushed the maurice/linearizable-lease branch from f3a27bb to e6ef786 Compare January 21, 2026 15:13
@MauriceVanVeen MauriceVanVeen marked this pull request as ready for review January 21, 2026 15:57
@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner January 21, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant