How to apply global ratelimits?

It seems like once we make a middleware with ratelimiting configured on it, we have to add each service to use that middleware for rate-limiting to take effect. Am I missing something? Is it possible to have a top level rate limiting configuration that services can then override if they opt in to specific ratelimiting configuration?

Hello @urjit, welcome to the community,

Middlewares can be added to an entrypoint, so that ever router using that entrypoint is connected to the middleware.

Otherwise, yes, you would have to add the middleware to each router.

Thanks for the welcome @cakiwi ! That linked is exactly what I was missing.
Is it possible to override the middleware attached to entrypoint with a middleware attached to a service?

Context: I want to define global ratelimits which now I see if doable by attaching the middleware to the entrypoint. However, I'd like to override ratelimits for a few services. My tests with ab show it's not working like that. Any pointers there?

Edit: It seems like applying more restrictive ratelimits on the service while having more open limits on the global level works. I guess I can understand that due to the chain formation. Is there a way to "merge" the ratelimiter middlewares?

Adding a middlewares at the entrypoint prepends them to any list added by a router.

So it is one or the other. If you have a set of middlewares you want to apply to many routers but not all you can define a chain and reuse that on your routers.