event-driven-architecture

Use when making architectural style decisions about whether and how to adopt event-driven architecture (EDA) for a Salesforce solution — including selecting a bus pattern, deciding between choreography and orchestration, designing event schema, and evaluating event sourcing feasibility. Triggers: 'should we use event-driven architecture or request-reply for this integration', 'designing an event mesh for Salesforce enterprise integration', 'choreography vs orchestration for our multi-system workflow', 'when does EDA add more complexity than value', 'how to architect event sourcing on Salesforce'. NOT for Platform Events implementation (use integration/event-driven-architecture-patterns). NOT for selecting between specific Salesforce event mechanisms such as Platform Events, CDC, or Pub/Sub API (use integration/event-driven-architecture-patterns).

Best use case

event-driven-architecture is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Use when making architectural style decisions about whether and how to adopt event-driven architecture (EDA) for a Salesforce solution — including selecting a bus pattern, deciding between choreography and orchestration, designing event schema, and evaluating event sourcing feasibility. Triggers: 'should we use event-driven architecture or request-reply for this integration', 'designing an event mesh for Salesforce enterprise integration', 'choreography vs orchestration for our multi-system workflow', 'when does EDA add more complexity than value', 'how to architect event sourcing on Salesforce'. NOT for Platform Events implementation (use integration/event-driven-architecture-patterns). NOT for selecting between specific Salesforce event mechanisms such as Platform Events, CDC, or Pub/Sub API (use integration/event-driven-architecture-patterns).

Teams using event-driven-architecture should expect a more consistent output, faster repeated execution, less prompt rewriting, better workflow continuity with your supporting tools.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.
  • You already have the supporting tools or dependencies needed by this skill.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/event-driven-architecture/SKILL.md --create-dirs "https://raw.githubusercontent.com/PranavNagrecha/AwesomeSalesforceSkills/main/skills/architect/event-driven-architecture/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/event-driven-architecture/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How event-driven-architecture Compares

Feature / Agentevent-driven-architectureStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Use when making architectural style decisions about whether and how to adopt event-driven architecture (EDA) for a Salesforce solution — including selecting a bus pattern, deciding between choreography and orchestration, designing event schema, and evaluating event sourcing feasibility. Triggers: 'should we use event-driven architecture or request-reply for this integration', 'designing an event mesh for Salesforce enterprise integration', 'choreography vs orchestration for our multi-system workflow', 'when does EDA add more complexity than value', 'how to architect event sourcing on Salesforce'. NOT for Platform Events implementation (use integration/event-driven-architecture-patterns). NOT for selecting between specific Salesforce event mechanisms such as Platform Events, CDC, or Pub/Sub API (use integration/event-driven-architecture-patterns).

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Event-Driven Architecture

Use this skill when the question is *whether* and *how* to adopt event-driven architecture as a strategic style for a Salesforce solution — not which specific Salesforce mechanism (Platform Events, CDC, Pub/Sub API) to use for a given integration requirement. This is the architectural decision layer that precedes mechanism selection.

---

## Before Starting

Gather this context before making architectural recommendations in this domain:

- What are the consistency requirements? Can the solution commit to eventual consistency, or does the workflow require strong transactional guarantees (e.g., financial settlement, inventory deduction)?
- How many systems need to react to the same business event? EDA pays off when fan-out is high; it adds unnecessary complexity when a single consumer is sufficient.
- Is state reconstruction from the event log a requirement? If yes, evaluate whether the event store has sufficient replay depth before recommending event sourcing.
- What is the failure tolerance model? Choreography tolerates partial failures; orchestration can centrally compensate.
- Most common wrong assumption: that Platform Events provide a durable event log suitable for event sourcing. The 72-hour default replay window does not support state reconstruction from event history without an external durable store.

---

## Core Concepts

### The Five EDA Bus Patterns

The Salesforce Architects EDA guide identifies five bus patterns available for Salesforce enterprise integration. Each solves a different routing and delivery problem:

