0.0
The project is in a healthy, maintained state
Issue a backup request after a delay and return the first response.
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

>= 1.0
 Project Readme

Faraday Hedge

Gem Version Gem Downloads Ruby CI GitHub Release Rails Elysium Arc

Hedged requests middleware for Faraday to reduce tail latency on idempotent methods.

About

Faraday Hedge issues a backup request after a small delay and returns the first response. This reduces tail latency when occasional slow requests occur, while keeping overall load bounded.

The middleware defaults to idempotent methods and can be configured to hedge only specific HTTP verbs.

Use Cases

  • Reduce p99 latency for flaky upstream APIs
  • Protect against tail latency spikes on critical read paths
  • Improve UX for latency-sensitive services

Compatibility

  • Ruby 3.0+
  • Faraday 1.0+

Elysium Arc Reliability Toolkit

Also check out these related gems:

Installation

# Gemfile

gem "faraday-hedge"

Usage

conn = Faraday.new do |f|
  f.request :hedge, delay: 0.05
  f.adapter :net_http
end

Options

  • delay (Float) seconds before firing a backup request
  • max_hedges (Integer) number of backup requests to allow
  • methods (Array) methods eligible for hedging
  • idempotent_only (Boolean) restrict hedging to idempotent methods

Notes

  • Hedging uses background threads.
  • Use conservative delays to avoid excessive duplicate work.

Release

bundle exec rake release