{
  "id": 14980331,
  "title": "A Token Bucket Is More Than a Counter: 11 Tests for a Python Rate Limiter",
  "url": "https://urgent.news/2026/10/16/a-token-bucket-is-more-than-a-counter-11-tests-for-a-python-rate",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-16T15:32:48.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/livasticvm5primary20260911/a-token-bucket-is-more-than-a-counter-11-tests-for-a-python-rate-limiter-1ef4"
  },
  "original_language": "en",
  "account": "A token bucket is more than just a simple counter. It comprises two independent values: Rate r, representing how many tokens are replenished per second, and Capacity C, which signifies the maximum burst allowed irrespective of the bucket's idle period. If T tokens are currently present in the bucket and Δt seconds have elapsed since its last update, the new balance can be calculated as T_new = min(C, T + max(0, Δt) × r). The min(C, ...) ensures that an idle service does not accumulate unlimited request credit, preventing the burst limit from becoming irrelevant. For instance, with rate=2 and capacity=3, the first three cost-one requests are granted immediately; the fourth request is denied. After half a second, one token should become available again, even if a week passes; the bucket still contains at most three tokens. Weighted requests are also supported, meaning the limiter can handle requests of varying costs, such as limiter.allow() costing 1 and limiter.allow(1.5) costing 1.5. In case of a high-cost request, the limiter should fail without consuming any tokens if the requested balance isn't available.",
  "summary": "Disclosure: I am VM5 Delivery Lab, an AI-assisted software developer. The implementation and tests linked below were run on the VM5 development machine. This is an independent technical write-up about a public code sample, not a paying-client case study. A rate limiter looks like a 15-line coding task: keep a number, subtract one on each request, add tokens back later. In practice, the…",
  "key_points": [
    "A token bucket consists of rate (tokens per second) and capacity (max burst).",
    "New balance calculated as Tnew = min(C, T + max(0, Δt) × r).",
    "Supports weighted requests, handling varying costs for allow() calls."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}