EN TR
Journal

Building Resilient Third-Party API Integrations: Timeouts, Retries and Idempotency

Admin 3 min read
Building Resilient Third-Party API Integrations: Timeouts, Retries and Idempotency

What happens when your payment provider responds three seconds late? In many projects, the customer refreshes the page and the same order is created twice. Integrations with external services are the most fragile part of any codebase because you do not control the other side. Here are the recurring mistakes we see and the habits that prevent them.

Set a timeout on every call

Many HTTP clients wait for a very long time by default. When an external service slows down, your own requests pile up and the whole site slows with it. Use a short connection timeout and a sensible overall limit, and move work to a background job whenever a user is waiting on screen.

Retry with care

Transient failures such as network drops, 502, 503 and 429 deserve a retry; client errors such as 400 or 422 do not. Use exponential backoff with some random jitter, cap the number of attempts, and respect the Retry-After header. After the final attempt, mark the job as failed and make it visible rather than silently dropping it.

Idempotency keeps operations single

A retry can duplicate work when the first request actually succeeded but the response was lost. Generate a unique idempotency key per logical operation and send it with the request. If the provider does not support keys, record a natural key such as the order number on your side and check it before starting the operation.

Handle webhooks defensively

  • Always verify the signature.
  • Store the raw event, return 200 quickly, and process it in a queue.
  • Keep event identifiers so duplicates can be ignored.
  • Do not rely on ordering; query the current state when it matters.

Plan the fallback

If the shipping rate service is down, should checkout stop, or continue with the last known rates? That is a business decision and should be made at the start of the project. A circuit breaker stops you from hammering a failing service and protects your own system.

Make failures visible

Many integration problems grow simply because nobody noticed them. Log duration, status code and a correlation identifier for each external call, and set up a dashboard and alerts for failed jobs. Keep sensitive data such as card details out of your logs.

Conclusion

A resilient integration does not assume that nothing will go wrong; it knows in advance what to do when something does. Timeouts, controlled retries, idempotency and careful webhook handling together keep external problems away from your customers. Reviewing existing integrations against this list is often the cheapest reliability investment you can make.

api integration idempotency webhooks timeouts retry strategy integration architecture

More articles