Implements CQRS with event sourcing on the iii engine. Use when building command/query separation, event-sourced systems, or fan-out architectures where commands publish domain events and multiple read model projections subscribe independently.
Comparable to: Kafka, RabbitMQ, CQRS/Event Sourcing systems
Use the concepts below when they fit the task. Not every CQRS system needs all of them.
HTTP POST /inventory (command)
→ cmd::add-inventory-item → validate → append event to state
→ publish('inventory.item-added')
↓ (fan-out via subscribe triggers)
→ proj::inventory-list (updates queryable list view)
→ proj::inventory-stats (updates aggregate counters)
→ notify::inventory-alert (sends low-stock alerts)
HTTP GET /inventory (query)
→ query::list-inventory → reads from projection state
| Primitive | Purpose |
|---|---|
registerWorker | Initialize the worker and connect to iii |
registerFunction | Define commands, projections, and queries |
trigger state::set, state::get, state::list | Event log and projection state |
trigger({ function_id: 'publish', payload }) | Publish domain events |
registerTrigger({ type: 'subscribe', config: { topic } }) | Subscribe projections to events |
registerTrigger({ type: 'http' }) | Command and query endpoints |
trigger({ ..., action: TriggerAction.Void() }) | Fire-and-forget notifications |
See ../references/event-driven-cqrs.js for the full working example — an inventory management system with commands that publish domain events and multiple projections building query-optimized views.
Code using this pattern commonly includes, when relevant:
registerWorker(url, { workerName }) — worker initializationtrigger({ function_id: 'state::set', payload: { scope: 'events', key, value } }) — event log appendtrigger({ function_id: 'publish', payload: { topic, data } }) — domain event publishingregisterTrigger({ type: 'subscribe', function_id, config: { topic } }) — projection subscriptionscmd:: prefix, projection functions with proj:: prefix, query functions with query:: prefixconst logger = new Logger() — structured logging per command/projectionUse the adaptations below when they apply to the task.
inventory-list, inventory-stats)TriggerAction.Enqueue({ queue }) instead of pubsub for guaranteed deliveryevt-${Date.now()}-${counter})iii-reactive-backend.iii-workflow-orchestration.iii-event-driven-cqrs when command/query separation, event sourcing, and independent projections are the primary concerns.iii-event-driven-cqrs in the iii engine.