| Pattern | Description | Best Fit |
|---|---|---|
| **Pub/Sub** | Publisher emits events; one or more subscribers consume independently | Decoupled notifications, audit feeds, cross-cloud fan-out |
| **Fanout** | A single event is delivered to all registered subscribers simultaneously | Broadcast scenarios where all consumers must receive every event |
| **Passed Messages** | Events carry data payloads routed point-to-point through a channel | Request-reply over async channel; workflow hand-off between bounded contexts |
| **Streaming** | Continuous ordered event feed consumed at subscriber pace (replay supported) | Analytics pipelines, CDC-driven data sync, audit trails |
| **Queuing** | Events are buffered; each event is consumed by exactly one worker (competing consumers) | Load leveling, exactly-once processing guarantee per event |

Selecting a bus pattern is an architectural decision — it determines the topology, failure propagation model, and consumer coupling before any Salesforce mechanism is chosen.

### Choreography vs Orchestration

**Choreography** is the coordination style where each service listens for events and reacts autonomously without a central authority directing the flow. There is no coordinator — each participant knows its own role.

- Decouples producers from consumers at design time
- Commits the solution to eventual consistency — no single participant knows the overall state of the process
- Failure in one participant does not block others, but compensating transactions must be designed explicitly
- Well-suited to: order lifecycle notifications, cross-cloud data sync, loosely coupled Salesforce-to-external workflows

**Orchestration** retains a central coordinator (Flow Orchestration, Apex, or a BPM tool) that directs each step explicitly and knows the overall process state.

- Retains transactional control — the orchestrator can compensate or roll back on failure
- Introduces coupling between the orchestrator and each participant service
- Suitable for: multi-step approval workflows, financial transactions requiring ACID-like guarantees, scenarios where a human-readable process map is required for compliance
- In Salesforce: Flow Orchestration provides managed orchestration with step-level monitoring; Apex-based orchestration via Queueable chains offers lower-level control

The critical architectural decision is not which tool to use but which *consistency model* the business requires. If eventual consistency is acceptable, choreography is the correct style. If the workflow cannot tolerate partial completion, orchestration is required.

### Event Sourcing — Architectural Considerations

Event sourcing is a pattern where the authoritative state of an entity is derived entirely by replaying its event history, rather than storing current state in a mutable record. It is architecturally distinct from simply publishing events.

**Platform Events are not a native event sourcing store.** The platform's default replay window is 72 hours (configurable to 3 days on some editions). After that window, events are no longer retrievable. This makes state reconstruction from event history architecturally unsound without an external durable store.

If event sourcing is genuinely required, the architecture must include one of:
- **Data Cloud** — durable storage with streaming ingestion via Pub/Sub API, suitable for Salesforce-native event sourcing
- **Apache Kafka** — enterprise-grade append-only log with configurable indefinite retention
- **Custom `Event_Log__c` object** — append-only Salesforce object storing event payloads; queryable via SOQL; subject to data storage limits and governor limits at high volume

Platform Events can act as the *transport* that delivers events to the durable store, but the store itself must live outside the Platform Events bus.

### Event Design Principles

Good event design is the foundation of a maintainable EDA. Four principles govern event schema quality:

1. **Schema versioning** — events must carry a schema version field. Consumers must tolerate unknown fields (forward compatibility). Breaking schema changes require version negotiation or a new event type, not an in-place modification.
2. **Idempotency** — consumers must be designed to process the same event more than once without side effects. At-least-once delivery is the default guarantee on most buses. Deduplication strategies: idempotency key on a custom object, UPSERT on an external ID, consumer-side processed-event log.
3. **Ordering guarantees** — most Salesforce buses do not guarantee strict ordering within a topic. Consumers that require ordered processing must implement sequence numbers or use a single-partition queue with a competing-consumer pattern.
4. **Event granularity** — events should represent a meaningful business fact (OrderPlaced, PaymentCaptured), not an implementation operation (RecordUpdated). Fine-grained technical events create brittle coupling between producer internals and consumers.

### Event Mesh Architecture

An event mesh is a network of interconnected event brokers that routes events dynamically across clouds, regions, and system boundaries. In Salesforce enterprise architecture, an event mesh typically connects:

- Salesforce Platform Events / Pub/Sub API as the Salesforce-native bus
- An enterprise message broker (Solace, Kafka, AWS EventBridge) as the inter-cloud routing layer
- External consumers (data warehouses, microservices, partner systems) subscribed through the mesh

Event mesh adoption is appropriate when events must traverse more than two systems or when the publisher and consumer landscape is expected to grow organically. For simple two-system integrations, a direct Pub/Sub channel is sufficient and a mesh adds unnecessary operational overhead.

