# Appstle Subscriptions webhooks in production: duplicates, ordering, retries and timeouts

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

This guide covers the problems Appstle Subscriptions webhooks cause in production and how to handle each one. What Appstle sends is on the [Appstle webhooks](/webhooks/appstle) overview, every event is on [Appstle webhook events](/webhooks/appstle/events), and signature verification code is on [Verify Appstle webhooks](/webhooks/appstle/verify).

## At a glance

| Problem | What to do | With Event Gateway |
| --- | --- | --- |
| [Timeouts](#timeouts) | 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`; key billing work on the attempt `id` | Drops repeats before they reach your handler |
| [Ordering](#ordering) | Don't assume an order; use `updatedAt`, `attemptCount` and `billingDate` | Logs every event and attempt, so you can see arrival order when debugging |
| [Retries](#retries) | Check the webhook portal after an outage and retry by hand | Accepts deliveries while your service is down and replays them |
| [Choosing events](#choosing-events) | Route on `type`; read the ID field for that shape | Filters and routes each kind of event to its own destination |
| [Testing](#testing) | Send an example event from the portal; keep fixtures of both shapes | Forwards to localhost and replays past events |
| [Other limits](#other-limits) | Parse failure reasons defensively; check the store's plan | Logs every event, so you can inspect and replay failures |

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

Return a `2xx` straight away and do the work in a background job. Appstle says slow responses time out and trigger retries, but it doesn't publish the timeout.

**Why it happens:** A contract event can start work in your CRM, fulfilment or analytics tools. A handler that waits for those calls before responding risks missing a limit you can't see. Appstle also counts any non-2xx as a failure, including one caused by your own business logic.

**Fix it in your handler:**

1. Verify the signature, store the raw event and return `200`.
2. Process the event in a worker. See [why to process webhooks asynchronously](/webhooks/guides/why-implement-asynchronous-processing-webhooks).
3. Return a `2xx` even when your business logic fails, as Appstle advises, and handle that failure on your side.

**With Event Gateway:** Hookdeck accepts each Appstle delivery immediately and queues it, so your handler can take as long as it needs without failing a delivery.

## Duplicate Appstle webhooks {#duplicates}

Appstle says webhooks may be delivered more than once and tells you to use the `svix-id` header for idempotency. It stays the same when a delivery is retried.

**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, some events repeat as different messages with a new `svix-id`. `subscription.billing-failure` fires after every failed try, and `subscription.upcoming-order-notification` can fire again when an order is rescheduled.

**Fix it in your handler:**

1. Track processed `svix-id` values, using a database table with a unique constraint. See our [guide to webhook idempotency](/webhooks/guides/implement-webhook-idempotency).
2. Treat `data.id` on a billing failure as the attempt. It stays the same across tries, while `attemptCount` goes up and `billingAttemptId` changes, so start dunning once per `id`.
3. Key your own reminders on `contractId` and `billingDate`, as Appstle suggests.

**With Event Gateway:** Hookdeck [deduplicates](/docs/deduplication) events before they reach your endpoint. Configure it on `svix-id` for retried deliveries, because the separate messages described above have new IDs and still need your own keys.

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

Appstle doesn't document delivery order, so don't assume events arrive in the order things happened.

**Why it happens:** A delivery that fails and is retried can arrive after a newer one. Some actions also send two events: on the last failed try, Appstle sends `subscription.billing-failure` and applies the store's failed-payment action, which sends `subscription.cancelled`, `subscription.paused` or `subscription.billing-skipped`.

**Fix it in your handler:**

1. On contract events, compare `updatedAt` with what you've stored before overwriting it.
2. On billing failures, ignore an event whose `attemptCount` is lower than the one you've stored for that `id`.
3. Don't make a billing failure depend on seeing the status change first. Handle whichever arrives, and let the later one find the work already done.

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

## Appstle webhook retries {#retries}

Keep the endpoint available, and check the webhook portal after an outage. Appstle retries a delivery that doesn't get a `2xx` with exponential backoff, but it doesn't publish the number of attempts, how long they run, or what happens when they run out.

**Why it happens:** You can't tell from the docs how long an outage is safe, so a long one may lose events with no signal from Appstle.

**Fix it in your handler:**

1. After any incident, open **Webhook Integration** under **More**, click **Launch webhook portal** and look through the delivery attempts.
2. Retry failed deliveries by hand from the portal.
3. If deliveries have stopped altogether, Appstle's troubleshooting steps are to confirm webhooks are enabled (the button reads **Disable Webhook**), the store's plan includes them and your endpoint is reachable over HTTPS.

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

## Choosing and routing Appstle events {#choosing-events}

Select only the events you handle for each endpoint, and route on `type` before you read any ID.

**Why it happens:** Seven events carry a Shopify subscription contract, where `data.id` is a string such as `gid://shopify/SubscriptionContract/12345`. Four carry a billing attempt record, where `data.id` is Appstle's number for the attempt and `data.contractId` is the subscription as a bare number, with no `gid://` prefix. Code that reads `data.id` as the subscription works on contract events and silently breaks on billing events.

**Fix it in your handler:**

1. Branch on `type`, then read the ID field for that shape. To join the two, take the number from the end of the `gid://` ID.
2. Read `retryingNeeded` only on `subscription.billing-failure`. Queued attempts report `true` too. `true` means Appstle has scheduled another try, which it can still drop without another event, for example if the subscription is paused or cancelled first.
3. Don't read `subscription.upcoming-order-notification` as "an email was sent". It fires even when the store has turned that email off, and `upcomingOrderEmailSentStatus` is always `null` on it.
4. Don't wait for an event about payment challenges. 3D Secure and similar challenges send none, so find attempts in `SECURITY_CHALLENGE` with Appstle's Admin API.

**With Event Gateway:** Hookdeck [filters](/docs/filters) on `type` can send contract events and billing events to different handlers from a single source, and a [transformation](/docs/transformations) can add a normalised contract ID before delivery.

## Testing Appstle webhooks {#testing}

Send an example event from the webhook portal, and keep fixtures of both payload shapes.

**Why it's awkward:** Only `subscription.created` and the four billing events have an example in Appstle's docs, and Appstle says its `subscription.upcoming-order-notification` example is trimmed. The other six contract events share the `subscription.created` shape but may leave out optional fields such as `discounts`, `note` and `customAttributes`.

**What to do:**

1. Open your endpoint in the webhook portal and send it an example event, then check your handler accepts it.
2. For local work, expose your server with a tunnel. Appstle suggests ngrok or localtunnel.
3. Log the raw payload during development, as Appstle suggests, and ignore fields you don't use. [Appstle webhook events](/webhooks/appstle/events) has samples to start your fixtures 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 event keeps its original `svix-timestamp`, so a five-minute check rejects it later on; [Verify Appstle webhooks](/webhooks/appstle/verify) explains the options.

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

Plan for these before they reach production.

**Failure reasons aren't always JSON.** `billingAttemptResponseMessage` is usually a JSON string with `error_code` and `error_message`. When Shopify rejects the billing request before trying the payment, it's plain text instead. Parse it in a `try`/`catch`, and handle anything that isn't JSON as a generic failure.

**Match on `error_code`, in upper case.** It can arrive as `insufficient_funds` or `INSUFFICIENT_FUNDS`, so trim it and compare in upper case. Appstle says never to match on `error_message`, because that text comes from Shopify and can change. Treat codes you don't recognise as generic failures. Out-of-stock failures such as `INVENTORY_ALLOCATIONS_NOT_FOUND` arrive through this event too, and they need a different response from an expired card.

**The field outlives the failure.** `billingAttemptResponseMessage` isn't cleared when a later try succeeds, so read it only on `subscription.billing-failure`.

**The status can say skipped.** When the last failed try makes the store skip the order, that try's `subscription.billing-failure` carries `status: SKIPPED_DUNNING_MGMT` instead of `FAILURE`.

**Nested JSON.** `contractDetailsJSON` on `subscription.upcoming-order-notification` is a JSON string, so parse it before you read the line items.

**Webhooks depend on the plan.** They're included in the Enterprise and Enterprise Plus plans. On another plan, a store gets none until you contact `support@appstle.com`, so check this first if you build for several stores.

**With Event Gateway:** Hookdeck logs every event it receives, so when a new error code or plain-text message breaks your parser you can fix the handler and replay the events that failed.