The project is in a healthy, maintained state
Provide idempotency keys with conflict detection and response replay.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 1.17
>= 13.0
~> 3.12
~> 0.22

Runtime

>= 2.2
 Project Readme

Rack Idempotency Kit

Gem Version Gem Downloads Ruby CI GitHub Release Rails Elysium Arc

Stripe-style idempotency for Rack and Rails APIs.

About

Rack Idempotency Kit ensures that repeated requests with the same idempotency key replay the original response instead of executing the action twice. It protects against retries, network timeouts, and client-side duplications.

The middleware stores a fingerprint of the request and a completed response. If the same key is used with different request parameters, it returns a conflict.

Use Cases

  • Payment, checkout, and webhook endpoints with retries
  • API clients with timeouts and automatic replays
  • Protecting side-effecting endpoints from duplicate writes
  • Reducing p99 spikes caused by retry storms

Compatibility

  • Ruby 3.0+
  • Rack 2.2+
  • Works with Rails middleware stack

Elysium Arc Reliability Toolkit

Also check out these related gems:

Installation

# Gemfile

gem "rack-idempotency-kit"

Usage (Rails)

# config/application.rb
config.middleware.use Rack::Idempotency::Kit,
  store: Rails.cache,
  ttl: 86_400,
  header: "Idempotency-Key"

Usage (Rack)

use Rack::Idempotency::Kit,
  store: MyStore.new,
  ttl: 86_400,
  header: "Idempotency-Key"

Options

  • store storage backend
  • ttl (Integer) response retention in seconds
  • header (String) idempotency header name
  • methods (Array) HTTP methods to protect
  • wait_timeout (Float) wait time for in-flight requests
  • lock_ttl (Integer) in-flight lock TTL in seconds
  • max_body_bytes (Integer) maximum body size to store

Store Backends

  • ActiveSupport cache stores (read/write)
  • Redis-style stores (get/set)

Behavior

  • Replays stored responses for repeated idempotency keys
  • Returns 409 if the same key is reused with a different request fingerprint
  • Returns 409 if a request is still in flight after wait_timeout

Release

bundle exec rake release