A circuit breaker stops a Salesforce integration from calling an external system that is already failing, and a fallback gives the process a defined path while those calls are paused. Open the breaker after a set number of timeouts or server errors inside a short window, serve the fallback, and close the breaker after a controlled test call succeeds.
When to stop calling a failing external system
Retrying a slow endpoint feels safe, but each attempt is another callout to a service that has already shown it cannot answer. Callout timeouts usually come first. An external service slows down, requests start hanging, and the transaction that made the call waits for a response it may not get. Once that repeats across many records, the process is queueing up behind a dependency that is down.
Write the opening rule for each breaker in one sentence. For example: five timeouts or 503 responses within two minutes opens the breaker for one named endpoint. Set the numbers from your own traffic. An integration that makes twenty calls an hour needs a different window from one that sends thousands during a nightly run, so a threshold copied from another project often trips at the wrong time.
Keep error types separate. Timeouts and server-side errors point to the external system, so they should count toward the breaker. A 401 response usually means credentials or permissions have changed, and a 400 response usually means the payload is wrong. Retrying either one will not fix it, and a breaker opened on them hides a configuration problem behind what looks like an outage. Send those errors to a fix-it queue instead.
Designing the fallback before anything fails
The fallback is the business decision that the breaker carries out. Write it down for each process before you build the breaker, because the people working through an incident will not have time to decide what a waiting record means. Common fallbacks fall into four groups:
- Queue the write. Save the outbound payload to a custom object with a pending status, and send it when the breaker closes.
- Use the last known value. Show the most recent synced value on the record and label it with the time it was last confirmed.
- Mark the record as waiting. Set a status field so users and reports can see which records have not reached the external system.
- Skip the call and keep the record. Let the user finish the transaction, skip only the external call, and show a clear message on the page.
Do not let a fallback drop data quietly. A queued record that no report shows is worse than a failed call, because nobody knows to look for it. Give each queued record a status, a timestamp, and a process name that a report can filter on.
Platform Events can separate the user transaction from the callout. The publishing transaction commits its own data and publishes an event. A trigger cannot make the callout itself, so the subscriber hands the work to asynchronous Apex and handles failure on its own schedule. An Apex trigger subscriber can ask for a retry by throwing EventBus.RetryableException. Replaying the original transaction needs custom design, so decide early what the event payload must contain to rebuild the request later.
For help planning this work, see Salesforce implementation.
Building retries and recovery paths
Retries and breakers do different jobs. A retry covers a short blip, and a breaker covers a longer outage. Put a fixed limit on retries inside each transaction, and let the breaker decide when to stop calling.
For Flow-based processes, use fault paths to send failed interactions to a recovery flow instead of showing a raw error. A fault connector can send the failure to a recovery path, where the flow records the failure and sets a status on the record.
For Apex, work in chunks where you can. Apex batch jobs isolate chunk failures, so one failed chunk does not stop the other chunks from processing. That gives you partial completion and a targeted retry of only the failed chunk. Build the retry queue around chunk boundaries, and keep the record IDs for each chunk so you can tell which records were sent.
When you retry transient errors, track the failures on the job records. Use the ExtendedStatus and NumberOfErrors fields on the AsyncApexJob record to decide whether a job failed for a reason worth retrying. If the same error repeats across attempts, stop retrying and treat the failure as a defect or an outage.
Who can change breaker settings
Thresholds, the endpoint each breaker covers, and any switch that forces a breaker open are operational controls, so limit who can change them. An administrator who can see the queue and the breaker status can run an incident. Developers should own the logic that opens and closes the breaker, and changes to that logic should go through the same release process as other integration code. For the access model behind this split, see permission set design for small teams.
Checks before you ship a breaker
Test in a sandbox with a stub endpoint that you can make fail on demand. Walk through each state change in order:
- Send normal traffic and confirm the breaker stays closed.
- Force timeouts until the threshold is passed, and confirm the breaker opens within the window you set.
- Run a user transaction through the fallback, and confirm the record shows the waiting status and the message text.
- Let the cooldown pass, and confirm that one probe call goes out while the rest of the queue stays held.
- Return success on the probe, and confirm the breaker closes and the queue starts at a controlled rate.
- Return failure on the probe, and confirm the breaker stays open and the cooldown restarts.
Check recent changes before you start. A validation rule or a field change can produce errors that look like an external outage, and a breaker opened by those errors hides the real cause. Review the validation rules in the integration path first, as covered in validation rules that do not break integrations.
Also check governor limits. A breaker that trips on limit exceptions is measuring a capacity problem, not an external one, and the fix is different. The limits that apply to admin-built processes are covered in governor limits for admins. Review them before you set thresholds.
Replaying queued work and avoiding duplicates
Replay queued records in the order they were created where order matters, such as a status update that must land after the create. Where order does not matter, replay in batches at a controlled rate. Start with a small batch, check the results, and increase the size only after the endpoint responds cleanly. For bulk loading choices, see Data Loader options for migration.
Check for duplicates before replay. If the external system accepted a request but the response timed out, a retry can create the same record twice. Send a unique key with each outbound request where the endpoint supports one, and check that key before resending. Where the endpoint does not support a key, query the external system for the record first. That adds a call per record, but it prevents a second copy that someone has to find and remove later.
Monitoring so the team knows when calls resume
The breaker state should be visible outside the code. Write each state change to a log record with the endpoint name, the old and new state, the reason, and the time. That log answers two questions quickly: is the breaker open right now, and how long has the queue been waiting?
The on-call person also needs a signal that the breaker has closed and the queue is draining. A scheduled probe that reports the endpoint state every few minutes is simple to build. Alert when a breaker has been open longer than the recovery target, so someone reviews the outage before the backlog grows. Set that target from the business impact. A breaker that stays open for three hours on an order sync needs a different response from one on a nightly report feed.
Questions about breaker thresholds and fallback design
How should the cooldown period be chosen after a breaker opens?
Choose the cooldown by how quickly the external system tends to recover and how much delay the business can tolerate. A short cooldown sends more probe calls into an outage. A long one holds the queue longer than necessary. Start with a value that matches your recovery target, then adjust it after you see a few real outages in the logs.
Can a breaker protect an overnight batch job?
Yes, but scope the breaker to the batch as well as the endpoint. Check the outcome of each chunk, and pause the remaining chunks when the breaker opens. The unfinished chunks stay queued with their record IDs, so the next run can pick them up without reprocessing the chunks that already succeeded.
Can a breaker be built with Flow alone?
Flow can handle the fault path, record the failure, and set the status fields that make up the fallback side of the design. Holding breaker state and cooldown logic is usually easier with code or a scheduled process, because the state changes on a timer and several processes read it.
Is a circuit breaker worth building for a low-volume integration?
Not always. If a failed call affects one record and a person can retry it the same day, a status field and a manual retry queue may be enough. The breaker earns its place when failures queue up behind users or jobs, or when repeated calls to a struggling service make the outage worse.