Fixed window rate limiting counts requests in a fixed time window (e.g., 1 minute) and blocks if the count exceeds the limit.
Step 2: Match the correct condition for allowing or blocking
If requests exceed 100 in the last minute, block; otherwise, allow. if requests_in_last_minute > 100 then block else allow matches this logic exactly.
Final Answer:
if requests_in_last_minute > 100 then block else allow -> Option C
Quick Check:
Fixed window limit = block if over limit [OK]
Hint: Block when requests exceed limit in fixed window [OK]
Common Mistakes:
Using wrong time window (hour instead of minute)
Reversing the condition (blocking when under limit)
Allowing requests when they should be blocked
3. Given this pseudocode for a token bucket rate limiter:
bucket_capacity = 5
refill_rate = 1 token per second
current_tokens = 3
request_tokens = 2
if current_tokens >= request_tokens:
current_tokens -= request_tokens
allow request
else:
block request
What happens if a request for 4 tokens arrives immediately?
medium
A. Request is allowed and tokens reduce to -1
B. Request is blocked because refill rate is too low
C. Request is allowed and tokens reduce to 1
D. Request is blocked because not enough tokens
Solution
Step 1: Check current tokens against requested tokens
Current tokens are 3, request needs 4 tokens, which is more than available.
Step 2: Determine if request is allowed or blocked
Since current tokens (3) < request tokens (4), the request is blocked.
Final Answer:
Request is blocked because not enough tokens -> Option D
Quick Check:
Tokens < request = block [OK]
Hint: Allow only if tokens ≥ requested tokens [OK]
Common Mistakes:
Allowing request when tokens are insufficient
Ignoring token count and refill rate
Assuming tokens can go negative
4. A microservice uses a sliding window rate limiter but users report some requests are blocked even when they seem under the limit. Which is the most likely cause?
medium
A. The sliding window is not updating timestamps correctly
B. The service has too many servers without shared state
Sliding window requires accurate tracking of request timestamps across all servers to count requests correctly.
Step 2: Identify issue with multiple servers and no shared state
If servers do not share state, each counts requests independently, causing incorrect blocking even if total requests are under limit.
Final Answer:
The service has too many servers without shared state -> Option B
Quick Check:
Multiple servers need shared state for sliding window [OK]
Hint: Sliding window needs shared state across servers [OK]
Common Mistakes:
Blaming slow user requests
Assuming rate limit is too high causes blocking
Ignoring distributed state issues
5. You design a rate limiter for a microservice that must handle 10 million users, each allowed 100 requests per hour. Which approach best balances accuracy and scalability?
hard
A. Use distributed token buckets with local caches and periodic sync
B. Use a centralized fixed window counter stored in a single database
C. Use client-side rate limiting without server checks
D. Use a sliding window log storing every request timestamp centrally
Solution
Step 1: Analyze scalability needs for 10 million users
A centralized database (Use a centralized fixed window counter stored in a single database) or storing every timestamp centrally (Use a sliding window log storing every request timestamp centrally) will cause bottlenecks and high latency.
Step 2: Evaluate distributed token bucket with local caches
Distributed token buckets with local caches reduce central load and sync periodically, balancing accuracy and scalability well.
Step 3: Consider client-side rate limiting
Client-side (Use client-side rate limiting without server checks) is unreliable as clients can bypass limits.
Final Answer:
Use distributed token buckets with local caches and periodic sync -> Option A
Quick Check:
Distributed token bucket = scalable + accurate [OK]
Hint: Distributed token buckets scale best for millions [OK]
Common Mistakes:
Choosing centralized storage causing bottlenecks
Relying only on client-side limits
Storing all request logs centrally causing overload