Challenge - 5 Problems
Rate Limiting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:00remaining
Understanding Rate Limiting Purpose
Why is rate limiting important in AI service APIs?
Attempts:
2 left
💡 Hint
Think about what happens when too many requests come at once.
✗ Incorrect
Rate limiting helps protect servers from too many requests at once, which can cause slowdowns or crashes.
❓ Model Choice
intermediate1:30remaining
Choosing a Rate Limiting Strategy
Which rate limiting strategy allows a user to make bursts of requests but limits the average rate over time?
Attempts:
2 left
💡 Hint
This algorithm uses tokens to allow bursts but controls the overall rate.
✗ Incorrect
The token bucket algorithm lets users send bursts of requests if tokens are available but enforces an average rate limit.
❓ Predict Output
advanced2:00remaining
Output of Rate Limiting Code Snippet
What is the output of this Python code simulating a fixed window rate limiter?
Prompt Engineering / GenAI
import time class FixedWindowLimiter: def __init__(self, limit, window_seconds): self.limit = limit self.window_seconds = window_seconds self.request_times = [] def allow_request(self): current_time = time.time() # Remove requests outside the current window self.request_times = [t for t in self.request_times if t > current_time - self.window_seconds] if len(self.request_times) < self.limit: self.request_times.append(current_time) return True else: return False limiter = FixedWindowLimiter(limit=3, window_seconds=5) results = [] for _ in range(5): results.append(limiter.allow_request()) time.sleep(1) print(results)
Attempts:
2 left
💡 Hint
The limiter allows 3 requests per 5 seconds window.
✗ Incorrect
The limiter allows the first 3 requests immediately, then blocks the next 2 because they fall within the same 5-second window.
❓ Metrics
advanced1:30remaining
Evaluating Abuse Prevention Effectiveness
Which metric best measures how well a rate limiter prevents abuse without blocking legitimate users?
Attempts:
2 left
💡 Hint
Think about mistakenly blocking users who should be allowed.
✗ Incorrect
False positive rate shows how often legitimate users are wrongly blocked, which is key for abuse prevention quality.
🔧 Debug
expert2:00remaining
Debugging Token Bucket Implementation
Given this token bucket rate limiter code, what error will occur when calling allow_request() repeatedly without waiting?
Prompt Engineering / GenAI
import time class TokenBucket: def __init__(self, capacity, refill_rate): self.capacity = capacity self.tokens = capacity self.refill_rate = refill_rate self.last_refill = 0 def allow_request(self): current_time = time.time() elapsed = current_time - self.last_refill self.tokens = min(self.capacity, self.tokens + elapsed * self.refill_rate) self.last_refill = current_time if self.tokens >= 1: self.tokens -= 1 return True else: return False bucket = TokenBucket(5, 1) for _ in range(10): print(bucket.allow_request())
Attempts:
2 left
💡 Hint
Check if all required modules are imported.
✗ Incorrect
The code uses time.time() but does not import the time module, causing a NameError.