# What core architectural best practices govern resilient, scalable enterprise integration design in Salesforce?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Architecture Best Practices, Design Patterns

Read it on the site: https://www.forcechallenges.com/interview-questions/what-core-architectural-best-practices-govern-resilient-scalable-enterprise-integration-design-in-salesforce

## Answer

**Basics:** An integration is a contract between systems that fail independently. Good design asks: Is it real-time or batch? Who is the system of record? What happens when a call fails or repeats? How much volume and how many API calls? The Salesforce Integration Patterns catalog groups answers: Request and Reply, Fire and Forget, Batch Data Synchronization, Remote Call-In, UI Update Based on Data Changes, and Data Virtualization.

**How it works:**
1. Define data ownership and direction per entity.
2. Pick the pattern: synchronous request-reply for user-facing lookups; asynchronous fire-and-forget for non-blocking updates; Bulk API for volume; Salesforce Connect for virtualized reads; events for change notification.
3. Secure it: OAuth, Named/External Credentials, least-privilege integration user, TLS.
4. Make it reliable: idempotent operations, retries with backoff, dead-letter handling, logging with correlation IDs.
5. Observe: dashboards on failures, API usage, event backlog.

**Advanced / deep dive:** Use event-driven designs: **Platform Events**, **Change Data Capture** and the **Pub/Sub API** (gRPC) instead of polling; events have a replay window of 72 hours, so subscribers must store the last replay ID and resync from source if they are down longer (verify the current retention for your event type). Use middleware (MuleSoft, an ESB or iPaaS) when you need transformation, orchestration, many consumers or protocol translation, rather than point-to-point spaghetti. Respect limits: 100 callouts per transaction, 120 seconds cumulative timeout, API request allocation per 24 hours, 25 concurrent long-running requests, and the rule that a callout cannot follow uncommitted DML. Design for bulk: accept lists, use Composite/Collections, and avoid one call per record. Version contracts and test with mocks. Plan for eventual consistency: no distributed transactions, so use compensating actions.

**Code / config example:**
```apex
// Publish an event instead of making a synchronous callout from a trigger
List<Order_Closed__e> evts = new List<Order_Closed__e>();
for (Order__c o : closedOrders) {
    evts.add(new Order_Closed__e(Order_Id__c = o.Id, Ext_Id__c = o.Ext_Id__c));
}
List<Database.SaveResult> results = EventBus.publish(evts);
```

**Hidden gotchas & must-remember points:**
- Polling the API burns your daily allocation; use events or CDC.
- No cross-system transactions exist; design for retries and compensation.
- Callout after pending DML throws a CalloutException.
- Event delivery is at-least-once in practice; subscribers must be idempotent.
- Integration users consume licenses and can lock out when passwords expire; use OAuth flows.
- New custom platform events are high volume by default.

**Best practice:** Choose pattern by volume and latency, secure with named credentials, make every operation idempotent, and monitor from day one.

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