{"id":41679,"date":"2026-12-03T06:00:04","date_gmt":"2026-12-03T06:00:04","guid":{"rendered":"https:\/\/www.railscarma.com\/?p=41679"},"modified":"2026-12-03T06:00:15","modified_gmt":"2026-12-03T06:00:15","slug":"rails-api-integration-retries-webhooks","status":"publish","type":"post","link":"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/rails-api-integration-retries-webhooks\/","title":{"rendered":"Reliable Third-Party API Integrations in Rails: Handling Retries, Webhooks and Failures"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"41679\" class=\"elementor elementor-41679\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-25106a7 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"25106a7\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e004434\" data-id=\"e004434\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-fe4f497 elementor-widget__width-initial elementor-widget elementor-widget-text-editor\" data-id=\"fe4f497\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">Sidekiq&#8217;s documentation says it plainly: Sidekiq <\/span><a href=\"https:\/\/github.com\/sidekiq\/sidekiq\/wiki\/Best-Practices\"><span style=\"font-weight: 400;\">will execute your job at least once, not exactly once<\/span><\/a><span style=\"font-weight: 400;\">. Every Ruby on Rails API integration that runs through a background queue inherits that rule, and most integration bugs are what happens when the code assumes the opposite.<\/span><\/p><p><span style=\"font-weight: 400;\">This guide follows one invented scenario from the first API call to the first outage, and shows where each decision about retries, duplicates and webhooks comes from. The framework details refer to the Rails 8.1 documentation.<\/span><\/p><h2><b>The scenario: a subscription product with a payment provider and a courier<\/b><\/h2><p><span style=\"font-weight: 400;\">This is a made-up example, used for illustration only. A SaaS company bills customers through a payment provider and ships hardware kits through a courier&#8217;s API. A customer upgrades their plan. The app has to charge the card, mark the subscription as active and book a shipment.<\/span><\/p><p><span style=\"font-weight: 400;\">The first version makes all three calls inside the controller action. It works for months. Then the courier&#8217;s API starts answering in twelve seconds instead of one, the web workers fill up waiting, and the whole product slows down because of a supplier&#8217;s problem.<\/span><\/p><h2><b>Outbound calls belong in a job, with their own timeouts<\/b><\/h2><p><span style=\"font-weight: 400;\">A request that waits on someone else&#8217;s server is borrowing that server&#8217;s reliability. Move the call into a background job so the user gets a response straight away and the slow dependency can only hold up a queue, not the site. Set explicit open and read timeouts in whichever HTTP client you use, so a stalled connection fails in seconds rather than waiting on the default.<\/span><\/p><p><span style=\"font-weight: 400;\">One caution on timing. If the job is enqueued inside a database transaction, it can start before the transaction commits and look for a record that isn&#8217;t there yet. Rails 8.1 has <\/span><a href=\"https:\/\/guides.rubyonrails.org\/active_job_basics.html\"><span style=\"font-weight: 400;\">enqueue_after_transaction_commit<\/span><\/a><span style=\"font-weight: 400;\">, which defers enqueuing until the surrounding transaction has committed.<\/span><\/p><h2><b>Retry only the failures that time can fix<\/b><\/h2><p><span style=\"font-weight: 400;\">Active Job doesn&#8217;t retry on its own. The <\/span><a href=\"https:\/\/guides.rubyonrails.org\/active_job_basics.html\"><span style=\"font-weight: 400;\">Active Job guide<\/span><\/a><span style=\"font-weight: 400;\"> says retries must be configured explicitly with retry_on, and a job that raises without it counts as failed. The <\/span><a href=\"https:\/\/api.rubyonrails.org\/classes\/ActiveJob\/Exceptions\/ClassMethods.html\"><span style=\"font-weight: 400;\">API documentation<\/span><\/a><span style=\"font-weight: 400;\"> gives the defaults: a 3 second wait and 5 attempts, where the count includes the original run. The polynomially_longer option stretches the gaps to roughly 3, 18 and 83 seconds, and jitter adds a random spread of 15 percent by default.<\/span><\/p><p><span style=\"font-weight: 400;\">A courier timeout deserves a retry. A 422 saying the postcode is invalid doesn&#8217;t, because the thousandth attempt will fail the same way as the first. Retry network errors, timeouts and 5xx responses. Discard, or route to a person, anything the provider rejected on its merits. Here is the shape in code, written for Rails 8.1 and not executed against a live provider:<\/span><\/p><p><span style=\"font-weight: 400;\">class BookShipmentJob &lt; ApplicationJob<\/span><span style=\"font-weight: 400;\"><br \/><\/span><span style=\"font-weight: 400;\">\u00a0 retry_on Net::OpenTimeout, Net::ReadTimeout,<\/span><span style=\"font-weight: 400;\"><br \/><\/span><span style=\"font-weight: 400;\"> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 wait: :polynomially_longer, attempts: 6, report: true<\/span><span style=\"font-weight: 400;\"><br \/><\/span><span style=\"font-weight: 400;\">\u00a0 discard_on ActiveJob::DeserializationError<\/span><span style=\"font-weight: 400;\"><br \/><\/span><span style=\"font-weight: 400;\"><br \/><\/span><span style=\"font-weight: 400;\">\u00a0 def perform(shipment_id)<\/span><span style=\"font-weight: 400;\"><br \/><\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 # call the courier, store its reference<\/span><span style=\"font-weight: 400;\"><br \/><\/span><span style=\"font-weight: 400;\">\u00a0 \u7d42\u308f\u308a<\/span><span style=\"font-weight: 400;\"><br \/><\/span><span style=\"font-weight: 400;\">\u7d42\u308f\u308a<\/span><\/p><p><span style=\"font-weight: 400;\">The report option sends each failure to Rails.error before the retry, which gives your error tracker a record while the job is still trying. When attempts run out, the documentation says the exception bubbles up to the underlying queue system unless you pass a block to handle it. If your queue is Sidekiq, remember that it has its own retry policy: 25 retries over roughly 20 days by default, per the <\/span><a href=\"https:\/\/github.com\/sidekiq\/sidekiq\/wiki\/Error-Handling\"><span style=\"font-weight: 400;\">Sidekiq error handling page<\/span><\/a><span style=\"font-weight: 400;\">. Check which layer is retrying, because running both can turn one failed booking into a long tail of surprise attempts.<\/span><\/p><h2><b>A retry that creates a second charge is worse than the outage<\/b><\/h2><p><span style=\"font-weight: 400;\">Back in the scenario, the payment call times out. Did the provider charge the card or not? The job can&#8217;t know, and retrying blindly may bill the customer twice.<\/span><\/p><p><span style=\"font-weight: 400;\">The fix is an idempotency key. For Stripe, you send an <\/span><a href=\"https:\/\/docs.stripe.com\/api\/idempotent_requests\"><span style=\"font-weight: 400;\">Idempotency-Key header<\/span><\/a><span style=\"font-weight: 400;\"> of up to 255 characters, and a retry with the same key returns the saved result instead of repeating the operation. Generate the key once, store it on your own record before the first attempt, and reuse it on every retry. A new random key per attempt defeats the purpose.<\/span><\/p><p><span style=\"font-weight: 400;\">Not every provider offers this. When one doesn&#8217;t, store the provider&#8217;s reference as soon as you get it, and make the job check for that reference before it calls again. The courier job above should start by asking: do I already hold a tracking number for this shipment?<\/span><\/p><h2><b>Webhooks arrive late, twice and out of order<\/b><\/h2><p><span style=\"font-weight: 400;\">The payment provider confirms the charge through a webhook, and this is where assumptions break. Stripe&#8217;s <\/span><a href=\"https:\/\/docs.stripe.com\/webhooks\"><span style=\"font-weight: 400;\">webhook documentation<\/span><\/a><span style=\"font-weight: 400;\"> states that endpoints might receive the same event more than once, that delivery order isn&#8217;t guaranteed, and that failed deliveries are retried for up to three days with exponential backoff in live mode.<\/span><\/p><p><span style=\"font-weight: 400;\">That shapes the endpoint. Verify the signature against the raw request body, because any change to the body makes verification fail, and reject events whose timestamp falls outside the tolerance window. Return a 2xx status quickly, then hand the real work to a job. Record each event ID in a table with a unique index, and skip any event you&#8217;ve already processed. Don&#8217;t use the event&#8217;s created time to decide which event is newer, since the documentation warns against it. Fetch the current object from the API when order matters.<\/span><\/p><p><span style=\"font-weight: 400;\">Rails needs one more step: a webhook endpoint can&#8217;t carry a CSRF token, so it must be excluded from forgery protection. Stripe&#8217;s own Rails example does this with protect_from_forgery except: :webhook, and the signature check takes over the job of proving the request is genuine.<\/span><\/p><h2><b>Someone has to find out when retries run out<\/b><\/h2><p><span style=\"font-weight: 400;\">Return to the courier outage. Six attempts fail, the job gives up, and the customer&#8217;s kit is never booked. Without an alert, the first sign is a support email a week later.<\/span><\/p><p><span style=\"font-weight: 400;\">Decide in advance what happens at the end of the retry path. Sidekiq moves exhausted jobs to a Dead set, with hooks such as sidekiq_retries_exhausted for custom handling. In Active Job, the block form of retry_on lets you mark the shipment as needing attention and notify a person. Either way, the record should show a clear state, such as &#8220;courier booking failed&#8221;, so a support agent or an admin screen can retry it by hand once the provider recovers.<\/span><\/p><p><span style=\"font-weight: 400;\">Also decide what the customer sees while the supplier is down. &#8220;Your kit is on its way, we&#8217;ll send tracking shortly&#8221; is accurate, and it keeps the upgrade itself from failing for a reason the customer can&#8217;t control.<\/span><\/p><h2><b>What the finished design looks like<\/b><\/h2><p><span style=\"font-weight: 400;\">Put together, the upgrade now commits the subscription change and returns immediately. A payment job uses a stored idempotency key. A shipment job checks for an existing tracking number, retries timeouts and server errors with growing gaps, and reports each failure. A webhook endpoint verifies, records the event ID, returns 200 and queues the processing. An alert fires when a shipment job runs out of attempts, and the record shows its state.<\/span><\/p><p><span style=\"font-weight: 400;\">None of this needs a new gem or a service rewrite. It needs each integration to answer the same five questions: what happens on a timeout, a duplicate, an out-of-order event, an exhausted retry and a rejected request.<\/span><\/p><h2><b>Where an outside review helps<\/b><\/h2><p><span style=\"font-weight: 400;\">Integrations tend to be written one at a time, by different people, and nobody owns the pattern across them. If your application has grown that way, a review of the retry, idempotency and alerting setup is a contained piece of work. RailsCarma offers <\/span><a href=\"https:\/\/www.railscarma.com\/ja\/ruby-on-rails%e3%82%b3%e3%83%b3%e3%82%b5%e3%83%ab%e3%83%86%e3%82%a3%e3%83%b3%e3%82%b0\/\"><span style=\"font-weight: 400;\">Ruby on Rails\u30b3\u30f3\u30b5\u30eb\u30c6\u30a3\u30f3\u30b0<\/span><\/a><span style=\"font-weight: 400;\">, lists <\/span><a href=\"https:\/\/www.railscarma.com\/ja\/api%e9%a7%86%e5%8b%95%e9%96%8b%e7%99%ba%e3%81%a8%e3%83%9e%e3%83%83%e3%82%b7%e3%83%a5%e3%82%a2%e3%83%83%e3%83%97\/\"><span style=\"font-weight: 400;\">API-driven development<\/span><\/a><span style=\"font-weight: 400;\"> among its services, and provides <\/span><a href=\"https:\/\/www.railscarma.com\/ja\/%e3%82%a2%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%81%ae%e3%82%b5%e3%83%9d%e3%83%bc%e3%83%88%e3%81%a8%e3%83%a1%e3%83%b3%e3%83%86%e3%83%8a%e3%83%b3%e3%82%b9\/\"><span style=\"font-weight: 400;\">\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30b5\u30dd\u30fc\u30c8\u3068\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9<\/span><\/a><span style=\"font-weight: 400;\"> for keeping integrations monitored after the fixes ship.<\/span><\/p><h2><b>Decide the failure path before the success path<\/b><\/h2><p><span style=\"font-weight: 400;\">Any developer can make an API call work on a good day. The integration is finished when you can say what happens to the customer, the record and the on-call engineer on a bad one.<\/span><\/p><p><a href=\"https:\/\/www.railscarma.com\/ja\/ruby-on-rails%e3%82%b3%e3%83%b3%e3%82%b5%e3%83%ab%e3%83%86%e3%82%a3%e3%83%b3%e3%82%b0\/\"><span style=\"font-weight: 400;\">Speak with RailsCarma&#8217;s team to review how your Rails application handles failed API calls and duplicate webhooks.<\/span><\/a><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t  <div class=\"related-post slider\">\r\n        <div class=\"headline\">\u95a2\u9023\u8a18\u4e8b<\/div>\r\n    <div class=\"post-list owl-carousel\">\r\n\r\n            <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Reliable Third-Party API Integrations in Rails: Handling Retries, Webhooks and Failures\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/rails-api-integration-retries-webhooks\/?related_post_from=41679\">\r\n\r\n      <img decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png\" class=\"attachment-full size-full wp-post-image\" alt=\"Ruby on Rails API Integration\" srcset=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png 800w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration-300x113.png 300w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration-768x288.png 768w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration-18x7.png 18w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Reliable Third-Party API Integrations in Rails: Handling Retries, Webhooks and Failures\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/rails-api-integration-retries-webhooks\/?related_post_from=41679\">\r\n        Reliable Third-Party API Integrations in Rails: Handling Retries, Webhooks and Failures  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Slow Rails Applications: How to Separate Database, Background Job and Infrastructure Problems\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/ruby-on-rails-performance-optimization-diagnosis\/?related_post_from=41669\">\r\n\r\n      <img decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Performance-Optimization.png\" class=\"attachment-full size-full wp-post-image\" alt=\"Ruby on Rails Performance Optimization\" srcset=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Performance-Optimization.png 800w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Performance-Optimization-300x113.png 300w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Performance-Optimization-768x288.png 768w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Performance-Optimization-18x7.png 18w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Slow Rails Applications: How to Separate Database, Background Job and Infrastructure Problems\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/ruby-on-rails-performance-optimization-diagnosis\/?related_post_from=41669\">\r\n        Slow Rails Applications: How to Separate Database, Background Job and Infrastructure Problems  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"What Does a Rails Upgrade Cost? Dependencies, Test Coverage and Deployment Risk\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/ruby-on-rails-upgrade-cost\/?related_post_from=41657\">\r\n\r\n      <img decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Upgrade-Cost.png\" class=\"attachment-full size-full wp-post-image\" alt=\"What Does a Rails Upgrade Cost? Dependencies, Test Coverage and Deployment Risk\" srcset=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Upgrade-Cost.png 800w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Upgrade-Cost-300x113.png 300w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Upgrade-Cost-768x288.png 768w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Ruby-on-Rails-Upgrade-Cost-18x7.png 18w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"What Does a Rails Upgrade Cost? Dependencies, Test Coverage and Deployment Risk\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/ruby-on-rails-upgrade-cost\/?related_post_from=41657\">\r\n        What Does a Rails Upgrade Cost? Dependencies, Test Coverage and Deployment Risk  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Rails Upgrade Testing: How to Reduce Release Risk When Test Coverage Is Limited\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/rails-upgrade-testing-limited-test-coverage\/?related_post_from=41651\">\r\n\r\n      <img decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Rails-Upgrade-Testing.png\" class=\"attachment-full size-full wp-post-image\" alt=\"Rails Upgrade Testing\" srcset=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Rails-Upgrade-Testing.png 800w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Rails-Upgrade-Testing-300x113.png 300w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Rails-Upgrade-Testing-768x288.png 768w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/11\/Rails-Upgrade-Testing-18x7.png 18w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Rails Upgrade Testing: How to Reduce Release Risk When Test Coverage Is Limited\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/rails-upgrade-testing-limited-test-coverage\/?related_post_from=41651\">\r\n        Rails Upgrade Testing: How to Reduce Release Risk When Test Coverage Is Limited  <\/a>\r\n\r\n        <\/div>\r\n      \r\n  <\/div>\r\n\r\n  <script>\r\n      <\/script>\r\n  <style>\r\n    .related-post {}\r\n\r\n    .related-post .post-list {\r\n      text-align: left;\r\n          }\r\n\r\n    .related-post .post-list .item {\r\n      margin: 10px;\r\n      padding: 10px;\r\n          }\r\n\r\n    .related-post .headline {\r\n      font-size: 14px !important;\r\n      color: #999999 !important;\r\n          }\r\n\r\n    .related-post .post-list .item .post_thumb {\r\n      max-height: 220px;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n          }\r\n\r\n    .related-post .post-list .item .post_title {\r\n      font-size: 14px;\r\n      color: #000000;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .post-list .item .post_excerpt {\r\n      font-size: 12px;\r\n      color: #3f3f3f;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .owl-dots .owl-dot {\r\n          }\r\n\r\n      <\/style>\r\n      <script>\r\n      jQuery(document).ready(function($) {\r\n        $(\".related-post .post-list\").owlCarousel({\r\n          items: 2,\r\n          responsiveClass: true,\r\n          responsive: {\r\n            0: {\r\n              items: 1,\r\n            },\r\n            768: {\r\n              items: 2,\r\n            },\r\n            1200: {\r\n              items: 2,\r\n            }\r\n          },\r\n                      rewind: true,\r\n                                loop: true,\r\n                                center: false,\r\n                                autoplay: true,\r\n            autoplayHoverPause: true,\r\n                                nav: true,\r\n            navSpeed: 1000,\r\n            navText: ['<i class=\"fas fa-chevron-left\"><\/i>', '<i class=\"fas fa-chevron-right\"><\/i>'],\r\n                                dots: false,\r\n            dotsSpeed: 1200,\r\n                                                    rtl: false,\r\n          \r\n        });\r\n      });\r\n    <\/script>\r\n  <\/div>","protected":false},"excerpt":{"rendered":"<p>Sidekiq&#8217;s documentation says it plainly: Sidekiq will execute your job at least once, not exactly once. Every Ruby on Rails API integration that runs through a background queue inherits that rule, and most integration bugs are what happens when the code assumes the opposite. This guide follows one invented scenario from the first API call to the first outage, and shows where each decision about retries, duplicates and webhooks comes from. The framework details refer to the Rails 8.1 documentation. The scenario: a subscription product with a payment provider and a courier This is a made-up example, used for illustration only. A SaaS company bills customers through a payment provider &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.railscarma.com\/ja\/%e3%83%96%e3%83%ad%e3%82%b0\/rails-upgrade-testing-limited-test-coverage\/\"> <span class=\"screen-reader-text\">Rails Upgrade Testing: How to Reduce Release Risk When Test Coverage Is Limited<\/span> \u3082\u3063\u3068\u8aad\u3080 \"<\/a><\/p>","protected":false},"author":11,"featured_media":41684,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1224],"tags":[],"class_list":["post-41679","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Ruby on Rails API Integration: Retries and Webhooks<\/title>\n<meta name=\"description\" content=\"How to build reliable third-party API integrations in Rails: retry rules, idempotency, webhook handling and alerting, with a worked scenario.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.railscarma.com\/ja\/\u30d6\u30ed\u30b0\/rails-api-integration-retries-webhooks\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ruby on Rails API Integration: Retries and Webhooks\" \/>\n<meta property=\"og:description\" content=\"How to build reliable third-party API integrations in Rails: retry rules, idempotency, webhook handling and alerting, with a worked scenario.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.railscarma.com\/ja\/\u30d6\u30ed\u30b0\/rails-api-integration-retries-webhooks\/\" \/>\n<meta property=\"og:site_name\" content=\"RailsCarma - Ruby on Rails Development Company specializing in Offshore Development\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/RailsCarma\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-12-03T06:00:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-12-03T06:00:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"ashish\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@railscarma\" \/>\n<meta name=\"twitter:site\" content=\"@railscarma\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"ashish\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"6\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/\"},\"author\":{\"name\":\"ashish\",\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/person\/9699b14852b308edfeb03096b33c7a7a\"},\"headline\":\"Reliable Third-Party API Integrations in Rails: Handling Retries, Webhooks and Failures\",\"datePublished\":\"2026-12-03T06:00:04+00:00\",\"dateModified\":\"2026-12-03T06:00:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/\"},\"wordCount\":1354,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.railscarma.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png\",\"articleSection\":[\"Blogs\"],\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/\",\"url\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/\",\"name\":\"Ruby on Rails API Integration: Retries and Webhooks\",\"isPartOf\":{\"@id\":\"https:\/\/www.railscarma.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png\",\"datePublished\":\"2026-12-03T06:00:04+00:00\",\"dateModified\":\"2026-12-03T06:00:15+00:00\",\"description\":\"How to build reliable third-party API integrations in Rails: retry rules, idempotency, webhook handling and alerting, with a worked scenario.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#primaryimage\",\"url\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png\",\"contentUrl\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png\",\"width\":800,\"height\":300,\"caption\":\"Ruby on Rails API Integration\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.railscarma.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reliable Third-Party API Integrations in Rails: Handling Retries, Webhooks and Failures\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.railscarma.com\/#website\",\"url\":\"https:\/\/www.railscarma.com\/\",\"name\":\"RailsCarma - Ruby on Rails Development Company specializing in Offshore Development\",\"description\":\"RailsCarma is a Ruby on Rails Development Company in Bangalore. We specialize in Offshore Ruby on Rails Development based out in USA and India. Hire experienced Ruby on Rails developers for the ultimate Web Experience.\",\"publisher\":{\"@id\":\"https:\/\/www.railscarma.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.railscarma.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ja\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.railscarma.com\/#organization\",\"name\":\"RailsCarma\",\"url\":\"https:\/\/www.railscarma.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2020\/08\/railscarma_logo.png\",\"contentUrl\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2020\/08\/railscarma_logo.png\",\"width\":200,\"height\":46,\"caption\":\"RailsCarma\"},\"image\":{\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/RailsCarma\/\",\"https:\/\/x.com\/railscarma\",\"https:\/\/www.linkedin.com\/company\/railscarma\/\",\"https:\/\/myspace.com\/railscarma\",\"https:\/\/in.pinterest.com\/railscarma\/\",\"https:\/\/www.youtube.com\/channel\/UCx3Wil-aAnDARuatTEyMdpg\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/person\/9699b14852b308edfeb03096b33c7a7a\",\"name\":\"ashish\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/204411c7d72714bc32d5ac6398e0596896318386bd537860fdd14ce905a79e07?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/204411c7d72714bc32d5ac6398e0596896318386bd537860fdd14ce905a79e07?s=96&d=mm&r=g\",\"caption\":\"ashish\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ruby on Rails API Integration: Retries and Webhooks","description":"How to build reliable third-party API integrations in Rails: retry rules, idempotency, webhook handling and alerting, with a worked scenario.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.railscarma.com\/ja\/\u30d6\u30ed\u30b0\/rails-api-integration-retries-webhooks\/","og_locale":"ja_JP","og_type":"article","og_title":"Ruby on Rails API Integration: Retries and Webhooks","og_description":"How to build reliable third-party API integrations in Rails: retry rules, idempotency, webhook handling and alerting, with a worked scenario.","og_url":"https:\/\/www.railscarma.com\/ja\/\u30d6\u30ed\u30b0\/rails-api-integration-retries-webhooks\/","og_site_name":"RailsCarma - Ruby on Rails Development Company specializing in Offshore Development","article_publisher":"https:\/\/www.facebook.com\/RailsCarma\/","article_published_time":"2026-12-03T06:00:04+00:00","article_modified_time":"2026-12-03T06:00:15+00:00","og_image":[{"width":800,"height":300,"url":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png","type":"image\/png"}],"author":"ashish","twitter_card":"summary_large_image","twitter_creator":"@railscarma","twitter_site":"@railscarma","twitter_misc":{"\u57f7\u7b46\u8005":"ashish","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"6\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#article","isPartOf":{"@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/"},"author":{"name":"ashish","@id":"https:\/\/www.railscarma.com\/#\/schema\/person\/9699b14852b308edfeb03096b33c7a7a"},"headline":"Reliable Third-Party API Integrations in Rails: Handling Retries, Webhooks and Failures","datePublished":"2026-12-03T06:00:04+00:00","dateModified":"2026-12-03T06:00:15+00:00","mainEntityOfPage":{"@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/"},"wordCount":1354,"commentCount":0,"publisher":{"@id":"https:\/\/www.railscarma.com\/#organization"},"image":{"@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#primaryimage"},"thumbnailUrl":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png","articleSection":["Blogs"],"inLanguage":"ja","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/","url":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/","name":"Ruby on Rails API Integration: Retries and Webhooks","isPartOf":{"@id":"https:\/\/www.railscarma.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#primaryimage"},"image":{"@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#primaryimage"},"thumbnailUrl":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png","datePublished":"2026-12-03T06:00:04+00:00","dateModified":"2026-12-03T06:00:15+00:00","description":"How to build reliable third-party API integrations in Rails: retry rules, idempotency, webhook handling and alerting, with a worked scenario.","breadcrumb":{"@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/"]}]},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#primaryimage","url":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png","contentUrl":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/12\/Ruby-on-Rails-API-Integration.png","width":800,"height":300,"caption":"Ruby on Rails API Integration"},{"@type":"BreadcrumbList","@id":"https:\/\/www.railscarma.com\/blog\/rails-api-integration-retries-webhooks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.railscarma.com\/"},{"@type":"ListItem","position":2,"name":"Reliable Third-Party API Integrations in Rails: Handling Retries, Webhooks and Failures"}]},{"@type":"WebSite","@id":"https:\/\/www.railscarma.com\/#website","url":"https:\/\/www.railscarma.com\/","name":"RailsCarma - \u30aa\u30d5\u30b7\u30e7\u30a2\u958b\u767a\u306b\u7279\u5316\u3057\u305f Ruby on Rails \u958b\u767a\u4f1a\u793e","description":"RailsCarma \u306f\u30d0\u30f3\u30ac\u30ed\u30fc\u30eb\u306e Ruby on Rails \u958b\u767a\u4f1a\u793e\u3067\u3059\u3002\u5f53\u793e\u306f\u7c73\u56fd\u3068\u30a4\u30f3\u30c9\u3092\u62e0\u70b9\u3068\u3059\u308b\u30aa\u30d5\u30b7\u30e7\u30a2 Ruby on Rails \u958b\u767a\u3092\u5c02\u9580\u3068\u3057\u3066\u3044\u307e\u3059\u3002\u7d4c\u9a13\u8c4a\u5bcc\u306a Ruby on Rails \u958b\u767a\u8005\u3092\u96c7\u3063\u3066\u3001\u7a76\u6975\u306e Web \u30a8\u30af\u30b9\u30da\u30ea\u30a8\u30f3\u30b9\u3092\u5b9f\u73fe\u3057\u307e\u3057\u3087\u3046\u3002","publisher":{"@id":"https:\/\/www.railscarma.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.railscarma.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ja"},{"@type":"Organization","@id":"https:\/\/www.railscarma.com\/#organization","name":"\u30ec\u30fc\u30eb\u30ab\u30fc\u30de","url":"https:\/\/www.railscarma.com\/","logo":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.railscarma.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2020\/08\/railscarma_logo.png","contentUrl":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2020\/08\/railscarma_logo.png","width":200,"height":46,"caption":"RailsCarma"},"image":{"@id":"https:\/\/www.railscarma.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/RailsCarma\/","https:\/\/x.com\/railscarma","https:\/\/www.linkedin.com\/company\/railscarma\/","https:\/\/myspace.com\/railscarma","https:\/\/in.pinterest.com\/railscarma\/","https:\/\/www.youtube.com\/channel\/UCx3Wil-aAnDARuatTEyMdpg"]},{"@type":"Person","@id":"https:\/\/www.railscarma.com\/#\/schema\/person\/9699b14852b308edfeb03096b33c7a7a","name":"\u30a2\u30b7\u30b7","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.railscarma.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/204411c7d72714bc32d5ac6398e0596896318386bd537860fdd14ce905a79e07?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/204411c7d72714bc32d5ac6398e0596896318386bd537860fdd14ce905a79e07?s=96&d=mm&r=g","caption":"ashish"}}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/posts\/41679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/comments?post=41679"}],"version-history":[{"count":4,"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/posts\/41679\/revisions"}],"predecessor-version":[{"id":41683,"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/posts\/41679\/revisions\/41683"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/media\/41684"}],"wp:attachment":[{"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/media?parent=41679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/categories?post=41679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.railscarma.com\/ja\/wp-json\/wp\/v2\/tags?post=41679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}