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:
| Rule | Detail |
|---|---|
| Format | Yours to choose β V4 UUIDs or another sufficiently random string are the suggested format |
| Same key, same response | The same response comes back, including when the first attempt returned an error code |
| Keys are not reusable with different parameters | A key is bound to the request parameters it first carried |
| Keys expire after 24 hours | After that the key is forgotten and the request is processed as new |
Not on GET or DELETE | They 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:
| Code | Meaning |
|---|---|
voucher_redeemed | Already redeemed |
voucher_expired | Past its validity period |
voucher_inactive | Not active |
voucher_deleted | No longer exists |
voucher_out_date | Outside its valid dates |
voucher_out_location | Not valid at this location |
voucher_not_found | Unknown 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:
| Class | Examples | What to do |
|---|---|---|
| Business rejection | voucher_redeemed, customer_not_enough_score, customer_inactive | Inform, do not retry, continue the sale |
| Client error | 400 malformed request, 403 invalid credentials | Fix the request or the configuration; retrying will not help |
| Rate limit | 429 | Retry after the interval in Retry-After |
| Server error | 500 | Retry 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:
| Situation | Behaviour |
|---|---|
| Simulation does not answer in time | Continue without loyalty benefits; do not block the checkout |
| Confirmation cannot be delivered | Queue it locally and complete the sale |
| The queue cannot drain | Retry with back-off; escalate what never succeeds |
| Service is restored | Replay 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.
Related API Referenceβ
- HTTP behavior β idempotency, rate limits, status codes and the error format
- API Reference β endpoint catalog
Troubleshootingβ
| Symptom | Likely cause | What to check |
|---|---|---|
| Duplicated effects after a timeout | A new idempotency key was generated on retry | The key must be created once, at the origin of the operation |
| A retry returns the same error every time | It is a business rejection, not a technical failure | Read the code field and stop retrying |
| Idempotent replay stopped working after a while | The key expired | Keys are forgotten after 24 hours |
400 on a retry that previously worked | The same key was reused with different parameters | A key is bound to its original request |
| Checkout freezes during an incident | No degraded mode, or the timeout budget is too generous | Cap the wait and continue the sale without benefits |