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
Section titled “The Outbox”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.
The Inbox
Section titled “The Inbox”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; }}import io.cratis.chronicle.eventSequences.EventSequenceId
object SubscriptionsOutboxInboxId { fun resolve(): EventSequenceId { val inboxId = EventSequenceId("inbox-source-event-store") // Resolves to: "inbox-source-event-store" return inboxId }}// EventSequenceId is a Kotlin value class, so its constructor is mangled for Java - the id is// just this string wherever a Java API asks for one.class SubscriptionsOutboxInboxId { static String resolve() { String inboxId = "inbox-source-event-store"; // Resolves to: "inbox-source-event-store" return inboxId; }}Elixir does not support this workflow yet.TypeScript does not support this workflow yet.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.
Lifecycle
Section titled “Lifecycle”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.
Event Flow
Section titled “Event Flow”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;}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactor
@EventTypedata class SubscriptionsOutboxInboxOrderPlaced(val orderId: String)
@Reactorclass SubscriptionsOutboxInboxIncomingOrdersReactor { fun orderPlaced(event: SubscriptionsOutboxInboxOrderPlaced, context: EventContext) { // Handles OrderPlaced events from any subscribed source event store process(event.orderId) }
private fun process(orderId: String) {}}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;
@EventTyperecord SubscriptionsOutboxInboxOrderPlaced(String orderId) {}
@Reactorclass SubscriptionsOutboxInboxIncomingOrdersReactor { void orderPlaced(SubscriptionsOutboxInboxOrderPlaced event, EventContext context) { // Handles OrderPlaced events from any subscribed source event store process(event.orderId()); }
private void process(String orderId) {}}Elixir does not support this workflow yet.import { eventType, onceOnly, reactor } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class SubscriptionsOutboxInboxOrderPlaced { @field(String) readonly orderId: string;
constructor(orderId: string) { this.orderId = orderId; }}
@reactor()class SubscriptionsOutboxInboxIncomingOrdersReactor { // Without @handles(EventType), the method name must be the exact camelCase of the // event's class name - Chronicle discovers undecorated handlers by name, not by parameter type. @onceOnly() async subscriptionsOutboxInboxOrderPlaced(event: SubscriptionsOutboxInboxOrderPlaced): Promise<void> { // Handles OrderPlaced events from any subscribed source event store await this.process(event.orderId); }
private async process(orderId: string): Promise<void> {}}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.