Skip to content

Conversation

@arsh-anwr
Copy link

This PR introduces a complete, dependency-based Rate Limiting system for the FastAPI backend with Redis integration, configurable strategies, and automated validation through Settings. The implementation avoids middleware complexity and instead leverages FastAPI’s dependency injection system to enforce rate limiting at the endpoint level.

  1. Rate Limiting via FastAPI Depends
    Adds a RateLimiter class usable via Depends.

    @router.get("/users", dependencies=[Depends(RateLimiter(times=2, seconds=5))])

  2. Redis-backed Sliding Window Strategy
    Implements a redis-based sliding window rate limiter.

    Uses Redis key patterns containing:

    • identifier strategy (ip/user/header)
    • HTTP method + path
  3. Strategy & Redis URL now configurable via .env

    New environment variables added:

    RATE_LIMITER_STRATEGY=sliding_window
    RATE_LIMIT_FAIL_OPEN=True
    REDIS_URL=redis://redis:6379/0

@arsh-anwr arsh-anwr marked this pull request as draft November 16, 2025 19:48
@arsh-anwr arsh-anwr marked this pull request as ready for review November 16, 2025 20:36
@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Jan 20, 2026
@github-actions
Copy link
Contributor

This pull request has a merge conflict that needs to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant