# What common integration antipatterns should architects avoid to prevent governor limit exhaustion and system brittleness?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Integration Antipatterns, Best Practices

Read it on the site: https://www.forcechallenges.com/interview-questions/what-common-integration-antipatterns-should-architects-avoid-to-prevent-governor-limit-exhaustion-and-system

## Answer

**Basics:** An antipattern is a common design that looks reasonable but fails at scale. In Salesforce integrations the failures usually show up as limit errors, row-lock contention, API quota exhaustion, or silent data loss.

**How it works:** Common antipatterns and fixes:
1. **Polling** an API every few seconds: wastes API calls (daily quota is shared). Use Platform Events, CDC, outbound messages or Pub/Sub API instead.
2. **Point-to-point mesh**: N systems means N-squared connections. Use middleware/ESB or an event bus.
3. **Chatty record-at-a-time calls**: use Composite, sObject Collections or Bulk API.
4. **Callouts in loops or sync triggers**: 100 callouts per transaction; triggers cannot callout synchronously. Use Queueable with `Database.AllowsCallouts`.
5. **Large synchronous payloads**: 6 MB sync heap, timeouts. Use async and paging.
6. **No idempotency or retry**: duplicates and lost messages.
7. **Over-privileged integration users** and hard-coded credentials.

**Advanced / deep dive:** Concurrency is a hidden killer: more than 25 requests running longer than 20 seconds each trigger concurrent request limits, and parallel loads against the same parent cause `UNABLE_TO_LOCK_ROW` (use serial mode or sort by parent). Data skew (one account with hundreds of thousands of children, or one owner with huge record counts) makes sharing recalculation slow. Request-reply for long-running work blocks threads; prefer fire-and-forget with callback. Ignoring the API consumption model (24-hour rolling limit) lets one noisy integration starve others. Tight coupling to field API names makes schema changes break integrations; use a canonical contract and versioned endpoints.

**Code / config example:**
```apex
// Bulk-safe: one queueable per chunk, callouts allowed, no callout in trigger context
public class SyncJob implements Queueable, Database.AllowsCallouts {
    List<Id> ids; public SyncJob(List<Id> ids) { this.ids = ids; }
    public void execute(QueueableContext qc) {
        List<Account> accs = [SELECT Id, Name FROM Account WHERE Id IN :ids];
        HttpRequest req = new HttpRequest();
        req.setEndpoint('callout:ERP/accounts/bulk'); req.setMethod('POST');
        req.setBody(JSON.serialize(accs));          // one call for the whole chunk
        new Http().send(req);
    }
}
```

**Hidden gotchas & must-remember points:**
- Triggers cannot make synchronous callouts.
- 100 callouts and 120 s cumulative timeout per transaction.
- Parallel loads cause lock errors; use serial or ordering.
- Using the System Administrator profile for integrations is a security anti-pattern.
- Polling consumes daily API quota even when nothing changed.
- Do not retry non-idempotent calls blindly.

**Best practice:** Prefer event-driven, bulk, asynchronous, idempotent patterns with a least-privilege integration user.

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