# Webhook reliability
Source: https://docs.lomi.africa/build/reliability/webhook-reliability

Retries, idempotency, delivery logs, and safe handling of duplicate events.

***

title: Webhook reliability
description: Retries, idempotency, delivery logs, and safe handling of duplicate events.
----------------------------------------------------------------------------------------

Production integrations must assume **at-least-once** delivery: the same logical event may arrive more than once. This guide complements [Handling webhooks](/build/reliability/handling-webhooks) with operational behavior.

## Respond quickly, process async

Webhooks are delivered as plain HTTP `POST` requests. Your handler’s main job in the hot path is narrow: **authenticate the payload** (signature), **persist or enqueue the minimum you need** so you will not lose work, and **return a success status to lomi.** right away.

Return **2xx** promptly after you validate the signature and persist enough to acknowledge receipt. Heavy work should run in **your** background queue. If you block on third-party APIs, large database transactions, or sequential business rules before responding, you risk exceeding lomi.’s outbound HTTP read timeout (**approximately four seconds per attempt**: see [timeouts and retries](#timeouts-retries-and-client-errors)). Keeping the HTTP response under a second in the common case leaves headroom for bursts and cold starts.

## Idempotent processing

Use a stable **event envelope id** or a tuple of **(event type, canonical resource id)** to detect duplicates:

* If you have already applied the event, **skip** or **no-op** safely.
* Never assume “exactly once” without storing processed ids.

This matches server-side patterns where transaction updates **merge metadata** and balance updates check **already processed** flags.

## Retries and delivery logs

Operational debugging almost always starts with what lomi. saw on the wire. Your endpoint’s response code, body snippet, and timings are written to **webhook delivery logs**, which you can read from the Dashboard or the [Webhooks](/api/webhooks) API. Use them to:

* confirm whether your endpoint returned non-2xx
* inspect latency and payload size
* debug signature or parsing issues

### Fetch delivery logs

```bash
curl -X GET "https://api.lomi.africa/webhooks/YOUR_WEBHOOK_ID/logs?limit=10&failed=true" \
  -H "X-API-Key: YOUR_API_KEY"
```

`GET /webhooks/{id}/logs` accepts `limit` (max 100), `offset`, `success`, and `failed`.

### Retry a failed delivery

```bash
curl -X POST "https://api.lomi.africa/webhooks/YOUR_WEBHOOK_ID/logs/YOUR_LOG_ID/retry" \
  -H "X-API-Key: YOUR_API_KEY"
```

Manual retry is for a specific failed log entry. Automatic retries stay bounded: `4xx` is usually terminal for that sequence, while `5xx` and timeouts may retry. See [timeouts and retries](#timeouts-retries-and-client-errors).

<h2 id="timeouts-retries-and-client-errors">Timeouts, retries, and client errors</h2>

The sections below describe how lomi. delivers webhooks today so you can plan for **timeouts**, **retries**, and **non-retryable client errors**. Product behavior can evolve; when in doubt, rely on delivery logs and **idempotent** handlers.

### Per-attempt HTTP timeout

lomi.’s webhook HTTP client waits **approximately 4 seconds** (`timeout: 4000` ms per request) for your server to finish the HTTP response.

* Aim to send **`200` / `204` immediately** after verifying `X-Lomi-Signature` (well under \~1 s), then enqueue business logic elsewhere.
* If you exceed \~4 s, from lomi.’s viewpoint the delivery **failed due to timeout** for that attempt (subject to retries, see below).

### When lomi retries (and when it does not)

On **each failed attempt**, lomi. classifies the HTTP response as follows:

| Outcome                                                           | Retries?                                                                 |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------ |
| **2xx**                                                           | No, delivered                                                            |
| **4xx client errors** (`400`–`499`, incl. **`401 Unauthorized`**) | **No further attempts** for that delivery (“non-retryable client error”) |
| **5xx** and transient/network errors                              | **Yes**: subject to backoff and attempt caps                             |

In practice: **fix configuration and auth issues** (which often surface as `4xx`) before expecting automatic healing, lomi. will not keep retrying a misconfigured URL.

### Retry attempt limits

For **retryable** failures (timeouts, `5xx`, transient network faults), lomi. may attempt delivery up to **four** times on some paths, or up to **five** times when delivery is queued, with **exponential backoff** (initial delay about **3–5 seconds** between attempts).

You do not need to distinguish delivery paths in your handler, **always** process events idempotently, but attempt counts help when you read delivery logs after an outage.

### Payload envelope (`lomi_environment`)

The JSON field **`lomi_environment`** reflects the deployment environment (`production`, `development`, etc.). It is **not** a substitute for distinguishing **live** vs **test** traffic, use your API key environment and webhook endpoint configuration for that.

## Signature verification

Verify using the **raw request body** bytes. Re-serialized JSON can break HMAC or similar schemes. Details: [Handling webhooks](/build/reliability/handling-webhooks) and [API integration](/start/first-payment).

## Test vs live

Webhook endpoints and secrets are **environment-specific**. Promote configurations carefully so test URLs and secrets never receive live traffic.

## Related API reference

* [Webhooks API](/build/reliability)
* [Payment and payout lifecycle](/build/reliability/payment-lifecycle)
