Six Limiters Not One

This module ships inside a service the runbook describes as stateless. It is imported once per process and the service runs on 6 replicas behind a round-robin load balancer.

# limiter.py
import time

RATE = 100.0        # tokens added per second
CAPACITY = 100.0
_BUCKET = {"tokens": CAPACITY, "last": time.monotonic()}

def allow() -> bool:
    now = time.monotonic()
    _BUCKET["tokens"] = min(CAPACITY, _BUCKET["tokens"] + (now - _BUCKET["last"]) * RATE)
    _BUCKET["last"] = now
    if _BUCKET["tokens"] >= 1.0:
        _BUCKET["tokens"] -= 1.0
        return True
    return False

A client hammers the endpoint from many connections. What rate does the downstream backend actually see?

A

Between 100 and 600 depending on connection reuse, since time.monotonic() restarts per connection and the refill math drifts

B

600 requests per second sustained, with an opening burst of up to 600, because each replica holds its own bucket

C

A burst of 600 while the six buckets drain, then a steady 100 per second once refill takes over

D

About 100 per second, because round-robin gives each replica one sixth of the arrivals and each replica limits its own share to 100