Salesforce Event-Driven Architecture

A reference design for publishing Salesforce changes as events, delivering them to external consumers, and handling ordering, replay, duplicates and failures.

Banner for the GeekMidst reference architecture “Salesforce Event-Driven Architecture”, covering Business context and Salesforce event-driven…

An event-driven architecture lets Salesforce announce that something happened, such as an order was approved or a contact changed, and lets other systems react without Salesforce calling each of them directly. It reduces polling, isolates failures and makes it easier to add consumers later. It also brings its own problems: duplicates, ordering, replay windows and failed messages. This page is a reference design; we validate the APIs, edition and permissions for each implementation.

Business context

Point-to-point callouts from triggers are a common source of fragile orgs: a slow ERP blocks a save, and a new consumer means new Apex. Events break that coupling. Salesforce offers two main event types. Change Data Capture (CDC) publishes record changes for selected objects. Platform events carry business events you define, published from Flow, Apex or APIs. External clients subscribe through the Pub/Sub API (gRPC over HTTP/2, with Avro payloads), which Salesforce describes as a newer API than the Streaming API; the Streaming API is not marked deprecated. Inside the org, Apex triggers subscribe and run asynchronously after commit.

GeekMidst can design and implement event-driven integrations with MuleSoft or other middleware. See also platform events for decoupled integrations.

Salesforce event-driven reference architecture

Reference architecture: a reusable pattern, not a live client integration

Your integration estatePRODUCERSSALESFORCE EVENT BUSSUBSCRIBERSINTEGRATION AND BUSCONSUMERS AND OPERATIONSSalesforce recordsselected objectsAFlow and Apexbusiness logicAData 360data actionsAChange Data Capturechange eventsAPlatform eventscustom event typesAPub/Sub APIgRPC, HTTP/2, AvroApex trigger subscribersin-orgAEvent relaymanaged relayMiddlewareMuleSoft or otherExternal event busyour cloud or streaming platformERP and back officeconsumersData warehouseanalytics consumerDead-letter queuefailed messagesMonitoringalerts and dashboardsrecord changespublishdata actionssubscribesubscribein-org handlingrelayed eventsevent streamrelayed eventsnormalised eventsbusiness eventsevent historyfailed after retriesdepth alertsstatus write-back
  • Salesforce product
  • Data and analytics
  • Integration layer
  • Identity, policy and governance
  • External or custom system
  • People
  • AYour Salesforce org
  • Your integration estate
  • Dashed: asynchronous, optional or feedback
Diagram source (Mermaid)

Select a component to see what it is responsible for and how data moves to and from it.

Reference architecture. Event volumes, allocations, retention and consumer design are confirmed per implementation.
Components and data flows (text version)
ComponentTypeResponsibility
Salesforce recordsselected objectsSalesforce productRecord changes on objects enabled for Change Data Capture.
Flow and Apexbusiness logicSalesforce productPublish platform events for business moments such as order approved, rather than calling external systems directly.
Data 360data actionsData and analyticsCalculated insights can trigger data actions to platform events, Marketing Cloud or a webhook.
Change Data Capturechange eventsSalesforce productPublishes change events for selected objects. Change events are retained for 72 hours.
Platform eventscustom event typesSalesforce productCarry your own event schema. High-volume platform events are retained for 72 hours; standard-volume events are no longer available.
Pub/Sub APIgRPC, HTTP/2, AvroIntegration layerExternal clients subscribe, replay from a stored position and can use event filtering.
Apex trigger subscribersin-orgSalesforce productRun asynchronously after commit. Event filtering is not available for Apex triggers.
Event relaymanaged relayIntegration layerRelays events to an external event bus without custom subscriber code. Check supported targets in Salesforce documentation.
MiddlewareMuleSoft or otherIntegration layerSubscribes, transforms, deduplicates and routes events. Stores the last processed position and retries failures.
External event busyour cloud or streaming platformExternal or custom systemFans events out to many consumers and keeps its own retention for replay.
ERP and back officeconsumersExternal or custom systemProcess events idempotently, so the same event applied twice has no extra effect.
Data warehouseanalytics consumerData and analyticsStores the event history for analysis and audit.
Dead-letter queuefailed messagesIdentity, policy and governanceHolds messages that failed after the retry limit, with the error and payload, for review and replay.
Monitoringalerts and dashboardsPeopleTracks consumer lag, error rates, dead-letter depth and event allocation usage.

