# What is the Remote Process Invocation Request-And-Reply pattern and what operational risks does it introduce in Salesforce?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Integration Patterns, Request and Reply

Read it on the site: https://www.forcechallenges.com/interview-questions/what-is-the-remote-process-invocation-request-and-reply-pattern-and-what-operational-risks-does-it-introduce

## Answer

**Basics:** This is one of the standard Salesforce integration patterns (Remote Process Invocation). Examples: validating an address, getting a credit score or a tax quote while a user waits. You use it when the outcome of the call changes what happens next in the same user interaction.

**How it works:**
1. A user action or process invokes Apex (or a Flow with an HTTP/External Services action, or a Lightning/Aura controller).
2. Apex builds `HttpRequest` using a Named Credential, calls `Http.send()`, and blocks.
3. The response is parsed and the logic continues; errors are shown to the user or logged.
Variants: Apex callout, `Continuation` (long-running calls from LWC/Aura/Visualforce), External Services actions in Flow, and Salesforce Connect for virtual data.

**Advanced / deep dive:** Operational risks:
- Latency: the user waits; default callout timeout is 10 s, maximum 120 s.
- Limits: 100 callouts per transaction, 120 s cumulative callout time, heap 6 MB sync.
- Concurrency: if 10 or more requests run longer than 5 seconds at once in an org, new ones can be rejected with a "concurrent requests" limit error. Slow endpoints therefore threaten the whole org. `Continuation` calls do not count toward this limit.
- Callouts are not allowed after uncommitted DML in the same transaction ("You have uncommitted work pending"), and cannot run directly from triggers (need `@future(callout=true)` or Queueable).
- Availability coupling: if the remote system is down, the Salesforce user action fails. The remote call also cannot be rolled back, so a later Apex failure can leave the two systems inconsistent unless you design compensation.
Mitigations: short timeouts, retries only for idempotent calls, circuit breakers (for example disable calling via a custom metadata flag after repeated failures), caching, and switching to fire-and-forget when the answer is not needed immediately.

**Code / config example:**
```apex
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Tax_Service/v1/quote');   // Named Credential
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setTimeout(10000);                              // ms; max 120000
req.setBody(JSON.serialize(payload));
try {
    HttpResponse res = new Http().send(req);
    if (res.getStatusCode() != 200) { /* log and show a friendly error */ }
} catch (CalloutException e) { /* timeout or network failure */ }
```

**Hidden gotchas & must-remember points:**
- Callout then DML is fine; DML then callout in the same transaction fails.
- Timeout applies per callout but cumulative time is capped at 120 s.
- Tests cannot make real callouts; use `HttpCalloutMock`.
- Retrying a non-idempotent POST can create duplicates.
- A record-triggered flow's synchronous path cannot make callouts; use the asynchronous path.

**Best practice:** Use Request and Reply only when the user truly needs the answer now, and always guard it with timeouts, error handling and idempotency.

---
Source: ForceChallenges · last updated 2026-11-02
