timeouts

ruby
require "faraday"
require "faraday/retry"

module Http
  class RetryableError < StandardError; end
  class CircuitOpenError < StandardError; end

HTTP Timeouts + Retries Wrapper (Faraday)

rails http reliability
by codesnips 3 tabs
typescript
export type CircuitState = "closed" | "open" | "half-open";

export interface CircuitBreakerOptions {
  failureThreshold: number;
  resetTimeout: number; // ms to wait in "open" before probing
  onStateChange?: (from: CircuitState, to: CircuitState) => void;

Circuit breaker wrapper for flaky third-party APIs

circuit-breaker resilience http
by codesnips 3 tabs
go
package main

import (
  "context"
  "net/http"
  "time"

HTTP server timeouts that prevent slowloris and stuck connections

go http reliability
by Leah Thompson 1 tab
java
public class ProductAggregator implements AutoCloseable {

    private final RemoteServices services;
    private final ExecutorService pool = Executors.newFixedThreadPool(8);

    public ProductAggregator(RemoteServices services) {

Coordinate Parallel Remote Lookups With CompletableFuture in Java

java completablefuture concurrency
by codesnips 3 tabs
ruby
module BoundedFanOut
  Result = Struct.new(:value, :error) do
    def ok?
      error.nil?
    end
  end

Parallelize Independent External Calls (in a bounded way)

concurrency threads http
by codesnips 3 tabs
go
package httpretry

import (
	"math/rand"
	"time"
)

Exponential Backoff With Full Jitter for Flaky HTTP Calls in Go

go http retry
by codesnips 3 tabs
python
import random
from dataclasses import dataclass
from typing import Iterator


@dataclass(frozen=True)

Retry Flaky HTTP Requests with Exponential Backoff and Full Jitter in Python

python requests retry
by codesnips 3 tabs
ruby
class CircuitBreaker
  class CircuitOpenError < StandardError; end

  def initialize(name, redis: Redis.current, failure_threshold: 5, failure_window: 60, cooldown: 30)
    @key = "circuit:#{name}"
    @redis = redis

Service-Level “Circuit Breaker” (Simple)

rails reliability http
by codesnips 3 tabs