Apex REST = synchronous request-response. Platform Events = asynchronous pub-sub.
Apex REST:
- External system calls Salesforce; gets immediate response.
- Or Salesforce calls external; gets immediate response.
- Synchronous; sender waits.
- Apex code must handle the request within governor limits.
Platform Events:
- Salesforce publishes event; subscribers process asynchronously.
- Salesforce subscribes to events from elsewhere via Pub/Sub API.
- Decoupled; sender doesn't wait.
- 72-hour event retention.
When Apex REST wins:
- Real-time response needed — user clicks button, expects immediate result.
- Bidirectional request-response — submit data, get back IDs / confirmation.
- Single-record operations — fetch one customer, return details.
- Complex transformations before/after — easier in code path.
- Tightly coupled — caller depends on receiver's specific response.
When Platform Events win:
- Decouple systems — publisher doesn't know subscribers.
- Async processing acceptable — fire and forget.
- Multiple subscribers — same event handled differently by different systems.
- Replay needed — subscriber catches up after downtime.
- High volume — throttle subscribers without backing up publishers.
- Eventual consistency acceptable.
Hybrid pattern:
- Apex REST for immediate request-response.
- Platform Events for follow-on async work.
Example: user submits form (Apex REST returns immediate ack); Apex publishes Platform Event for downstream processing.
Architecture decisions:
1. Latency requirement.
- Sub-second user-facing -> Apex REST.
- Multi-second acceptable -> Platform Events.
2. Coupling.
- Tight coupling acceptable -> REST.
- Decoupled architecture preferred -> Events.
3. Volume.
- Low volume -> either.
- High volume -> Events.
4. Reliability.
- Both reliable but different — REST has direct error handling; Events have retention + replay.
5. Cost.
- REST consumes API daily limits.
- Events have per-event costs at high scale.
Common pitfalls:
- Sync where async would do — overburdens Salesforce, blocks users.
- Async where sync needed — user gets no immediate feedback.
- Misuse of Platform Events as fire-and-forget without reliability — subscribers must be idempotent.
- REST overuse — chatty integrations hit API limits.
Senior architect insight: the choice is about coupling, not just synchronisation. Tightly coupled architectures use REST; decoupled use Events.
The senior framing: modern architectures lean toward eventing where possible. Decoupling enables independent evolution. Reserve sync for genuine real-time need.