### When NOT to Choose EDA

EDA adds architectural complexity. It is not the correct style for:

- **Simple request-reply integrations** — if System A needs a synchronous response from System B, use REST callout or SOAP. Adding an async event bus to a request-reply scenario adds latency and complicates error handling with no benefit.
- **Workflows requiring strong transactional guarantees** — if all steps must succeed or all must roll back atomically, choreography cannot deliver this. Consider orchestration or synchronous processing.
- **Low-volume point-to-point data sync** — if one system writes and one system reads, a direct integration or scheduled batch is simpler and more observable than an event-driven pipeline.
- **Teams without operational maturity for async debugging** — event-driven failures are harder to trace than synchronous call stacks. Without correlation ID conventions, centralized logging, and replay tooling, EDA increases mean time to resolution.

---

## Common Patterns

### Choreography for Cross-Cloud Order Lifecycle

**When to use:** An order placed in Salesforce must notify a fulfillment system, a finance system, and a customer notification service independently, with no centralized process coordinator.

**How it works:** Salesforce publishes an `Order_Placed__e` Platform Event. The fulfillment system (via MuleSoft or Pub/Sub API) subscribes and creates a fulfillment record. The finance system subscribes and posts a revenue recognition entry. The notification service subscribes and sends a confirmation email. Each subscriber operates independently and at its own pace.

**Why not orchestration:** The business accepted that a fulfillment delay does not block finance posting. Each system compensates independently on failure. Adding an orchestrator introduces a single point of failure and couples all three systems to the orchestrator's availability.

### Orchestration for Multi-Step Financial Transaction

**When to use:** A loan disbursement workflow requires credit check approval, compliance review, and fund transfer to complete in sequence — with full rollback if any step fails.

**How it works:** Flow Orchestration coordinates the steps sequentially. The orchestrator invokes each step, waits for completion, and can trigger compensation steps (e.g., reverse a credit hold) if a downstream step fails. All steps are visible in the orchestration monitor.

**Why not choreography:** The business requires that all three steps complete or none do. Eventual consistency is not acceptable for fund disbursement. An orchestrator provides centralized state and compensation capability.

---

## Decision Guidance

| Situation | Recommended Approach | Reason |
|---|---|---|
| Multiple systems must react to the same business event independently | Choreography via Pub/Sub or Fanout | No coordinator needed; decoupling maximizes |
| Workflow requires all steps to complete or all to roll back | Orchestration (Flow Orchestration or Apex Queueable) | Central coordinator can compensate on failure |
| State reconstruction from event history is required | Event sourcing with external durable store (Data Cloud / Kafka) | 72-hour Platform Events replay window is insufficient |
| Single producer, single consumer, synchronous response needed | Request-reply (REST/SOAP callout) | EDA adds complexity without benefit |
| Enterprise-wide events spanning multiple clouds and systems | Event mesh with enterprise broker | Direct bus-to-bus connections become unmanageable at scale |
| Event volume exceeds what a single consumer can process in real time | Queuing pattern with competing consumers | Load leveling distributes processing across workers |
| Two-system integration with low volume | Direct callout or scheduled batch | EDA overhead is not justified |

---

## Recommended Workflow

Step-by-step instructions for making an EDA architectural decision:

1. **Clarify consistency requirements** — establish whether the business process requires strong transactional guarantees or can accept eventual consistency. This single answer constrains the rest of the decision.
2. **Map the event topology** — identify all producers and consumers, the events that flow between them, and whether fan-out (one event, many consumers) or point-to-point is the dominant pattern.
3. **Select a bus pattern** — using the five-pattern framework (Pub/Sub, Fanout, Passed Messages, Streaming, Queuing), identify which pattern matches the topology and delivery semantics required.
4. **Choose choreography or orchestration** — if eventual consistency is acceptable and consumers are independent, choose choreography. If transactional control or compensation is required, choose orchestration.
5. **Evaluate event sourcing need** — if state reconstruction from event history is required, confirm an external durable store is included in scope (Data Cloud, Kafka, or Event_Log__c). Do not rely on Platform Events replay.
6. **Design event schema** — define event payloads with schema version field, idempotency key, business event name (not operation name), and ordering metadata if sequence matters.
7. **Document the Architecture Decision Record** — record the chosen pattern, the consistency model, the trade-offs accepted, and the external store strategy. This ADR is the deliverable that precedes mechanism selection.

