You want to limit users to 10 requests per minute globally across multiple FastAPI instances behind a load balancer. Which setup is best?
1. Use in-memory counters in each instance
2. Use Redis with fastapi_limiter shared by all instances
3. Use local file storage for counts
4. Disable rate limiting
hard
A. Option 2: Use Redis with fastapi_limiter shared by all instances
B. Option 1: Use in-memory counters in each instance
C. Option 3: Use local file storage for counts
D. Option 4: Disable rate limiting
Solution
Step 1: Understand distributed rate limiting need
Multiple FastAPI instances require a shared store to track request counts globally.
Step 2: Evaluate options
In-memory counters are local to each instance, causing inconsistent limits. Local files are not suitable for concurrency. Disabling rate limiting removes protection.
Step 3: Choose Redis shared by all instances
Redis is a fast, centralized store that all instances can use to enforce limits consistently.
Final Answer:
Option 2: Use Redis with fastapi_limiter shared by all instances -> Option A
Quick Check:
Distributed rate limiting needs shared Redis [OK]
Hint: Use shared Redis for consistent limits across instances [OK]
Common Mistakes:
Using local memory causing inconsistent limits
Using file storage which is slow and unsafe
Disabling rate limiting ignoring abuse risks
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.