Core responsibilities
Your endpoint should:- Receive the HTTP
POSTfrom Pocketsflow. - Verify the
X-Pocketsflow-Signatureagainst the raw body (see Authentication & security). - Acknowledge with a
2xximmediately. - Parse the JSON and route on the
X-Pocketsflow-Eventheader. - Process the event idempotently in the background.
Delivery guarantees
Pocketsflow makes a single delivery attempt per event with a 5-second
timeout. There is no automatic retry of the outbound call — so if your
endpoint is slow, down, or returns a non-
2xx, that delivery is recorded as
failed and not re-sent. Design for at-most-once delivery: reconcile via the
API and re-fire test events manually when needed.- Acknowledge fast. Verify the signature, enqueue the event, and return
200— all well under 5 seconds. Never do slow work (emails, third-party calls, heavy DB writes) before responding. - Reconcile. Periodically pull the source of truth from the API so a missed
delivery self-heals:
- Orders →
GET /orders - Payments (one-time + subscription) →
GET /payments - Subscribers →
GET /subscriptions/subscribers
- Orders →
Idempotency
Handlers must be safe to run more than once for the same logical event. Pick a stable idempotency key from the payload and record it before you act:
Before processing, check whether you’ve already handled that key; if so, skip. If
not, record it and proceed. This protects you from re-processing during
reconciliation and from any duplicate delivery.
Ordering
Events are not guaranteed to arrive in the order they occurred. Don’t assume, for example, thatpayment_intent.succeeded always lands before the first
invoice.payment_succeeded. Make each handler tolerant of out-of-order arrival
(upsert state; use the payload’s own fields and the API rather than relying on
sequence).
Error handling
Plan for invalid payloads, downstream outages, and transient connectivity issues:- Log every delivery with enough context to debug (event type, idempotency key,
timestamp, and
webhookId). - Return
2xxonly after you’ve safely recorded the event for processing — not after the full downstream work completes. - Alert when your handler’s error rate crosses a threshold.
Recommended flow
1
Read the raw body
Capture raw bytes before parsing so signature verification is exact.
2
Verify the signature
Recompute the HMAC-SHA256 and compare in constant time. Reject on mismatch.
3
Enqueue and acknowledge
Persist the raw event (keyed by its idempotency key) and return
200.4
Process asynchronously
A worker parses
event.type, skips already-processed keys, performs the
action, and marks the key done.