# Ampersand webhooks in production: duplicates, ordering, retries and timeouts

Agent skill: `npx skills add hookdeck/webhook-skills --skill ampersand-webhooks` ([details](https://hookdeck.com/webhooks/ampersand/skill))

This guide covers the problems Ampersand webhook destinations cause in production and how to handle each one. What Ampersand sends is on the [Ampersand webhooks](/webhooks/ampersand) overview, every notification type is on [Ampersand webhook events](/webhooks/ampersand/events), and signature verification code is on [Verify Ampersand webhooks](/webhooks/ampersand/verify).

## At a glance

| Problem | What to do | With Event Gateway |
| --- | --- | --- |
| [Timeouts](#timeouts) | Store the message, return a 2xx quickly and process in a background job | Accepts the delivery at once, then queues it for your service |
| [Duplicates](#duplicates) | Record each `svix-id`; upsert records on their provider id | Drops repeats before they reach your handler |
| [Ordering](#ordering) | Don't assume an order; compare the provider's own timestamps | Logs every event and attempt, so you can see arrival order when debugging |
| [Retries](#retries) | Route destination alerts elsewhere; trigger reads for the gap | Accepts deliveries while your service is down and replays them |
| [Choosing events](#choosing-events) | Branch on `notificationType`, then `action`; route only the types you handle | Filters and routes each kind of message to its own destination |
| [Testing](#testing) | Use a dev project, a temporary URL and the trigger read API | Forwards to localhost and replays past events |
| [Other limits](#other-limits) | Plan for 300 KB bodies, 15-minute download links and 1000 messages per second | Holds bursts in a queue and delivers at a rate you set |

## Ampersand webhook timeouts and slow handlers {#timeouts}

Return a 2xx quickly and do the work in a background job. Ampersand publishes no timeout for webhook destinations. Svix, which delivers its webhooks, documents 30 seconds to return a 2xx, and Ampersand doesn't say whether it changes that.

**Why it happens:** A result message can carry many records, and a backfill can send many messages in quick succession. A handler that writes every record to a database before responding falls behind during exactly those bursts, and Svix treats anything other than a 2xx as a failed delivery.

**Fix it in your handler:**

1. Verify the signature, store the raw message and return 200.
2. Process the message in a worker. See [why to process webhooks asynchronously](/webhooks/guides/why-implement-asynchronous-processing-webhooks).
3. Start any `resultInfo.downloadUrl` fetch as soon as the message is stored, because the link expires after 15 minutes.

**With Event Gateway:** Hookdeck accepts each Ampersand delivery immediately, then queues messages and delivers them to your service at a rate it can handle, with its own retries. Your handler can take as long as it needs without failing an Ampersand delivery.

## Duplicate Ampersand webhooks {#duplicates}

A resent message keeps its `svix-id`, so record each id you process and skip repeats. Ampersand's own pages don't discuss duplicates; the id's behaviour comes from Svix's documentation.

**Why it happens:** A delivery that times out or gets a non-2xx response is sent again, even if your handler had already done the work. Separately, the same records can come back in a new message with a new `svix-id`, for example from a triggered read over a period you've already synced.

**Fix it in your handler:**

1. Track processed `svix-id` values, using a database table with a unique constraint.
2. Upsert records on the provider's record id, and make handlers [idempotent](/webhooks/guides/implement-webhook-idempotency), so records that a later read returns again do no harm.
3. Don't deduplicate subscribe results on the record id and `subscribeEventType`. A record can change twice, and both updates would share that key.

**With Event Gateway:** Hookdeck [deduplicates](/docs/deduplication) events before they reach your endpoint, so repeats are filtered at the infrastructure level rather than in each handler.

## Out-of-order Ampersand webhooks {#ordering}

Ampersand doesn't document delivery order, so don't assume messages arrive in the order records changed.

**Why it happens:** A large read can arrive as several messages, each with a subset of the records. A delivery that fails and is retried can also arrive after a newer one.

**Fix it in your handler:**

1. Before overwriting a record, compare a modified timestamp from the provider's data in `raw`, where the provider has one. The field name varies by provider.
2. Use `operationId` to group the messages of one read. Subscribe results don't carry it.
3. Don't treat any one result message as the end of a read. `read.backfill.done` tells you a historical sync has finished, though Ampersand doesn't say it always arrives after the last result message.

**With Event Gateway:** Hookdeck logs every event and delivery attempt, so when state looks wrong you can see the order messages actually arrived in and replay them.

## Ampersand webhook retries and disabled destinations {#retries}

Keep the endpoint available. Ampersand reports results it couldn't deliver after all retries with `destination.delivery.error`, and it can disable a webhook destination automatically after repeated failures.

**Why it happens:** Ampersand publishes neither its retry schedule nor its disable threshold. Svix's documentation gives 8 attempts over about 27 hours, and disabling an endpoint after 5 days of failures, but Ampersand doesn't say whether it keeps those settings.

**Fix it in your handler:**

1. Route `destination.webhook.disabled` and `destination.delivery.error` to a different destination, such as Slack. Ampersand says the delivery error may or may not go to the destination that failed, so don't rely on the failing URL to tell you.
2. When a `destination.delivery.error` arrives, use its `installationId`, `objectName` and `action` to find the gap, then trigger a read for that object. Ampersand documents no way to resend a lost message, including subscribe results.
3. Ampersand doesn't document how a disabled destination comes back, so check it in the dashboard after an outage and ask `support@withampersand.com` if it stays off.

**With Event Gateway:** Hookdeck accepts Ampersand's deliveries while your services are down, so they succeed and the destination has no failures to count. Failed events can be [retried](/docs/retries) automatically, manually or in bulk once you recover.

## Choosing which Ampersand messages to receive {#choosing-events}

Route only the notification types you handle, and make sure your handler can tell the two message shapes apart.

**Why it happens:** A webhook destination can receive both results and notifications. Results have `action` and `result`, and aren't in the event list because `action` only names the kind of read or subscribe. Notifications have `notificationType` and `data`. A handler written for one crashes on the other.

**Fix it in your handler:**

1. Branch on `notificationType` first, then on `action`, or use separate destinations for data and notifications, each with its own handler.
2. Create a topic for the event types you handle. The dashboard creates the routes for you, and the API needs a route from each event type to the topic and from the topic to the destination.
3. Look up the tenant from `groupRef` and `consumerRef` before touching any data. `destination.webhook.disabled` carries neither, so handle it separately.

**With Event Gateway:** Hookdeck [filters](/docs/filters) on `notificationType` or `action` can route each kind of message to its own destination from a single source.

## Testing Ampersand webhooks {#testing}

Test in a separate dev project with a temporary URL, and use the trigger read API to produce messages when you need them.

**Why it's awkward:** A destination URL must start with `https`, and most messages depend on a customer's connection to a SaaS system, so you can't simply send yourself a sample.

**What to do:**

1. Create a dev project, as Ampersand recommends, and add a destination there. Destinations are per project, so its signing secret is different from production's.
2. Point it at a temporary URL to see real messages. Ampersand's docs suggest Hookdeck's tools for this, and [Hookdeck Inspect](https://inspect.hookdeck.com/webhooks/ampersand) has an Ampersand page.
3. Call the [trigger read API](https://docs.ampersand.ai/reference/read/trigger-a-read) to send a read on demand.
4. Keep fixtures of both message shapes, including a `url` result; [Ampersand webhook events](/webhooks/ampersand/events) has sample notifications to start from.

**With Event Gateway:** The [Hookdeck CLI](/docs/cli) receives webhooks on your machine without a public server, and you can replay past events. A replayed message keeps its original `svix-timestamp`, so the Svix libraries reject it more than five minutes later; [Verify Ampersand webhooks](/webhooks/ampersand/verify) explains the options.

## Other Ampersand webhook limits {#other-limits}

Plan for Ampersand's body size, its download links, its sending rate and two deprecated fields before they reach production.

**300 KB bodies.** A message can be up to 300 KB, and some frameworks default to less. Express's limit is 100 KB, so a backfill can start failing with `413 Payload Too Large`. Ampersand suggests setting the limit to 350 KB.

**Download URLs expire after 15 minutes.** A single record over 300 KB arrives with `resultInfo.type` set to `url` and no `result`. Fetch `resultInfo.downloadUrl` first and store the file. A message that waits in a retry queue, or is replayed later, carries a dead link, so trigger a new read for that object if it has expired. Installation notifications do the same with `configURL` and `lastConfigURL` when a config is too large to include.

**1000 messages per second.** That's Ampersand's default across all your destinations. Queue messages in your receiver, and contact Ampersand support if you need the limit changed.

**Deprecated error fields run in opposite directions.** On `connection.error`, read `errors`, because `error` is deprecated. On `write.async.done`, read `error`, because `errors` is deprecated and will be removed.

**Paused schedules.** Ampersand pauses a read schedule when runs keep failing, most often because a customer's connection has expired, and sends `read.schedule.paused`. No more results arrive until the connection is fixed and you call the unpause reads endpoint.

**Subscriptions left behind.** `subscribe.delete.error` means the provider's subscription may still be active and using its quota. You may need to remove it in the provider.

**With Event Gateway:** Hookdeck queues every delivery and can [limit the delivery rate](/docs/destinations#set-a-max-delivery-rate) to your service, so a backfill is spread out instead of overloading it. Filters can send `url` results to a dedicated destination that only downloads and stores the file, so a slow downstream service never holds up the fetch.