---
name: event-driven-systems
description: Use for event-driven or message-driven architecture, commands and events, queues, pub/sub, Kafka, choreography, orchestration, sagas, outbox, idempotency, retries, ordering, backpressure, consumer lag, and messaging operations.
title: event-driven-systems
canonical_url: https://skilld.dev/gh/eralmansouri/skills/event-driven-systems
last_updated: 2026-09-27T14:01:38.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install eralmansouri/skills/event-driven-systems`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/event-driven-systems`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/eralmansouri/skills/event-driven-systems) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/event-driven-systems`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/event-driven-systems --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/event-driven-systems --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Event-Driven Systems

Use messaging to solve explicit workflow, temporal-decoupling, buffering, or
integration needs. It changes coupling rather than removing it and introduces
delivery, consistency, failure, and operational responsibilities.

## Design Workflow

1. Establish capability boundaries and ownership before choosing messages or transport.
2. Map business intent, facts, handoffs, decisions, deadlines, and failure outcomes.
3. Use synchronous request-response for an immediate answer, a command for directed intent, and an event for an independently consumable fact.
4. Decide whether temporal decoupling is valuable enough to change completed into accepted for later processing.
5. Use choreography while the workflow remains understandable; use orchestration or a stateful policy when progress and compensation must be explicit.
6. Define delivery, duplicate, ordering, timeout, retry, dead-letter, and reconciliation behavior.
7. Choose queue, pub/sub, or retained log by semantics rather than product preference.
8. Design external messages as stable APIs and keep internal events private by default.
9. Design tracing, lag monitoring, outbox operations, dead-letter replay, and capacity before rollout.
10. Choose deployment topology last; messaging does not require microservices.

## Message Semantics

- Command: imperative intent directed to one logical owning consumer.
- Event: past-tense fact, one logical publisher, zero or more consumers.
- Queue: distributes directed work to one logical consumer across competing instances.
- Pub/sub: gives each subscription or consumer group an independent copy.
- Retained log: retains records and tracks offsets; partitioning controls ordering and parallelism.
- Event-sourcing event, notification event, and state-transfer event are different concepts.

## Workflow Choice

Choreography lets boundaries react to facts without a central director, but the
end-to-end process becomes implicit. Use it for small, comprehensible handoffs.

An orchestrator persists progress, receives outcomes, and sends commands for
the next step. It adds explicit participant coupling but improves visibility,
deadlines, and compensation. A policy can record prerequisite events and act
once all are present, removing unnecessary arrival-order dependencies.

## Reliability Patterns

| Need | Pattern | Critical detail |
| --- | --- | --- |
| Atomic state and publication | Transactional outbox | Relay can publish duplicates |
| Duplicate internal work | Inbox/deduplication | Record ID and state change in one transaction |
| External side effect | Idempotency key and reconciliation | Local inbox cannot prevent duplicate remote effects |
| Unknown event order | Stateful policy | Record prerequisites and trigger once |
| Required per-key order | Partition/message group | Ordering limits concurrency |
| Complex workflow | Orchestrator/saga | Persist progress and model compensation |
| Future action | Delayed message | Recheck current state on delivery |
| Large payload | Claim check | Secure shared payload storage |
| New projection | Replay, snapshot, or lazy seed | Question broad data copying |

## Failure Responses

| Failure | Response |
| --- | --- |
| State commits but publication fails | Outbox |
| Acknowledgement is lost | Idempotent consumer or inbox |
| Remote request times out | Query by reference or reconcile |
| Poison message repeats | Bounded retries, inspectable DLQ, controlled replay |
| Slow dependency occupies workers | Timeouts, isolation, circuit/fail-fast where appropriate |
| Production exceeds consumption | Optimize, scale consumers, reduce inflow, or bound capacity |
| Hot partition | Revisit partition key; extra consumers cannot help that partition |
| Contract breaks consumers | Compatible evolution or a new version/type |
| Read model lags after a write | Primary read, wait/poll by version, or push completion |

Assume at-least-once delivery. Make outcomes idempotent, expect outbox relay
duplicates, prefer order-independent policies, bound retries by failure type,
and treat timeouts as uncertainty rather than proof of failure.

## Contracts And Operations

External events are public APIs. Prefer additive changes, but verify serializer,
schema-registry, and consumer behavior because unknown fields are not universally
safe. Use replacement events for semantic changes and translate from internal
state. Thin events work when consumers own what they need. State-carrying events
are valid when data distribution is the purpose, with explicit staleness,
seeding, and schema-coupling costs.

- Propagate trace and correlation context across producers, brokers, consumers, databases, and external calls.
- Track production and completion rate, queue depth, oldest age, lead time, processing duration, and lag by partition or group.
- Track retries, timeout categories, circuit state, dead-letter moves, and fallback usage.
- Monitor outbox age, unpublished rows, relay failures, and throughput.
- Expose workflow progress, deadlines, compensation, completion, and reconciliation state.
- Capacity-test databases and third parties before adding consumers.
- Provide inspectable messages and controlled replay with clear ownership.
- Perform a separate security and privacy review for sensitive fields, access controls, encryption, retention, deletion, dead letters, claim checks, and replay.

## Avoid

- Making every interaction asynchronous or calling every message an event.
- Using Kafka as a command queue without accepting its log semantics.
- CRUD over pub/sub with generic created, updated, and deleted events.
- Thin events followed by synchronous callbacks for required data.
- Fat events expanded for every consumer.
- Assuming FIFO delivery means handlers finish in order.
- Believing inbox deduplication makes external effects exactly once.
- Blanket retries and circuit breakers without modeled failure behavior.
- Treating a dead-letter queue as a solution without inspection and replay tooling.
- Using sagas as the source of truth for external systems.