---

## Review Checklist

Run through these before marking EDA architectural work complete:

- [ ] Consistency model is explicitly documented — eventual consistency or transactional control
- [ ] All producers and consumers are identified with event topology mapped
- [ ] Bus pattern selected from the five-pattern framework with rationale recorded
- [ ] Choreography vs orchestration decision is explicit and tied to consistency requirement
- [ ] Event sourcing feasibility evaluated — external durable store included in design if required
- [ ] Event schema includes version field and idempotency key
- [ ] Failure and compensation strategy is defined for choreography scenarios
- [ ] ADR completed before mechanism selection (Platform Events vs CDC vs Pub/Sub API vs external broker)

---

## Salesforce-Specific Gotchas

Non-obvious platform behaviors that cause real production problems:

1. **Platform Events 72-hour replay ceiling** — the default event replay window is 72 hours. After that, events are gone from the bus. Any architecture that relies on replaying Platform Events to reconstruct state or recover a consumer backlog beyond 3 days will fail silently — consumers simply miss events with no error.
2. **Choreography commits to eventual consistency — permanently** — teams often adopt choreography because it is easy to get started, then discover later that a compliance requirement demands proof that all steps completed. Choreography does not provide this by default. The consistency model must be a conscious architectural choice, not an afterthought.
3. **Platform Events ordering is not guaranteed** — events published to the same Platform Events channel can be delivered out of order under high throughput. Consumers that assume ordered delivery will produce incorrect results. Sequence number fields and consumer-side ordering logic are required if order matters.

---

## Output Artifacts

| Artifact | Description |
|---|---|
| Architecture Decision Record (ADR) | Documents EDA adoption decision, selected bus pattern, consistency model, and trade-offs accepted |
| Event topology diagram | Producer-consumer map showing event flows, bus patterns, and external system boundaries |
| Event schema specification | Field definitions including schema version, idempotency key, and business event name |
| External durable store design | Required when event sourcing is in scope; specifies store technology and retention policy |
| Choreography/Orchestration decision memo | Records which coordination style is chosen and why, tied to consistency requirements |

---

## Related Skills

- `integration/event-driven-architecture-patterns` — use after the architectural decision is made to select the specific Salesforce mechanism (Platform Events, CDC, Pub/Sub API, Change Data Capture)
- `apex/long-running-process-orchestration` — use when orchestration is chosen and Apex Queueable chains are the implementation vehicle
- `flow/orchestration-flows` — use when Flow Orchestration is selected as the orchestration runtime
- `architect/integration-framework-design` — use when designing the reusable integration layer that carries events between systems
- `architect/data-cloud-architecture` — use when Data Cloud is the selected external durable store for event sourcing

Related Skills

xss-and-injection-prevention

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when writing or reviewing Visualforce pages, Apex controllers, or LWC components that output user-supplied data, build dynamic queries, or construct HTTP responses. Triggers: 'XSS in Visualforce', 'SOQL injection vulnerability', 'how to encode output in Apex', 'JSENCODE Visualforce', 'open redirect prevention'. NOT for Apex CRUD/FLS enforcement (use soql-security or apex-crud-and-fls), NOT for Shield encryption (use shield-encryption-key-management), NOT for AppExchange security review process (use secure-coding-review-checklist).

shield-event-log-retention-strategy

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when designing Salesforce Shield Event Monitoring retention, SIEM routing, and storage-tier strategy — which event types to keep, for how long, where, and how to answer audit queries across hot/warm/cold tiers. Triggers: 'shield event log retention', 'route event monitoring to splunk', 'how long to keep login history', 'siem salesforce integration', 'event monitoring storage tier'. NOT for enabling Shield (see salesforce-shield-deployment).

recaptcha-and-bot-prevention

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when configuring reCAPTCHA on Web-to-Case, Web-to-Lead, Experience Cloud forms, or Headless Identity flows, or when designing bot-mitigation strategies for Salesforce public-facing surfaces. Triggers: 'enable reCAPTCHA on Web-to-Case', 'bot spam submissions on my Experience Site', 'Headless Identity reCAPTCHA v3 setup'. NOT for AppExchange security review (use secure-coding-review-checklist), NOT for session-level login security policies (use session-management-and-timeout), NOT for IP-range-based access controls (use network-security-and-trusted-ips).

