Skip to content

Is there a way to combine rate limits? #126

@david8z

Description

@david8z

What is the optimal way to combine two rate limits together?

We could define:

export const ratelimit = {
    a: new Ratelimit({
      redis,
      limiter: Ratelimit.fixedWindow(1000, "60 s"),
    }),
    b: new Ratelimit({
      redis,
      limiter: Ratelimit.fixedWindow(3, "10 s"),
    })
  ]

And then await both:

await Promise.all(
ratelimit.a.blockUntilReady("a"),
ratelimit.b.blockUntilReady("b")
)

But this doesn't assures that once resolved none are blocked as one could resolve much faster than the other one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions