Skip to content

feat(rate-limiter): implement leaky bucket rate limiting algorithm#186

Merged
halvaradop merged 1 commit into
masterfrom
feat/add-leaky-bucket-alg
Jun 10, 2026
Merged

feat(rate-limiter): implement leaky bucket rate limiting algorithm#186
halvaradop merged 1 commit into
masterfrom
feat/add-leaky-bucket-alg

Conversation

@halvaradop

@halvaradop halvaradop commented Jun 10, 2026

Copy link
Copy Markdown
Member

Description

This pull request implements the Leaky Bucket rate-limiting algorithm.

The algorithm can be used through the centralized createRateLimiter API or directly via the dedicated createLeakyBucketAlgorithm function.

The Leaky Bucket algorithm enforces a constant outflow rate by allowing requests to accumulate in a bucket with a fixed capacity while continuously leaking requests at a configured rate. This approach helps smooth traffic bursts and provides predictable request processing over time.

Usage with createRateLimiter

import {
  createRateLimiter,
  createMemoryStorage,
} from "@aura-stack/rate-limiter"

const limiter = createRateLimiter({
  storage: createMemoryStorage(),
  rules: {
    signIn: {
      algorithm: "leaky-bucket",
      capacity: 10,
      leakRatePerMs: 0.001,
      keyGenerator: (req: Request) =>
        req.headers.get("x-forwarded-for") ?? "unknown",
    },
  },
})

await limiter.signIn.check(
  new Request("http://incoming.request")
)

Direct Usage

import {
  createLeakyBucketAlgorithm,
  createMemoryStorage,
} from "@aura-stack/rate-limiter"

const signInLimiter = createLeakyBucketAlgorithm({
  algorithm: "leaky-bucket",
  capacity: 10,
  leakRatePerMs: 0.001,
  storage: createMemoryStorage(),
  keyGenerator: (req: Request) =>
    req.headers.get("x-forwarded-for") ?? "unknown",
})

await signInLimiter.check(
  new Request("http://incoming.request")
)

Features

  • Leaky Bucket rate-limiting algorithm
  • Integration with createRateLimiter
  • Direct usage through createLeakyBucketAlgorithm
  • Configurable bucket capacity and leak rate
  • Burst traffic smoothing
  • Compatible with all supported storage adapters
  • Custom request key generation

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
auth Skipped Skipped Jun 10, 2026 8:30pm

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@halvaradop, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b5e6b7f7-5b9b-49a5-913a-726ffa84a932

📥 Commits

Reviewing files that changed from the base of the PR and between 5d429a1 and fcd906a.

📒 Files selected for processing (6)
  • packages/rate-limiter/CHANGELOG.md
  • packages/rate-limiter/src/algorithms/index.ts
  • packages/rate-limiter/src/algorithms/leaky-bucket.ts
  • packages/rate-limiter/src/rate-limiter.ts
  • packages/rate-limiter/src/types.ts
  • packages/rate-limiter/test/algorithms/leaky-bucket.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-leaky-bucket-alg

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@halvaradop halvaradop merged commit 947b5f0 into master Jun 10, 2026
7 checks passed
@halvaradop halvaradop deleted the feat/add-leaky-bucket-alg branch June 10, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant