Articles

Send signed deployment webhooks with automatic retries

Subscribe to a Gregale deployment event, verify its signature, and follow a failed attempt and successful retry under the same delivery ID.

Updated

Subscribe to deployment.live to send a signed webhook when an app goes live. Gregale signs the request, retries temporary failures, and records the outcome of each attempt. An event can enter the delivery queue without reaching the receiver. Look up its delivery ID to tell those apart.

This is the sending side of webhooks. If you're trying to receive events from Stripe or another provider, use the inbound webhook guide instead.

1. Register a receiver and choose an event

Register the HTTPS URL without credentials in the URL, then subscribe that destination to deployment.live for the source app. Give each receiver a dedicated signing secret, store it in the receiver's secret manager, and don't log it. This starter asks for the CloudEvents envelope and uses the default retry policy.

The next live deployment on the source app creates an outbound delivery automatically. This example uses that lifecycle event; it doesn't depend on the custom-event outbox endpoint.

2. Verify the signature on the exact bytes received

The receiver reads X-Faas-Webhook-Timestamp, X-Faas-Delivery-Id, and X-Faas-Webhook-Signature. Verify HMAC-SHA256 over:

text
<unix-timestamp>.<delivery-id>.<raw-body>

Compare against the hex signature after the sha256= prefix using a constant-time comparison. Reject timestamps outside a window you choose, and verify before decoding the JSON. Re-serializing the body can change the signed bytes. The timestamp is for the attempt; the delivery ID stays the same across retries. Neither receiving a valid signature nor receiving an HTTP retry makes processing exactly once.

3. Watch one temporary failure recover

Download the stateless Python starter. Run it only in a disposable Gregale workspace. It creates a public synthetic receiver and a separate disposable source app. It registers the receiver's generated HTTPS URL, subscribes the source to deployment.live, and deploys the source to trigger the event. It does not contact a customer's endpoint or need a database. Use the Gregale CLI, Bash, curl, jq, OpenSSL and Python 3. Export a test GREGALE_TOKEN that can manage the temporary app, its secrets and its webhooks, then run:

bash
bash run-demo.sh

The fixture checks that an unsigned control request is refused. For the signed event, the receiver verifies the signature on both attempts, deliberately answers 503 the first time, and returns 200 on the automatic retry. Inspect the same delivery's attempts endpoint in the webhooks API to see both outcomes; the ledger does not keep request or response bodies. The fixture uses the attempt header only to trigger the synthetic failure, not as an authentication or deduplication signal. Cleanup removes only the two test apps it created.

Make production retries safe

Deliveries are at least once: a receiver can commit a write successfully even if the sender never gets its response. After verifying the signature, record the delivery ID durably and apply the side effect in the same transaction where possible. Return a 2xx for a verified duplicate you've already processed. For side effects outside that transaction, use a durable business idempotency key or an outbox of your own. The starter intentionally performs no business writes and does not demonstrate durable deduplication.

See the application outbox for retry behavior and limits.

Questions

How do I tell whether an outbound webhook was delivered?

Use the webhook delivery ID and attempt history to check what the receiver returned. An event entering the delivery queue is not a receiver acknowledgement.

What should a webhook receiver verify?

Verify the signed timestamp, delivery ID, and raw request body together with the configured signing secret. Reject stale signatures before applying effects.

Do automatic retries deliver a webhook exactly once?

No. Outbound deliveries are at least once. Keep a durable record keyed by the delivery ID and make business effects idempotent.