Select the Right Integration Pattern

Synchronous APIs, asynchronous messaging, batch processing and event streaming: what each does, its trade-offs, how they compare, and why one solution usually uses several.

  • Intermediate to advanced
  • About 22 minutes
  • Includes an exercise and a knowledge check

The concept Four ways for systems to talk

How systems communicate shapes reliability, latency, coupling and operational complexity. There are four main patterns, and each fits a different kind of business timing.

Four communication patterns with everyday metaphors. Synchronous API, a phone call: waits for the answer; use it when the result is needed now, such as looking up a payment; trade-off, it depends on the other side being up. Asynchronous messaging, a mailbox: drop it and carry on; use it for background work such as ingesting events; trade-off, duplicates and ordering to handle. Batch, the daily truck: everything at once on a schedule; use it for periodic files such as bank settlement; trade-off, only as fresh as the last run. Event streaming, a river: continuous, many can draw from it; use it for high volume with many consumers; trade-off, the most moving parts to run.
Same goal, different timing. Match the pattern to when the business needs the answer.

In detail Each pattern, its strengths and its costs

PatternUse it whenAdvantagesDisadvantages
Synchronous APIThe caller needs the result now, such as reading a transaction or updating an exceptionSimple request-response; immediate feedbackDepends on downstream availability; timeouts; cascading latency
Async messagingWork can happen independently, such as payment event ingestionDecouples systems; absorbs spikes; recovers after failuresDuplicates, ordering, replay and eventual consistency to design for
BatchThe process is naturally periodic, such as the daily settlement fileEfficient at volume; matches partner schedulesDelayed results; one failed batch affects many records; large files
Event streamingContinuous high volume with several consumersMany consumers; real-time analytics; replay where retainedMost infrastructure; partitions, lag and schema compatibility to manage

Side by side How the patterns compare

FactorSynchronous APIAsync messagingBatchEvent streaming
Immediate responseYesNoUsually noNot inherently
DecouplingLowerHigherHigherHigher
Workload spikesLimited by capacityCan bufferScheduledAbsorbed by retained streams
Processing modelRequest and responseMessageGroup of recordsContinuous events
OrderingApplication-definedDepends on setupFile orderBy partition and key
Operational complexityLow to mediumMediumLow to mediumMedium to high

Apply it One solution, several patterns

A candidate Apex design using several patterns. An operations user looking up a payment uses a synchronous API because the answer is needed now. A provider payment event uses asynchronous messaging: accept, record, process later. The bank settlement arrives as a batch file because the bank works daily. Reconciliation runs as scheduled processing after settlement lands. Failed processing waits in a queue for controlled retry, checking state before replay. Reporting receives history in a nightly batch. Event streaming is used only if continuous multi-consumer processing is required, which today's workload does not justify.
You do not have to force every workflow into one communication model.

Practice Pick the pattern

Practical exercise

Four more workflows

Choose a pattern for each workflow and give one reason.

  1. A borrower checks their payment status in a mobile app.
  2. A fraud team wants every payment event as it happens, alongside reconciliation and analytics.
  3. Finance needs a month-end extract of all adjustments.
  4. The loan servicing platform is occasionally unavailable for minutes at a time.
Show sample answers
  • Payment status: synchronous API; the borrower is waiting for an answer.
  • Fraud plus reconciliation plus analytics: event streaming may now be justified, because several consumers need the same continuous events. Confirm the volume first.
  • Month-end extract: batch; it is periodic and nobody needs it sooner.
  • Servicing sometimes down: accept and record events, then process asynchronously so a short outage does not reject payments.

3 questions

Check your understanding

1. A user needs an immediate answer. Which pattern fits?
2. Why might batch beat streaming for a once-a-day settlement file?
3. What must you still design even with a streaming platform's delivery guarantees?
Answer every question to submit.

What you can do now

  • Explain the four communication patterns and their trade-offs.
  • Compare them on response, decoupling, spikes, ordering and complexity.
  • Combine several patterns in one solution.