Salesforce Decode
Salesforcedecode
Back to questions
ApexArchitect (Hardest)transactionscalloutsintegration

Design compensating transaction when external payment API fails after Salesforce commit

Real World Scenario

Order saved in Salesforce triggers payment capture callout. Gateway timeout causes unknown payment state while Order shows Paid in Salesforce.

Expected Answer

• Never block user DML on synchronous callout—decouple with Queueable • Order status Pending_Payment until async payment confirmation received • Idempotency key on payment API preventing duplicate charges on retry • Compensating Queueable voids authorization if DML rollback impossible • Reconciliation batch matches gateway settlement file to Order records nightly • Store payment correlation Id on Order before callout for support lookup • Saga pattern: explicit state machine not boolean Paid flag

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Direct answer: Never block user DML on synchronous callout—decouple with Queueable Also consider: Order status Pending_Payment until async payment confirmation received In practice: Idempotency key on payment API preventing duplicate charges on retry Document the decision in an ADR and align with enterprise standards.

Architect Perspective

Distributed transactions need explicit state machines—boolean flags hide partial failure states.