Skip to content

Rate Limit NOT working with multiple workers using memory #226

@abdksyed

Description

@abdksyed

Describe the bug
I implemented rate limiting with default values, so the storage being used is local memory and running uvicorn with 8 workers.

For a end point with rate limit 5/minute, when I am hitting the endpoint in a for loop, I am able to hit for more than 10 times without any rate limiting. Is it due to multiple workers?

But isn't the memory shared between workers, so that the rate limit should work across workers?

To Reproduce

limiter = Limiter(key_func=get_remote_address)

@app.get("/home")
@limit.limiter("5/minute")
async def home(request: Request):
    return {"message": "hello"}

Expected behavior
N/A

Screenshots
N/A

Your app (please complete the following information):

  • fastapi or starlette? FastAPI
  • Version? 0.111.1
  • slowapi version (have you tried with the latest version)? 0.1.9

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions