Urgent.News

What's breaking now, across thousands of outlets.

Tech

A Token Bucket Is More Than a Counter: 11 Tests for a Python Rate Limiter

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…

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.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Build in Public Without Breaking Trust: Write the Migration Note First

Before announcing a breaking product change in public, write and rehearse the migration note. Explain who is affected, what stops working, how to move to the new behavior, and what to do if the move…

  • Draft migration guide before publicizing significant product change
  • Outline impacted users, discontinued functionality, transition steps, and troubleshooting
  • Identify dependent behavior by examining current workflow, not implementation differences

I just saved 25 hours a month…

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 2: Side Hustle I just saved 25 hours a month — and a $20/mo ChatGPT subscription — by pointing a 3.4 GB open-source model at my…

  • Small shop owner saves 25 hours a month using open-source model
  • Gemma 3 (4B) model runs on local laptop via Ollama
  • Listing Copilot generates titles, descriptions, and tags without paid services

GitHub Classroom has closed: what you still have, and how to run next term

Disclosure: I work on Uppcoder , one of the options listed at the end. The rest is about GitHub Classroom itself and applies whatever you choose. GitHub retired GitHub Classroom on 28 August 2026.

  • GitHub Classroom retired on 28 August 2026
  • Educators can access created repositories, but some data deleted
  • Options: Classroom 50, Codio, Uppcoder for next term

More from Friday 16 October →