domain event
A record that something meaningful happened in the business, such as an order being created, sent so other services can react.
In more detail
Events are named in the past tense and carry an ID for deduplication. With the outbox pattern they are stored in the same transaction as the change they describe.
Example
type DomainEvent = { type: "REGISTER"; email: string } | { type: "PAYMENT"; amount: number }, routed by an exhaustive switch on event.typeRelated terms
- transactional outbox — Saving an event into an outbox table in the same database transaction as the business change, then having a separate worker publish it.
- broker — A server that receives messages from producers, stores them and delivers them to consumers, such as RabbitMQ or Apache Kafka.
- idempotency — The property of an operation that gives the same result whether you run it once or many times, because a repeat run finds nothing left to do.
- discriminated union — A type made of several object shapes that share one literal field, such as status or type, whose value tells them apart.
- exhaustiveness checking — Having the compiler prove that code handles every possible member of a union, so a newly added member causes a compile error.
- dead letter queue — A separate queue where messages that keep failing are moved, so they stop blocking others and can be inspected and replayed later.
Taught in
- Asynchronous Event Processing: Outbox Pattern & Queues — Production Full-Stack Engineering
- Full-Stack System Verification: Capstone Integration — Production Full-Stack Engineering
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- any Versus unknown: Defensive Typing In Practice — Production TypeScript
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- The in Operator And Instanceof Narrowing — Production TypeScript
- Exhaustive Narrowing With never In Production Handlers — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript