Skip to content

Cratis Chronicle sequence state for checkpoints and progress

The tail sequence number in Cratis Chronicle identifies the latest appended event matching a read’s filters. Use it to capture a boundary for a history read or to compare with an observer’s progress. It says what has been appended, not what a projection, reactor, or reducer has finished processing.

In .NET, IEventSequence.GetTailSequenceNumber returns that position. A read with no matching events returns EventSequenceNumber.Unavailable; do not save that sentinel as an event locator. A captured tail does not freeze the sequence or prevent duplicate processing when you resume.

For point-in-time read models, follow Getting snapshots and check the snapshot requirements rather than treating a tail value as a snapshot. To read current query results instead, use Getting a Collection of Instances.

using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
public class GettingStateCheckpointStore(IEventLog eventLog)
{
public async Task<EventSequenceNumber> CaptureTail()
{
// Persists the current tail so processing can resume later.
return await eventLog.GetTailSequenceNumber();
}
}

View C# snippet source on GitHub

This captures a history boundary; it does not persist a consumer checkpoint. Save your consumer’s successfully processed position separately, and account for the inclusive start when reading from a checkpoint. Kotlin, Java, and TypeScript expose getTailSequenceNumber; Elixir exposes get_tail_sequence_number/2.

Capture the tail for a specific event source and event types

Section titled “Capture the tail for a specific event source and event types”
using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
[EventType]
public record GettingStateInventoryAdjusted(string Sku, int Delta);
[EventType]
public record GettingStateInventoryReserved(string Sku, int Quantity);
public class GettingStateInventoryCheckpoint(IEventLog eventLog)
{
public async Task<EventSequenceNumber> CaptureFor(EventSourceId inventoryId)
{
// Scopes the tail to a specific stream of inventory events.
var eventTypes = new[]
{
typeof(GettingStateInventoryAdjusted).GetEventType(),
typeof(GettingStateInventoryReserved).GetEventType()
};
return await eventLog.GetTailSequenceNumber(
eventSourceId: inventoryId,
filterEventTypes: eventTypes
);
}
}

View C# snippet source on GitHub

The .NET example narrows the tail to one event source and selected event types. TypeScript also accepts event-source and event-type filters on getTailSequenceNumber. Kotlin and Java accept an optional event source identifier on that method, without an event-type filter.

using Cratis.Chronicle.Events;
using Cratis.Chronicle.EventSequences;
public class GettingStateObserverProgress(IEventSequence eventSequence)
{
public async Task<EventSequenceNumber> GetRelevantTail(Type observerType)
{
// Uses the observer's event type filters to compute the relevant tail.
return await eventSequence.GetTailSequenceNumberForObserver(observerType);
}
}

View C# snippet source on GitHub

This .NET call calculates the tail for the event types handled by the observer; it does not read the observer’s progress. Compare that boundary with the observer’s recorded position and check for failures or quarantined partitions before concluding that processing is complete. See Observers for progress and recovery.

TypeScript provides getTailSequenceNumberForObserver, and Elixir provides get_tail_sequence_number_for_observer/2. These helpers calculate a relevant event tail, not a completion guarantee.