SfSkills Domains Docs GitHub

Home / architect / event-driven-architecture

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.

Open the skill folder on GitHub


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:


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:

PatternDescriptionBest Fit
Pub/SubPublisher emits events; one or more subscribers consume independentlyDecoupled notifications, audit feeds, cross-cloud fan-out
FanoutA single event is delivered to all registered subscribers simultaneouslyBroadcast scenarios where all consumers must receive every event
Passed MessagesEvents carry data payloads routed point-to-point through a channelRequest-reply over async channel; workflow hand-off between bounded contexts
StreamingContinuous ordered event feed consumed at subscriber pace (replay supported)Analytics pipelines, CDC-driven data sync, audit trails
QueuingEvents 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.

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

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:

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:

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:


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

SituationRecommended ApproachReason
Multiple systems must react to the same business event independentlyChoreography via Pub/Sub or FanoutNo coordinator needed; decoupling maximizes
Workflow requires all steps to complete or all to roll backOrchestration (Flow Orchestration or Apex Queueable)Central coordinator can compensate on failure
State reconstruction from event history is requiredEvent sourcing with external durable store (Data Cloud / Kafka)72-hour Platform Events replay window is insufficient
Single producer, single consumer, synchronous response neededRequest-reply (REST/SOAP callout)EDA adds complexity without benefit
Enterprise-wide events spanning multiple clouds and systemsEvent mesh with enterprise brokerDirect bus-to-bus connections become unmanageable at scale
Event volume exceeds what a single consumer can process in real timeQueuing pattern with competing consumersLoad leveling distributes processing across workers
Two-system integration with low volumeDirect callout or scheduled batchEDA overhead is not justified

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:


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

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

Dependencies

Package files