Data flows

  1. Salesforce records → Change Data Capture: record changes. Change events for enabled objects, published after the transaction commits.
  2. Flow and Apex → Platform events: publish. Flow or Apex publishes a platform event. If publishing fails, log it and alert; do not silently continue.
  3. Data 360 → Platform events: data actions. Insight-driven events, such as a lifetime value threshold crossed.
  4. Change Data Capture → Pub/Sub API: subscribe. External subscribers receive change events through Pub/Sub API.
  5. Platform events → Pub/Sub API: subscribe. External subscribers receive platform events, optionally filtered.
  6. Platform events → Apex trigger subscribers: in-org handling. Apex trigger subscribers run asynchronously after commit, for work that belongs inside Salesforce.
  7. Platform events → Event relay: relayed events. A managed relay to an external bus, as an alternative to running a subscriber.
  8. Pub/Sub API → Middleware: event stream. Middleware keeps the last processed position. After an outage shorter than the 72-hour retention window it can resume from that position; beyond it, run a reconciliation.
  9. Event relay → External event bus: relayed events. Events land on a supported external bus. Event relays support specific targets only, so confirm yours is one of them.
  10. Middleware → External event bus: normalised events. Middleware publishes cleaned, versioned events for many consumers.
  11. External event bus → ERP and back office: business events. Consumers deduplicate on an event identifier and check record versions before applying changes.
  12. External event bus → Data warehouse: event history. Stored for analytics and audit.
  13. Middleware → Dead-letter queue: failed after retries. Messages that keep failing go to the dead-letter queue with the error, so the stream keeps moving.
  14. Dead-letter queue → Monitoring: depth alerts. Alert when the queue grows or a message ages past an agreed limit.
  15. ERP and back office → Salesforce records: status write-back. Consumers that update Salesforce call its APIs through an integration user, not by publishing loops of events.

Component responsibilities

ComponentResponsible forKey design decision
Change Data CaptureAnnouncing record changesWhich objects and fields to enable
Platform eventsAnnouncing business eventsEvent schema and versioning
Pub/Sub APIDelivering events to external clientsFilters and stored replay position
Apex trigger subscribersIn-org reactionsKeep them small; no filtering available
MiddlewareTransform, deduplicate, route, retryRetry policy and dead-letter rules
External event busFan-out and longer retentionTopics, partitions and retention
ConsumersApplying changes safelyIdempotency keys and version checks

Data flow, step by step

  1. A user approves an order. A record-triggered flow publishes an Order_Approved platform event; CDC also publishes the Order change.
  2. Middleware, subscribed through Pub/Sub API, receives the event, validates the schema and checks whether it has already processed that event identifier.
  3. Middleware publishes a normalised event to the external bus and saves its new position.
  4. The ERP consumer applies the change. If the ERP rejects it, middleware retries with backoff and, after the limit, sends it to the dead-letter queue.
  5. The ERP writes the fulfilment status back to Salesforce through the REST API, using its own integration user.

Ordering, replay and idempotency

  • Ordering: do not assume a global order across event types or objects. Carry a record version or timestamp, and have consumers ignore changes older than the one they hold.
  • Replay: subscribers store their last position and resume from it. Salesforce retains high-volume platform and change events for 72 hours; PushTopic and generic events, now labelled legacy, for 24 hours. If an outage exceeds the window, run a reconciliation job instead of hoping for a replay.
  • Idempotency: every consumer must tolerate duplicates. Use an event identifier or a business key with a version as the deduplication key.
  • Dead-letter queue: a poison message must not block the stream. Park it with the error, fix the cause, then replay it deliberately.

