Observing Events and Checkpoints¶
Projecting and publishing are both driven by a single background component: the observer. It watches the event store, hands each new event to your projectors, and records how far it has progressed with a checkpoint so it can resume after a restart.
The Observer¶
EventSourcingKit registers an IEventStoreObserver and starts it for you through a hosted background service, so you do not call Start yourself. Once running, the observer:
- loads the last checkpoint to learn where it stopped,
- observes the store from the next event onward,
- dispatches each event to every registered
IProjector, and - stores a new checkpoint after each event is processed.
Because the observer always resumes from its checkpoint, projecting is resumable: restarting your application reprocesses nothing it has already handled.
Checkpoints¶
A checkpoint is the id of the last processed event, kept by the ICheckpointStore:
public interface ICheckpointStore
{
Task StoreCheckpoint(
Checkpoint checkpoint,
CancellationToken cancellationToken
);
Task<Checkpoint> GetLastCheckpoint(CancellationToken cancellationToken);
}
By default, EventSourcingKit uses an in-memory checkpoint store, so progress is lost when the process ends and projecting starts from the beginning on the next run. That is fine for development, but in production you want a durable store so the observer truly resumes. Register one with AddCheckpointStore:
A durable checkpoint store and a durable projection store belong together; Persisting Projections shows both backed by PostgreSQL.
Observer States and Retries¶
The observer exposes its current condition as an ObserverState – for example observing, stopped, or failing and about to retry – and raises StateChanged as it transitions. When processing an event throws, the observer retries with exponential backoff governed by the ObservationRetryPolicy: MaxRetryAttempts, InitialDelayInMs, BackOffFactor, and MaxDelayInMs. Once the attempts are exhausted, it stops rather than silently dropping events.
For More Information¶
- Projecting is the introductory walkthrough.
- Configuration documents the
ObservationRetryPolicy. - Persisting Projections shows a durable checkpoint store.