Reference library

Reliability & rate limiting

Retries, exponential backoff, circuit breakers, token buckets, and idempotent handlers.

2 matches
Reliability & rate limiting medium

How to Implement an Adaptive Rate Limiter in Python

Build an adaptive rate limiter that adjusts request intervals dynamically based on recent error rates, slowing down when failures spike.

rate-limiting backoff adaptive
Python
import time
import random

class AdaptiveRateLimiter:
    """Simple adaptive rate limiter that reduces requests when error rate is high."""
    
    def __init__(self, min_interval=0.1, max_interval=2.0, error_threshold=0.3):
        self.min_interval = min_interval
        self.max_interval = max_interval
        sel…
12 0 Open
Reliability & rate limiting easy

How to Mock a Slow Startup Probe in Python

Simulate slow service initialization with a configurable mock delay to test readiness probes.

startup probe mock reliability
Python
import time
from dataclasses import dataclass, field


@dataclass
class StartupProbe:
    name: str
    min_wait_sec: float = 0.5
    max_wait_sec: float = 2.0
    _ready: bool = field(default=False, init=False, repr=False)

    def initialize(self) -> None:
        """Simulate slow startup with a fixed mock delay."""…
13 0 Open

Browse by section

Each section groups closely related Python snippets.

Reliability & rate limiting — Python code examples

What you will find here

This page collects reliability & rate limiting snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.