Skip to content

Chronicle outbox and inbox event delivery

Cratis Chronicle uses an outbox and inbox to separate publishing an event from processing it in another service. The source publishes to its outbox, the kernel forwards subscribed events into the consumer’s inbox, and the consumer processes that stored copy.

The outbox is the source store’s event sequence for publishing events to other stores. In C#, its well-known identifier is EventSequenceId.Outbox. A subscription selects which event types to forward from that sequence.

You do not need to create the outbox separately. Append events to it as you would to another event sequence. Appending to the source’s ordinary event log alone does not publish an event to subscribers.

An inbox stores the forwarded events in the consuming store. Each source has its own sequence, named inbox-{sourceEventStore}. For example, subscribing to fulfillment-service sends its matching events to inbox-fulfillment-service in the target store.

C# declares the well-known EventSequenceId.Inbox identifier and uses EventSequenceId.InboxPrefix to construct a per-source identifier:

using Cratis.Chronicle.EventSequences;
public static class SubscriptionsOutboxInboxId
{
public static EventSequenceId Resolve()
{
var inboxId = new EventSequenceId($"{EventSequenceId.InboxPrefix}source-event-store");
// Resolves to: "inbox-source-event-store"
return inboxId;
}
}

View C# snippet source on GitHub

Use the per-source sequence when you need to inspect a particular source’s delivery. Let Chronicle write the forwarded events rather than appending them to the inbox yourself.

Forwarding preserves the source event’s append tags, event-source identity, and stream-route metadata. Tag-filtered inbox observers can select those events. Events forwarded by earlier releases that dropped tags remain untagged; upgrading does not backfill them. Compliance and PII explains how forwarding preserves subject identity and handles encryption keys.

The kernel stores subscription definitions for the target event store, independently of a client session. They survive client disconnections and are re-established when the kernel starts.

You can register the same definition under the same subscription ID at application startup without creating a duplicate. Reusing the ID with a changed definition updates the subscription; an ID alone does not make every registration identical.

Source event store Target event store
───────────────── ─────────────────
Outbox Inbox
┌─────────┐ [subscription] ┌─────────┐
│ event A │ ─────────────────▶ │ event A │
│ event B │ ─────────────────▶ │ event B │
└─────────┘ └─────────┘

The kernel’s forwarding subscriber, EventStoreSubscriptionObserverSubscriber, receives events from the source outbox observer and appends them to the target inbox. Delivery into the inbox and processing by the consumer have separate progress: an event can have arrived even when a derived view has not updated.

A fresh subscription forwards matching retained outbox history from sequence number zero. Reconnecting the same subscription identity can instead resume from its saved forwarding progress. Replaying that source forwarding observer can append events to the inbox again; replaying a consumer inbox observer reprocesses rows already there. See Subscription recovery before choosing an operation.

Reactors, Projections, and Reducers on the Inbox

Section titled “Reactors, Projections, and Reducers on the Inbox”

Route each consumer observer to the inbox for the source it handles. In C#, implicit subscriptions infer that source from [EventStore] on the event contracts. With explicit subscriptions, configure the observer’s source or sequence separately; registering forwarding does not change a handler’s input sequence.

The following snippet shows how a reactor handles an incoming event. It does not select an inbox; add the source routing described in Subscribe Reactors to External Event Stores before using it as an inbox consumer.

using Cratis.Chronicle.Events;
using Cratis.Chronicle.Reactors;
[EventType]
public record SubscriptionsOutboxInboxOrderPlaced(Guid OrderId);
public class SubscriptionsOutboxInboxIncomingOrdersReactor : IReactor
{
public Task OrderPlaced(SubscriptionsOutboxInboxOrderPlaced @event, EventContext context)
{
// Handles OrderPlaced events from any subscribed source event store
return ProcessAsync(@event.OrderId);
}
Task ProcessAsync(Guid orderId) => Task.CompletedTask;
}

View C# snippet source on GitHub

To check the whole flow, publish an event to the source outbox, find its copy in the target’s per-source inbox, and then check the consumer’s result. If one step is missing, follow Subscription recovery to investigate that step rather than replaying the entire flow.