Reference library

Reliability & rate limiting

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

2 matches
Reliability & rate limiting medium

How to Cap Retry Attempts in Python with a Decorator

Build a reusable retry decorator that caps attempts, adds delays, and lets flaky services fail fast instead of hanging.

retry decorator resilience
Python
import random
from functools import wraps
from time import sleep


def retry(max_attempts, delay=0.1):
    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            attempts = 0
            while attempts < max_attempts:
                try:
                    return func(*args, **kw…
13 0 Open
Reliability & rate limiting medium

Saga Compensating Transaction Mock in Python

Simulates a distributed transaction using a saga pattern with compensating actions that roll back steps on failure.

saga transaction compensation
Python
import random
import time


class OrderService:
    def __init__(self):
        self.orders = {}

    def create_order(self, order_id):
        print(f"[Order] Creating order {order_id}...")
        time.sleep(0.1)
        if random.random() < 0.3:  # 30% chance of failure
            raise RuntimeError(f"Order {order…
12 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.