Skip to main content

Reliability and error handling

Most integration incidents are not caused by wrong endpoints. They are caused by a request that timed out, was retried, and applied twice β€” or by a sale that could not be completed because a loyalty call did not answer.

This page covers the four mechanisms that prevent that: idempotency, telling business rejections apart from technical failures, degraded mode, and compensation. They are independent of which module you are integrating, and they are worth deciding before the first line of code.

The failure that matters most: the ambiguous timeout​

When a request times out, you do not know whether it was processed. The sale is waiting. You have two options and both are wrong without a mechanism to disambiguate:

  • Retry blindly β€” and risk applying the same discount, redeeming the same voucher or granting the same points twice.
  • Do not retry β€” and risk losing the operation entirely.

Idempotency is what makes the first option safe.

Idempotency​

The Streaming API supports idempotent retries through an Idempotency-Key request header. When a retry carries the key of a request that was already processed, the API sends back the same response instead of applying the operation a second time.

Idempotency-Key: 3f8c2b1e-9d47-4a6f-b8e2-7c1d5a9f0b34

The contract, as defined in HTTP behavior:

RuleDetail
FormatYours to choose β€” V4 UUIDs or another sufficiently random string are the suggested format
Same key, same responseThe same response comes back, including when the first attempt returned an error code
Keys are not reusable with different parametersA key is bound to the request parameters it first carried
Keys expire after 24 hoursAfter that the key is forgotten and the request is processed as new
Not on GET or DELETEThey are idempotent by definition, so the header has no effect

Where it applies​

The endpoint reference marks idempotency explicitly on the point redemption endpoints β€” POST /points/redeem and POST /points/redeem_cart. Before making the header the retry mechanism for a flow, check the operation you are calling in the endpoint catalog and confirm with the Loyal Guru team that it accepts the key.

Cart confirmation is a different case. POST /carts/realtime does not validate cart integrity. If you resend a cart that is not unique β€” same cart id, same order in every line β€” the endpoint responds as if it had succeeded, but the effects behind it are not applied: no points awarded, no vouchers redeemed. A duplicate confirmation therefore does not double-count, but it is not visible in the response either, so your system cannot tell a real confirmation from a swallowed duplicate. Cart IDs that are unique, generated once at the origin of the sale and reused on every retry, are what keep that behaviour predictable.

Two consequences are easy to miss.

The key must be generated where the operation starts, not where the request is sent. If the middleware generates a fresh key on each attempt, retries are no longer protected. The key belongs to the business operation β€” this cart, this redemption β€” and has to survive a process restart on the way.

A replay returns the same error, not a second chance. If the first attempt was processed and came back with an error code, the retry with the same key comes back with that same error code. Retrying with an idempotency key never changes the outcome of the original request.

Business rejections are not failures​

A request can be perfectly well formed, reach the API, and still not do what you asked. That is not an error to retry β€” it is an answer.

Error responses carry both a human-readable message and a machine-readable code:

{
"error": "The voucher is already redeemed",
"code": "voucher_redeemed"
}

Vouchers are the clearest example, because they are the flows where two channels can genuinely collide:

CodeMeaning
voucher_redeemedAlready redeemed
voucher_expiredPast its validity period
voucher_inactiveNot active
voucher_deletedNo longer exists
voucher_out_dateOutside its valid dates
voucher_out_locationNot valid at this location
voucher_not_foundUnknown voucher

Retrying any of these produces the same answer. What the integration has to do instead is show the cashier a message that explains the situation and let the sale continue without that benefit.

The distinction to build into your error handling:

ClassExamplesWhat to do
Business rejectionvoucher_redeemed, customer_not_enough_score, customer_inactiveInform, do not retry, continue the sale
Client error400 malformed request, 403 invalid credentialsFix the request or the configuration; retrying will not help
Rate limit429Retry after the interval in Retry-After
Server error500Retry with exponential back-off

Concurrency on the same voucher​

Two checkouts, one voucher, the same second. This is not a case the integration has to resolve β€” it is resolved server-side, and the answer arrives as a business rejection.

Note that this is a different problem from the ambiguous timeout, even though both can end with a duplicate. Idempotency protects one operation retried twice. Concurrency control protects two distinct operations competing for the same resource. Solving one does not solve the other.

Degraded mode​

The sale must complete even if Loyal Guru is unreachable. This is not a nice-to-have, and it is the requirement most often left until the first outage.

A workable degraded mode:

SituationBehaviour
Simulation does not answer in timeContinue without loyalty benefits; do not block the checkout
Confirmation cannot be deliveredQueue it locally and complete the sale
The queue cannot drainRetry with back-off; escalate what never succeeds
Service is restoredReplay the queue with the original idempotency keys

Two decisions to make explicitly and write down:

  • The timeout budget. How long the checkout waits before giving up. It has to be short enough that the cashier does not notice, which usually means far shorter than the default of most HTTP clients.
  • What the customer is told. A sale that completes without the expected discount is a service situation, not just a technical one.

Retries and back-off​

For server errors, back off from a minimum of 1 second after the first error, increasing exponentially up to 32 seconds. For 429, honour the Retry-After header rather than guessing.

Retry only what is safe to retry: requests carrying an idempotency key, or reads. Never retry a business rejection.

Compensation​

Cancellations and returns are not retries. They are new operations that reverse the effect of an earlier one, and they need the same care: their own idempotency key, and a way to reconcile when the original operation is not found.

The reconciliation question worth answering during design: if a confirmation never arrived and the sale was cancelled, what does the platform hold? Deciding that before launch is cheaper than deciding it during an incident.

Troubleshooting​

SymptomLikely causeWhat to check
Duplicated effects after a timeoutA new idempotency key was generated on retryThe key must be created once, at the origin of the operation
A retry returns the same error every timeIt is a business rejection, not a technical failureRead the code field and stop retrying
Idempotent replay stopped working after a whileThe key expiredKeys are forgotten after 24 hours
400 on a retry that previously workedThe same key was reused with different parametersA key is bound to its original request
Checkout freezes during an incidentNo degraded mode, or the timeout budget is too generousCap the wait and continue the sale without benefits