Filed at ground and stays there.Integration

Retry logic is a love language

Idempotency, backoff, and caring about the system on the other end.

In this descent, 1 stop

Retry like you care about the other end

Retry logic says a lot about how you feel about the system on the other end. Retry instantly and forever, and you are the person who rings six times in a minute. Retry with exponential backoff, a sensible cap and a limit on attempts, and you are giving a struggling service room to recover. The second approach is kinder, and it usually gets your message through sooner as well, because the other end is not drowning. Backoff is manners, written in code.

Integer attempt = job.attemptCount;
if (attempt >= MAX_ATTEMPTS) {
    Logger.error('Order sync abandoned', job.orderId);
    return;
}
// Queueable delay is capped at 10 minutes by the platform
Integer delayMinutes = Math.min(10, Math.pow(2, attempt).intValue());
System.enqueueJob(new OrderSyncQueueable(job.next()), delayMinutes);

Retries only work if the receiving side is idempotent. Send every request with a stable key, such as the source record Id plus a version number, and have the target ignore anything it has already processed. Without that, a retry after a timeout creates a second order, and your careful backoff has just billed a customer twice. Politeness without idempotency is only a slower way to create duplicates. Log every duplicate you ignore. A rising count is often the first sign something upstream is struggling.

Nathan Avatar

More about Nathan

Where next