How RateLimiter and TokenBucket work together
mainThe library provides two main classes for rate limiting:
TokenBucket: A lower-level interface that uses a configurable burst rate and drip rate. It is useful for scenarios like byte-level throttling.RateLimiter: A higher-level abstraction built on top ofTokenBucket. It is designed to comply with common API restrictions (e.g., "150 requests per hour") by adding a restriction on the maximum number of tokens that can be removed each interval.
When using these classes, it is recommended to use them with a message queue to prevent multiple simultaneous calls to removeTokens(). Without a queue, earlier messages might be held up for long periods if newer messages continually drain the bucket, potentially causing out-of-order or seemingly "lost" messages.