Sub topic 1
Why integration patterns matter
Prerequisites
This chapter assumes you already know the following:
- The basic Salesforce data model: objects, fields, and records.
- How REST APIs and JSON work.
- Basic Apex syntax and how triggers fire.
- HTTP methods and status codes, such as
GET,POST,200, and500.
You do not need to have built an integration before. This chapter sets up the vocabulary and the decision framework that the rest of the tutorial uses.
What an integration pattern is
An integration pattern is a named, reusable way to connect two systems. It describes who starts the conversation, whether the sender waits, and what happens when something fails. It is not a product or a single API.
Teams without patterns tend to build each integration from scratch. One developer uses a trigger that makes a callout, another schedules a nightly script, and a third polls an endpoint every minute. Each version works on a good day. On a bad day, such as a slow partner system or a spike in record volume, each one breaks in a different, surprising way.
Patterns give you a shared way to reason about those bad days before you write code.
The three patterns in this tutorial
This tutorial covers three core patterns. They differ in timing, coupling, and failure behavior.
| Pattern | Timing | Coupling | If the other side fails |
|---|---|---|---|
| Request-reply | Caller waits for the answer | Tight: both systems must be up now | The caller sees the error immediately and must handle it |
| Fire-and-forget | Sender continues without waiting | Loose: sender does not know the subscribers | The sender is unaffected, and delivery is retried or replayed later |
| Batch sync | Runs on a schedule or in volume | Loose in time, tight in data format | Individual rows fail, and you review the failed results |
Request-reply is a synchronous call. Salesforce sends a request and waits for a response before it continues. An Apex callout that asks a billing system for an invoice status is a typical example.
Fire-and-forget is asynchronous delivery. The sender hands over a message and moves on. Publishing a platform event is a typical example. Salesforce confirms it accepted the event, but it does not wait for subscribers to process it.
Batch sync moves large volumes of records in one job. Loading 2 million accounts from an ERP system through Bulk API 2.0 is a typical example.
A worked example: one business, three needs
Suppose a company runs Salesforce for sales and an ERP system for billing and shipping. Three requirements show up in the same week.
- A support agent opens a case and needs the customer's current invoice status on screen. The agent is waiting, and the data must be fresh. This is request-reply.
- When a warehouse ships an order, several other systems need to know: a notification service, an analytics pipeline, and a customer portal. The warehouse should not wait for any of them. This is fire-and-forget.
- Every night, the ERP system sends all changed customer records, tens of thousands of them, to Salesforce. No human is waiting, and volume matters more than speed per record. This is batch sync.
Using one pattern for all three would cause problems. A nightly load done as thousands of single callouts would use up API limits. A user-facing screen that depends on a nightly batch would show stale data. A shipping event sent as a synchronous call would stop the warehouse whenever one subscriber was slow.
Questions that drive every choice
The rest of the tutorial keeps returning to a few questions. Ask them at the start of any integration.
- Who is waiting? A person or a transaction that needs an answer now points toward request-reply.
- How much data? Thousands or millions of records point toward batch sync.
- What if the other system is down? If the work can be delayed safely, an asynchronous pattern is more resilient.
- What if the same message arrives twice? Networks retry. A safe design gives the same result no matter how many times a message is processed. This property is called idempotency.
- Which limits apply? Salesforce enforces governor limits and API limits, and they shape which patterns are practical.
Common mistakes at this stage
- Choosing a tool before the pattern. Teams pick a feature because it is familiar, then bend the requirement to fit it. Decide the timing and failure behavior first, then pick the Salesforce feature.
- Treating everything as request-reply. It is the easiest to understand, so it gets overused. It also couples your system's availability to the other system's availability.
- Ignoring failure until production. Each pattern fails differently. Decide up front who retries, how often, and where failures are recorded.
What comes next
The next chapters look at synchronous and asynchronous trade-offs, then at the Salesforce features that implement each pattern. After that, each pattern gets its own chapter with working code, followed by limits, idempotency, retries, and monitoring.
Exercise
A warehouse system must tell Salesforce, a portal, and an analytics service that an order shipped. The warehouse must not slow down if one of these systems is slow. Which pattern fits, and why?
Show answer
Fire-and-forget. The warehouse publishes one event and continues without waiting. Subscribers process it on their own schedule, so a slow subscriber does not block the warehouse. Request-reply would tie the warehouse's speed to the slowest receiver.
Exercise
Name two reasons why sending 500,000 record updates as individual request-reply callouts is a poor design.
Show answer
Any two of these: each call consumes API or callout limits, so the volume would exhaust them. Each call waits for a response, which makes the total run time very long. One failed call can leave the data half-updated with no simple way to review the failures. Batch sync with Bulk API 2.0 is built for this volume.