Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Rate Limiting Middleware and Update Redis Integration #7

Merged
merged 2 commits into from
Nov 21, 2023

Conversation

saurabh-wednesday
Copy link
Contributor

This PR introduces a new rate-limiting middleware to the FastAPI application and updates the Redis integration to be compatible with aioredis version 2.x. The rate-limiting middleware restricts the number of requests a client can make within a specified time window, enhancing the API's robustness against potential abuse or excessive traffic.

Changes

  1. Rate Limiting Middleware:

    • Added a new RateLimitMiddleware class in middlewares/rate_limiter_middleware.py.
    • The middleware limits requests based on client IP and uses Redis to track request counts and enforce limits.
    • Clients exceeding the rate limit will receive a 429 Too Many Requests response.
  2. Redis Integration Update:

    • Updated Redis client creation to use aioredis.from_url, aligning with aioredis version 2.x API changes.
    • Removed explicit connection pool closing, as aioredis v2.x handles connection pooling automatically.
    • Ensured proper decoding of Redis responses by setting decode_responses=True.
  3. Configuration:

    • Redis URL and other configurations are managed via environment variables, allowing flexibility for different deployment environments.

Deployment Notes

  • Ensure that the Redis server is accessible at the configured URL in production.
  • Monitor the application logs for any unusual patterns or errors post-deployment.

@saurabh-wednesday saurabh-wednesday changed the base branch from main to feat/ecs-setup November 20, 2023 18:10
@saurabh-wednesday saurabh-wednesday changed the base branch from feat/ecs-setup to main November 20, 2023 18:11
config/db.py Show resolved Hide resolved
@saurabh-wednesday saurabh-wednesday changed the base branch from main to dev November 21, 2023 13:17
@saurabh-wednesday saurabh-wednesday changed the base branch from dev to main November 21, 2023 13:17
@saurabh-wednesday saurabh-wednesday merged commit cd1f692 into main Nov 21, 2023
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.

2 participants