Skip to main content

Durable webhooks

Restate handlers can be used as durable processors of webhook events.

What does this give you?

  • Restate persists all incoming events, and ensures that they are processed exactly once, across failures and restarts. Restate guarantees your handler runs till completion.
  • Let Restate deduplicate events on an idempotency key. If the sender of the event retries, Restate will not process the event again.
  • Use any of Restate's durable SDK constructs when processing the events: durable calls/messaging to other services, durable timers, scheduling tasks, K/V state, concurrency guarantees etc.
  • Any handler can be a durable webhook endpoint. No need to do anything special or extra!

Just point your webhook endpoint to your handler: restate:8080/MyService/myHandler.

Example

This example processes webhook callbacks from a payment provider.

The payment provider notifies us about payment success or failure of invoices by sending webhook events to our handler. The handler then routes the event to the correct processor via a one-way message.

const webhookCallbackRouter = restate.service({
name : "WebhookCallbackRouter",
handlers: {
// Any handler can be a durable webhook processor that never loses events
// You don't need to do anything special for this.
// Just point your webhook to the handler endpoint: restate:8080/WebhookCallbackRouter/onStripeEvent
onStripeEvent: async (ctx: restate.Context, event: StripeEvent) => {
if (event.type === "invoice.payment_failed") {
ctx.objectSendClient(PaymentTracker, event.data.object.id)
.onPaymentFailed(event);
} else if (event.type === "invoice.payment_succeeded") {
ctx.objectSendClient(PaymentTracker, event.data.object.id)
.onPaymentSuccess(event);
}
}
}
})
restate.endpoint().bind(webhookCallbackRouter).listen(9080);
Example not available in your language?

This pattern is implementable with any of our SDKs. We are still working on translating all patterns to all SDK languages. If you need help with a specific language, please reach out to us via Discord or Slack.