HTTP Timeouts + Retries Wrapper (Faraday)

10051
0

I wrapped external HTTP calls once I realized most “flaky APIs” were actually my fault: no timeouts, unclear retries, and logs that didn’t tell a story. In Client with timeouts, I centralize a Faraday connection with explicit open_timeout and timeout, plus a bounded retry policy that only retries the exceptions I can plausibly recover from. I also use f.response :raise_error so failures don’t get silently ignored. The part I lean on the most is with_timing, which measures elapsed time with Process::CLOCK_MONOTONIC and logs structured JSON including method, path, and Current.request_id. That makes it trivial to correlate a slow request to a specific outbound call, and it keeps the retry behavior consistent across the app.