Skip to main content

Sequence Model and Allocation

A Kahuna sequence is a named counter. Values are monotonically increasing per sequence name, not globally across every sequence in the cluster.

State

FieldDescription
NameThe sequence name, such as orders or tenant-a/invoices.
CurrentValueThe highest committed value for the sequence.
InitialValueThe value used as the starting point.
IncrementThe step between allocated values.
MaxValueOptional upper bound.
RevisionSequence metadata revision.
DurabilityCurrently Persistent.
CreatedAtHybrid logical timestamp when the sequence was created.
UpdatedAtHybrid logical timestamp when the sequence was last changed.

Defaults:

  • InitialValue: 0
  • Increment: 1
  • MaxValue: null
  • Durability: Persistent

With the defaults, the first allocated value is 1.

Next Value

next allocates one value. If orders has CurrentValue = 41 and Increment = 1, the next allocation returns 42 and commits 42 as the current value.

CurrentValue = 41
Increment = 1
Next = 42

Range Reservation

reserve allocates a contiguous range. If orders has CurrentValue = 100, Increment = 1, and the caller reserves 50, Kahuna returns:

Start = 101
End = 150
Count = 50

Range reservations for the same sequence do not overlap. After the reservation commits, the sequence current value is 150.

Max Value

If MaxValue is set and an allocation would exceed it, Kahuna returns MaxValueExceeded and does not partially allocate the request.

For example, if CurrentValue = 98, MaxValue = 100, and a caller reserves 5, the request fails because it would need 99..103.