Tutorials & samples
Learn Relay by building.
Hands-on guides for everything Relay does — commands and queries, event sourcing, projections, messaging, workflows, operations. Every article is paired with a test-backed sample project you can dotnet run today. Pick the capability you need below.
Mediator & CQRS
4 articles
Getting Started: Commands, Queries, and the Mediator
Relay is a framework for building .NET services around CQRS (Command Query Responsibility Segregation) and an in-process mediator.

Your First Aggregate
In Getting Started, the Product was a plain record and the "store" was a dictionary.

Domain Events
In Your First Aggregate, the Order aggregate raised domain events, but they just sat in a list — nothing reacted to them. This article closes that loop.

Errors & HTTP
A handler's job is to express what went wrong in business terms — "this payment was not found," "the amount exceeds the limit," "the card was declined" — not to know that those map to HTTP 404, 422, and 402.
Event Sourcing
8 articles
Event Sourcing Basics
Every sample so far stored state: the current product, the current order, the current balance.

Concurrency & Snapshots
Event sourcing works beautifully for a fresh account with three events. Production breaks that idyll two ways.

Schema Evolution: Upcasters, Stable Names, Migrations
In an event-sourced system the events are the database, and unlike rows you can never UPDATE them — history is immutable.

Time-Travel & Live Aggregation: Reading the Past from the Stream
Event sourcing stores the sequence of events that produced an aggregate's state, and the write side rebuilds the current state by replaying that sequence.

Pessimistic Per-Aggregate Write Lock
Concurrency & Snapshots established Relay's default for concurrent writes to an event-sourced aggregate: optimistic concurrency.

Rich Event Metadata
Every event Relay appends already carries a little metadata: the CommandName that produced it and a Timestamp.

Event Archiving & Compaction
An event store is append-only: events are never updated and never deleted, which is exactly what makes it a trustworthy source of truth.

Crypto-Shredding for the Right to Erasure
An event-sourced system has a property its operators love and its compliance officers fear: the log is immutable and never deletes.
Projections & Read Models
7 articles
Projections
Event sourcing stores what happened, which is perfect for the write side and useless for the read side.

Projection Operations
The Projections article's host works while every event is well-behaved. Production guarantees two things that break that assumption.

Caching Queries
A read model already makes queries fast — a single indexed SELECT.

Inline & Multi-Stream Projections
The Projections article built the standard read side: a projection runs in a background host, catches up from a checkpoint after each command commits, and is eventually consistent.

Intra-Projection Sharding: Parallel Lanes for One Hot Projection
Projection Operations makes a deliberate promise: a projection has exactly one active worker.

Automated Blue/Green Projection Rebuilds
The Projection Operations article gave you the shadow (blue/green) rebuild: a projection implements IRebuildableProjection, IProjectionRebuildManager builds a fresh shadow read model from history while the live one keeps serving, and once the shadow has caught up an operator calls SwapAsync to atomically promote it.

Persistent Named Subscriptions
A projection is a catch-up reader: it walks the global event log forward, updates a read model, and remembers how far it got so a restart resumes instead of reprocessing two years of history.
Messaging & Reliability
4 articles
The Outbox Pattern
A command often needs to do two things: change its own state (save the order) and tell other services about it (publish OrderPlaced).

Messaging & Transports
The outbox stages events; a transport carries them.

The Inbox Pattern
The outbox guarantees at-least-once delivery — which means the same message can arrive twice (a broker redelivery, an outbox re-publish after a crash).

Reliable Messaging (End to End)
The previous three articles built the pieces; this one assembles them into the complete, reliable, cross-service flow:
Sagas & Workflows
4 articles
Sagas
A command changes one aggregate; reliable messaging lets services react to each other.

State-Machine Sagas
The Sagas article authored a saga imperatively — handler methods that mutate state and call RequestTimeout/Complete.

Routing Slips & Compensation
A distributed process books a flight, a hotel, and a car across three services. The flight and hotel succeed; the car fails.

Standalone Courier Activities
Routing Slips & Compensation showed compensation inside a saga: forward legs record undo-commands onto a durable itinerary, and a failure replays them in reverse as reliable, scheduled commands.
Scheduling & Time
2 articles
Scheduling
Some work shouldn't happen now — it should happen later: send a reminder in 30 minutes, expire an unpaid order in an hour, retry a failed call after a backoff.

Recurring Jobs
The Scheduling article covered one-shot future work. This article covers the recurring case — "every night at 2am," "every Monday," "every 15 minutes" — and the job as the unit of recurring/background work.
Tenancy & Security
2 articlesProduction Operations
7 articles
Observability: Telemetry, Metrics, Tracing, Health
You cannot operate what you cannot see. Relay is instrumented with OpenTelemetry-native primitives out of the box — no wrappers, no proprietary format.

Resiliency: Retries, Circuit Breakers, Rate & Concurrency Limits
Distributed systems fail in partial, transient ways: a database blips, a downstream API times out, a queue backs up.

Distributed Coordination: Locks, Leader Election, Partitioning
You scale a service by running more copies of it — but now those copies can step on each other: two instances run the same nightly job, or both try to advance the same projection, or process the same key out of order.

Reference Architecture: A Production Service End-to-End
The previous twenty-four articles each isolated one capability.

Fenced Leadership & Cluster Membership
The Distributed Coordination article elects a leader the simple way: a connection-bound ILeaderElector holds a PostgreSQL advisory lock for as long as its connection lives, and the database drops that lock when the process dies.

Operational Event Queries: A Forensic Scan over the Log
The event store is an append-only log, and Event Sourcing Basics is emphatic about the rule that follows from that: never query the event store for reads.

Telemetry Segmentation: Per-Tenant & Per-Dimension Metrics
Relay's command/query metrics are tagged by message type out of the box — relay.commands.executed and relay.queries.executed carry a command/query name plus success, and a matching duration histogram.

