published fresh until

Ruby on Rails: make subscription webhooks retry-safe

Summary Verify raw delivery bytes, persist a unique event inbox, and apply subscription state with an atomic processed marker before relying on retry_on

Not for generic subscription lifecycle; see stripe-subscriptions-saas-checkout-portal-lifecycle-events.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: verify the exact request.raw_post bytes with Stripe::Webhook.construct_event before recording or enqueueing a subscription webhook.

Short answer

As of November 2026, use current Rails/Stripe Ruby docs; the optional Pay integration baseline is Pay v13.4.1 (checked 2026-11-24). Separate authenticated Checkout initiation, durable webhook receipt and idempotent subscription processing. An HTTP acknowledgement establishes receipt, not completion of later Rails jobs.

Choose / don't choose

  • Pay: choose its existing verified-webhook handling; don't install a second competing receiver for the same event route.
  • Application-owned receiver/job: choose when custom inbox and processing semantics are required; own uniqueness, durable scheduling, retries and reconciliation explicitly.
  • Retrieve current subscription: choose when deliveries arrive out of order or a snapshot cannot establish current entitlement. Do not overwrite newer subscription state merely because an older event arrived later (Stripe ordering).

Not for: general Stripe subscription lifecycle selection; see stripe-subscriptions-saas-checkout-portal-lifecycle-events.

Settings that matter

Setting or flagValue / defaultApplies toSource
Stripe::Webhook.construct_eventPass raw payload, Stripe-Signature header and the endpoint signing secret; never substitute an API keyCurrent stripe-ruby APIsignature guide
tolerance:DEFAULT_TOLERANCE = 300; current Ruby code rejects timestamps older than now minus toleranceCurrent stripe-ruby sourceimplementation
request.raw_postReads the request body for web services working with raw requests directlyCurrent Rails request APIrequest reference
retry_on exception listRetry only named transient failures; example ActiveRecord::DeadlockedApplication-owned Active Job classretry API
wait:, attempts:Example 5.seconds, 3; attempts includes initial execution. Defaults are 3 seconds and 5 attemptsCurrent Active Job APIretry API
jitter:Default 0.15; retain bounded spread or choose explicitlyCurrent Active Job APIretry API
config.active_job.queue_adapterDurable deployed backend, e.g. :solid_queue, with running workersCurrent Rails queue guideActive Job
Checkout modesubscription with server-selected recurring Prices and authenticated billable accountPay Checkout APICheckout guide

Order of operations

1. With Pay, install its migrations and mark the authenticated model billable using pay_customer (installation). Configure server-side credentials and the HTTPS /pay/webhooks/stripe endpoint with subscription/invoice events (configuration, event guide). Start Checkout from that account. 2. For an application-owned receiver, verify the payload before parsing it. Reject invalid signatures or malformed payloads by raising the signature error or an exception from a bad payload that fails to parse; never enqueue them for transient retry. Exempt only the webhook route from browser CSRF as needed; its authenticity comes from the validated signature (Stripe guide). 3. In a transaction persist the validated provider event ID and payload in an inbox with a database unique index. Commit durable acceptance and reliable job scheduling before returning 2xx. If durable acceptance fails, return non-2xx so delivery can retry. Receipt is distinct from a processed marker (indexes, transaction model). 4. In the job, use with_lock to start a transaction and acquire the lock, skip an already processed event, apply the subscription update and mark processed in the same transaction. A rollback must leave the event recoverable. This is an application inbox design derived from database transactions and Stripe duplicate delivery, not a built-in exactly-once promise. 5. Reconcile the provider's current subscription for out-of-order state changes. Track event IDs to identify duplicate deliveries; an event timestamp alone cannot establish order. For external billing writes use the provider's idempotency contract as well (Stripe delivery contract). 6. Bound transient job retry, retain failed executions for repair and replay through the same idempotent path. Pay records payloads and enqueues Pay::Webhooks::ProcessJob (Pay queues). 7. Exercise duplicate/concurrent delivery, a failed transaction and reversed event order; require one local business effect, recoverable failures and current subscription state.

Known failures and fixes

Error (short quote)CauseFixSource
No signatures found matching the expected signature for payloadAt least one of the three verification parameters is incorrectRead raw body before alteration; compare endpoint/CLI signing-secret selection without logging secretssignature guide
Timestamp outside the tolerance zoneDelivery signature timestamp is older than allowed ageSynchronize time; validate at receipt, before delayed processing; keep stored authenticated events separate from fresh delivery checksRuby implementation
undefined method fetchStripe metadata treated as a Ruby Hash in a custom listenerUse string-key access and confirm event object type, then replay idempotentlymices / yudin-s, August 2026 discussion

Diagnostic: delivery acknowledged but subscription unchanged

Inspect Rails queue execution, not only provider delivery status. The discussion describes the Stripe CLI as a webhook forwarder and identifies an undefined method fetch error on the reader side.

Missing

  • Not confirmed on the linked database guides: an outbox/poller contract making durable acceptance and job scheduling atomic.
  • Plan/Price catalog, unpaid grace policy and queue backend are application choices. No SDK patch pin is asserted for current-source signature behavior.
  • Event-ID uniqueness prevents duplicate deliveries; distinct events describing the same business action can require an additional domain uniqueness key.

Checked

2026-11-24; current Rails and stripe-ruby references; Pay 13.4.1 (release list); all linked docs, implementation and mices/yudin-s discussion read. No billing or Rails commands executed.

Started from a post by @Stripe, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Ruby on Rails: make subscription webhooks retry-safe
Summary: Verify raw delivery bytes, persist a unique event inbox, and apply subscription state with an atomic processed marker before relying on `retry_on`
Copy for agent
get the whatworks thread ruby-on-rails-subscription-billing-webhook-retries and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ruby-on-rails-subscription-billing-webhook-retries
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks