Challenge - 5 Problems
Rate Limiting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
Understanding basic rate limiting behavior in Flask
Given this Flask app snippet using Flask-Limiter, what happens when a client exceeds the limit?
Flask
from flask import Flask from flask_limiter import Limiter from flask_limiter.util import get_remote_address app = Flask(__name__) limiter = Limiter(app, key_func=get_remote_address, default_limits=["3 per minute"]) @app.route("/") def index(): return "Hello, world!"
Attempts:
2 left
💡 Hint
Think about what '3 per minute' means for request limits.
✗ Incorrect
The Flask-Limiter is set to allow 3 requests per minute per client IP. After the third request, the client gets a 429 error until the minute resets.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in Flask-Limiter setup
Which option contains a syntax error in setting up Flask-Limiter with a custom limit?
Flask
from flask import Flask from flask_limiter import Limiter from flask_limiter.util import get_remote_address app = Flask(__name__) limiter = Limiter(app, key_func=get_remote_address, default_limits=["5 per minute"]) @app.route("/data") @limiter.limit("10 per minute") def data(): return "Data response"
Attempts:
2 left
💡 Hint
Check how the limit string is passed in the decorator.
✗ Incorrect
The limit must be a string. Option A misses quotes, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does the rate limit not apply as expected?
A developer uses Flask-Limiter with this code but finds the limit is never enforced. What is the cause?
Flask
from flask import Flask from flask_limiter import Limiter app = Flask(__name__) limiter = Limiter(key_func=lambda: "fixed_key") @app.route("/test") @limiter.limit("2 per minute") def test(): return "Test endpoint"
Attempts:
2 left
💡 Hint
Check how Limiter is initialized with the app.
✗ Incorrect
The Limiter instance is created without passing the Flask app, so it is not linked and does not enforce limits.
❓ state_output
advanced2:00remaining
What is the value of remaining requests after 2 calls?
Using Flask-Limiter with a limit of 3 requests per minute, what is the remaining request count after two successful calls from the same client?
Flask
from flask import Flask from flask_limiter import Limiter from flask_limiter.util import get_remote_address app = Flask(__name__) limiter = Limiter(app, key_func=get_remote_address, default_limits=["3 per minute"]) @app.route("/resource") def resource(): return "Resource accessed"
Attempts:
2 left
💡 Hint
Think about how many requests remain after two out of three allowed.
✗ Incorrect
With a limit of 3 per minute, after 2 requests, 1 request remains before hitting the limit.
🧠 Conceptual
expert2:00remaining
Why use a distributed rate limiter in Flask apps?
In a Flask app deployed on multiple servers behind a load balancer, why is using a distributed rate limiter important?
Attempts:
2 left
💡 Hint
Consider what happens when requests come to different servers.
✗ Incorrect
Local limits only track requests per server. Clients can avoid limits by hitting different servers. Distributed limiters share state across servers to enforce limits globally.