event-monitoring

8
from PranavNagrecha/AwesomeSalesforceSkills

Shield Event Monitoring: event log types, downloading logs via REST API and SOQL, real-time event monitoring with streaming API, and threat detection policies. NOT for debug logs (use debug-logs-and-developer-console). NOT for custom platform event publishing/subscribing (use platform-events-apex).

lwc-server-sent-events

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when building LWCs that must react to live server pushes — Platform Events, Change Data Capture, or streaming updates — via the lightning/empApi (CometD) subscription model. Covers lifecycle, replayId, error handling, reconnection, scale considerations, and multi-tab behavior. Does NOT cover publishing events (see platform-events or apex-platform-events).

lwc-custom-event-patterns

8
from PranavNagrecha/AwesomeSalesforceSkills

When and how to design CustomEvent traffic out of an LWC — bubbles / composed / cancelable flag choices, detail payload shape, naming rules, and propagation control. Trigger keywords: 'event not reaching parent', 'composed shadow DOM', 'CustomEvent detail mutation', 'stopPropagation vs stopImmediatePropagation'. NOT for parent-to-child communication (use `@api` — see `lwc/component-communication`), NOT for sibling fan-out (use Lightning Message Service — see `lwc/lightning-message-service`), NOT for wire-service data plumbing.

platform-events-integration

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when publishing Platform Events from external systems via REST API, subscribing to Platform Events from outside Salesforce via CometD or Pub/Sub API, designing replay ID strategy for durable external consumers, or handling high-volume event delivery guarantees. Trigger keywords: 'external publish platform event', 'CometD subscribe', 'Pub/Sub API', 'replay ID external', 'durable subscription', 'RetainUntilDate'. NOT for Apex-only event publishing or triggering (use platform-events-apex). NOT for Change Data Capture external subscription (use change-data-capture-integration).

platform-event-schema-evolution

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when modifying the schema of a Platform Event that already has live publishers and subscribers — adding fields, deprecating fields, or splitting events. Triggers: 'add field to platform event without breaking subscribers', 'platform event versioning', 'evolve event schema safely', 'rename a field on a published event'. NOT for initial event design (use integration/platform-events-integration) or for Change Data Capture event schemas.

platform-event-publish-patterns

8
from PranavNagrecha/AwesomeSalesforceSkills

Publishing Platform Events: EventBus.publish, PublishBehavior (PublishImmediately vs PublishAfterCommit), high-volume events, event allocation, publish failures, Change Data Capture comparison. NOT for subscribing/consuming (use platform-event-subscribe-patterns). NOT for CDC architecture (use cdc-patterns).

recursion-and-re-entry-prevention

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when a record-triggered Flow re-fires on the same record because its own DML (or a downstream Flow's DML) re-satisfies the entry criteria — causing CPU-limit failures, duplicated side effects, or 'Maximum Trigger Depth Exceeded' errors. Triggers: 'flow infinite loop', 'flow re-firing on same record', 'flow updates field then runs again', 'flow A and flow B keep updating each other', 'maximum trigger depth exceeded record-triggered flow', 'flow recursion limit hit'. NOT for Apex trigger recursion (use apex/recursive-trigger-prevention) or for Loop element design inside a single Flow run (use flow/flow-loop-element-patterns).

pause-elements-and-wait-events

8
from PranavNagrecha/AwesomeSalesforceSkills

Use this skill when designing or troubleshooting flows that need to suspend execution and wait for an external signal — either a time-based alarm or a platform event. Trigger keywords: pause element, wait element, flow interview suspension, alarm event, platform event resume, async interview. NOT for scheduled flows that recur on a fixed schedule (use scheduled-flows), and NOT for record-triggered flow scheduled paths on a single record (those are set in the Start element, not a Pause element).

flow-platform-events-integration

8
from PranavNagrecha/AwesomeSalesforceSkills

Use when Flow is a Platform Event publisher, subscriber, or both. Triggers: 'publish platform event from flow', 'platform-event-triggered flow', 'high-volume platform event', 'publish after commit vs immediate', 'PE subscriber error handling', 'integration fan-out from save'. NOT for Change Data Capture (see integration skills) or for generic async work that does not need pub/sub (see flow/scheduled-flows).