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.
Examples
Section titled “Examples”Capture the tail for a checkpoint
Section titled “Capture the tail for a checkpoint”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(); }}import io.cratis.chronicle.IEventStore
suspend fun getAccountTailSequenceNumber(store: IEventStore, accountId: String): Long { val tail = store.eventLog.getTailSequenceNumber(accountId) println("Tail sequence number for $accountId: ${tail.value}") return tail.value}import io.cratis.chronicle.EventStore;
import io.cratis.chronicle.java.EventLogJavaBridge;
class EventsGettingStateTail { long getAccountTailSequenceNumber(EventStore store, String accountId) { long tail = EventLogJavaBridge.getTailSequenceNumber(store.getEventLog(), accountId); System.out.println("Tail sequence number for " + accountId + ": " + tail); return tail; }}defmodule MyApp.GettingStateCheckpointStore do def capture_tail do # Persists the current tail so processing can resume later. Cratis.Chronicle.get_tail_sequence_number() endendimport { EventSequenceNumber, IEventStore } from '@cratis/chronicle';
class GettingStateCheckpointStore { constructor(private readonly store: IEventStore) {}
async captureTail(): Promise<EventSequenceNumber> { // Persists the current tail so processing can resume later. return await this.store.eventLog.getTailSequenceNumber(); }}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 ); }}import io.cratis.chronicle.IEventStoreimport io.cratis.chronicle.eventSequences.EventSequenceNumber
/** * Scopes the tail sequence number to a specific event source, rather than the whole event log. */suspend fun captureFor(store: IEventStore, inventoryId: String): EventSequenceNumber = store.eventLog.getTailSequenceNumber(eventSourceId = inventoryId)import io.cratis.chronicle.EventStore;
import io.cratis.chronicle.java.EventLogJavaBridge;
class EventsGettingStateTailForEventSource { // Scopes the tail sequence number to a specific event source, rather than the whole event log. long captureFor(EventStore store, String inventoryId) { return EventLogJavaBridge.getTailSequenceNumber(store.getEventLog(), inventoryId); }}defmodule MyApp.Events.GettingStateInventoryAdjusted do use Cratis.Chronicle.Events.EventType, id: "getting-state-inventory-adjusted"
defstruct sku: "", delta: 0end
defmodule MyApp.Events.GettingStateInventoryReserved do use Cratis.Chronicle.Events.EventType, id: "getting-state-inventory-reserved"
defstruct sku: "", quantity: 0end
defmodule MyApp.GettingStateInventoryCheckpoint do alias Cratis.Chronicle.EventSequences.EventLog alias MyApp.Events.{GettingStateInventoryAdjusted, GettingStateInventoryReserved}
def capture_for(inventory_id) do # Scopes the tail to this event source and these event types. EventLog.get_tail_sequence_number(inventory_id, event_types: [GettingStateInventoryAdjusted, GettingStateInventoryReserved] ) endendimport { eventType, EventSequenceNumber, IEventLog } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class GettingStateInventoryAdjusted { @field(String) readonly sku: string; @field(Number) readonly delta: number;
constructor(sku: string, delta: number) { this.sku = sku; this.delta = delta; }}
@eventType()class GettingStateInventoryReserved { @field(String) readonly sku: string; @field(Number) readonly quantity: number;
constructor(sku: string, quantity: number) { this.sku = sku; this.quantity = quantity; }}
class GettingStateInventoryCheckpoint { constructor(private readonly eventLog: IEventLog) {}
// Scopes the tail to a specific stream of inventory events. captureFor(inventoryId: string): Promise<EventSequenceNumber> { return this.eventLog.getTailSequenceNumber( inventoryId, undefined, undefined, undefined, [GettingStateInventoryAdjusted, GettingStateInventoryReserved] ); }}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.
Check whether an observer is caught up
Section titled “Check whether an observer is caught up”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); }}import io.cratis.chronicle.eventSequences.EventSequenceNumberimport io.cratis.chronicle.eventSequences.IEventSequenceimport kotlin.reflect.KClass
/** * Computes the tail sequence number relevant to a specific observer, based on the event types * it handles. */suspend fun getRelevantTail(eventSequence: IEventSequence, observerType: KClass<*>): EventSequenceNumber = eventSequence.getTailSequenceNumberForObserver(observerType)import io.cratis.chronicle.eventSequences.IEventLog;import io.cratis.chronicle.java.EventLogJavaBridge;
class TailForObserverExample { /** * Computes the tail sequence number relevant to a specific observer, based on the event types * it handles. */ static long getRelevantTail(IEventLog eventLog, Class<?> observerType) { return EventLogJavaBridge.getTailSequenceNumberForObserver(eventLog, observerType); }}defmodule MyApp.Events.GettingStateObserverProgressSomethingHappened do use Cratis.Chronicle.Events.EventType, id: "getting-state-observer-progress-something-happened"
defstruct []end
defmodule MyApp.Reactors.GettingStateObserverProgressReactor do use Cratis.Chronicle.Reactors.Reactor
alias MyApp.Events.GettingStateObserverProgressSomethingHappened
@handles GettingStateObserverProgressSomethingHappened
@impl true def handle(%GettingStateObserverProgressSomethingHappened{}, _context), do: :okend
defmodule MyApp.GettingStateObserverProgress do alias Cratis.Chronicle.EventSequences.EventLog alias MyApp.Reactors.GettingStateObserverProgressReactor
def get_relevant_tail do # Uses the reactor's @handles event types to compute the relevant tail. EventLog.get_tail_sequence_number_for_observer(GettingStateObserverProgressReactor) endendimport { Constructor } from '@cratis/fundamentals';import { EventSequenceNumber, IEventSequence } from '@cratis/chronicle';
class GettingStateObserverProgress { constructor(private readonly eventSequence: IEventSequence) {}
// Uses the observer's event type filters to compute the relevant tail. getRelevantTail(observerType: Constructor): Promise<EventSequenceNumber> { return this.eventSequence.getTailSequenceNumberForObserver(observerType); }}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.