Trust boundaries and authentication

External subscribers authenticate with OAuth through an External Client App, because Salesforce has said connected apps support ends in Summer '27. Give each subscriber a dedicated integration user with access only to the event channels and objects it needs. Credentials stay in the middleware's secrets store. Treat the external bus as a separate trust zone with its own access policies and encryption.

Failure scenarios and how to handle them

ScenarioEffectHandling
Subscriber down for hoursEvents pile upResume from the stored position within 72 hours; reconcile beyond that
Duplicate deliveryDouble processingIdempotent consumers keyed on event identifier
Poison messageStream stallsDead-letter after the retry limit, alert, fix and replay
Event allocation exhaustedEvents not deliveredMonitor usage against your org's allocations; check limits in Salesforce documentation
Record-lock errors in flowsFailed savesWinter '27 adds automatic retry on record-lock errors after 10 seconds (status not stated); design to avoid contention anyway
Schema change breaks consumersParsing failuresVersion events and add fields without removing old ones

Operational monitoring

Monitor consumer lag (time since the last processed event), error and retry rates, dead-letter depth and age, and event usage against allocations. Event Monitoring in Shield, a separate licence, adds API activity logs. Alert on silence too: a consumer that stops receiving events during business hours is often a failed subscription. Our integration error handling checklist lists the checks.

Alternative approaches and trade-offs

  • Scheduled API polling. Simple, but adds load and latency, and misses intermediate states.
  • Synchronous callouts from Flow or Apex. Fine when the user needs an immediate answer; risky for anything that can wait.
  • Data virtualisation with Salesforce Connect. Shows external data without moving it; it does not notify anyone of changes. See API-led integration architecture.

Implementation checklist

  1. 01

    List business events

    Name each event, its producer, consumers and the decision it drives.

  2. 02

    Choose CDC or platform events

    CDC for record changes, platform events for business moments.

  3. 03

    Design schemas

    Include an event identifier, version and timestamp.

  4. 04

    Build idempotent consumers

    Deduplicate and check versions before applying changes.

  5. 05

    Configure retries and a dead-letter queue

    Agree retry limits, alerting and who reviews parked messages.

  6. 06

    Test failure modes

    Stop consumers, replay, send duplicates and exceed the window in a sandbox.

  7. 07

    Set up monitoring

    Dashboards and alerts for lag, errors, dead-letter depth and allocations.

Questions we hear

Should we use CDC or platform events?
Use CDC when consumers need to know that a record changed. Use platform events for business events with their own meaning, such as an order being approved, which may combine several records.
How long can a subscriber be offline?
High-volume platform events and change events are retained for 72 hours. Beyond that, replay is not possible and you need a reconciliation process.
Does Salesforce guarantee exactly-once delivery?
Design as if it does not. Build idempotent consumers that can safely receive the same event twice.
Do we need middleware?
Not for one simple consumer. With several consumers, transformation, retries and dead-letter handling, middleware or an external bus usually pays for itself.

Sources

  • https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_subscribe.htm
  • https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/using_streaming_api_durability.htm
  • https://developer.salesforce.com/docs/data/data-cloud-dev/guide/dc-dev-overview.html
  • https://admin.salesforce.com/blog/2026/jens-top-winter-27-release-features-for-admins
  • https://www.mulesoft.com/

Design integrations that survive failure

We can design your events, subscribers, retries and monitoring, and build them with MuleSoft or other middleware. Consultations are remote, from India.

Book a consultation →

Tell us what you are trying to fix.

Share your Salesforce setup, goals and constraints. A practitioner reads every message and replies with questions, first thoughts or an honest view of whether you need outside help at all.

Talk to a Salesforce Expert
Book a Consultation