# Why is publish-subscribe architecture superior to tight point-to-point coupling for complex enterprise integrations?

**Topic:** Integration · **Difficulty:** Medium · **Tags:** Integration, Pub-Sub Architecture, Decoupling Patterns

Read it on the site: https://www.forcechallenges.com/interview-questions/why-is-publish-subscribe-architecture-superior-to-tight-point-to-point-coupling-for-complex-enterprise

## Answer

**Basics:** In point-to-point, system A calls B, C and D directly. A needs their endpoints, formats and availability, and adding a new consumer means changing A. With pub-sub, A publishes an event such as `OrderPlaced` to a bus, and any interested system subscribes. The bus stores the message, so subscribers that are offline can catch up later.

**How it works:** In Salesforce the bus is the event bus. Platform events, Change Data Capture and Pub/Sub API are the building blocks. Publishers raise events from Apex, Flow, API or a trigger. Subscribers can be Apex triggers, Flows, LWC (`empApi`), CometD or gRPC clients. A replay ID lets each subscriber track its own position. Retention is commonly documented as 72 hours (verify for your release).

**Advanced / deep dive:** Benefits are loose coupling, fan-out to many consumers, burst absorption, and resilience when a consumer is down. Costs are eventual consistency, no direct response to the publisher, harder debugging (you need correlation IDs), and at-least-once delivery, which requires idempotent consumers. Use request-reply (REST or Apex callouts) when the caller needs an immediate answer, and use events when many systems need to learn that something happened. Event contracts are public APIs, so version them carefully. Retention limits mean a long outage needs a resync path from the source of truth.

**Code / config example:**
```text
Point-to-point: Salesforce -> ERP, Salesforce -> Billing, Salesforce -> Warehouse  (3 connections, each custom)
Pub-sub:        Salesforce -> [Order_Event__e] -> ERP / Billing / Warehouse   (publish once, add subscribers freely)
```

**Hidden gotchas & must-remember points:**
- Pub-sub is not a transaction. There is no rollback across subscribers.
- Ordering is by replay ID on a channel, but processing across retries can repeat events.
- The event bus is not a permanent store. Events expire after the retention window.
- Publishing and delivery are limited by org allocations, so heavy fan-out needs capacity planning.
- Do not use events as a way to hide a synchronous requirement.
- Monitoring becomes essential, since failures are no longer visible to the caller.

**Best practice:** Use events for notification and decoupling, keep payloads small with identifiers, and make every consumer idempotent.

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