Bird
Raised Fist0

Why Rate Limiting Exists and What Happens to Systems Without It

HLDmediumInterview freq: common
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/6
Clients

Send HTTP request

Client sends a burst of HTTP requests to API Gateway

Protocol:HTTP
BeforeClient has requests ready to send
AfterRequests are in transit to API Gateway
API Gateway

Receive and forward request

API Gateway receives request and forwards to Rate Limiter

Protocol:gRPC
BeforeAPI Gateway has incoming HTTP request
AfterRequest forwarded to Rate Limiter for limit check
Rate Limiter

Check request count

Rate Limiter queries Redis to get current request count

Protocol:Redis GET
BeforeRate Limiter has request but no count yet
AfterCurrent request count retrieved from Redis
Rate Limiter

Increment request count

Rate Limiter increments request count in Redis

Protocol:Redis INCR
BeforeCurrent request count known
AfterRequest count incremented atomically in Redis
Rate Limiter

Decide allow or reject

If count exceeds limit, reject; else allow request

Protocol:Internal logic
BeforeRequest count updated in Redis
AfterRequest either allowed to proceed or rejected
Rate Limiter

Send metrics

Push rate limiting metrics to Metrics Database

Protocol:Metrics Push
BeforeRate Limiter has updated counters
AfterMetrics stored for monitoring and alerting
🏗️
Architecture Diagram
Architecture Diagram
┌───────────┐
│  Clients  │
└─────┬─────┘
      │ HTTP Requests
      ▼
┌─────────────┐
│API Gateway  │
└─────┬───────┘
      │ gRPC
      ▼
┌─────────────┐
│Rate Limiter │
└─────┬───────┘
      │ Redis GET/INCR
      ▼
┌─────────────┐
│Redis Cluster│
└─────┬───────┘
      │ Metrics Push
      ▼
┌─────────────────┐
│Metrics Database │
└─────────────────┘

This architecture shows how rate limiting protects backend systems from overload by controlling request rates at the API Gateway. Clients send HTTP requests which the API Gateway forwards to the Rate Limiter. The Rate Limiter uses Redis Cluster to atomically track request counts per client or API key. If the count exceeds configured limits, requests are rejected early, preventing backend overload. Metrics about request rates and rejections are pushed to a Metrics Database for monitoring. Without rate limiting, the API Gateway and backend services risk being overwhelmed by bursts of requests, causing degraded performance or outages. This design ensures system stability and fair resource usage.

Primary Focus

✓

Practice

(1/5)
1. A company needs to store large amounts of unstructured data like images and videos with metadata accessible via HTTP APIs. Which storage type best fits this use case?
easy
A. Object storage, because it stores data as objects with metadata and supports HTTP access.
B. Block storage, because it provides low-latency random access to raw data blocks.
C. File storage, because it offers hierarchical directories and POSIX file system semantics.
D. In-memory storage, because it offers the fastest access to large files.

Solution

  1. Step 1: Identify storage needs for unstructured data with metadata

    Object storage stores data as objects with customizable metadata and supports HTTP APIs, ideal for images/videos.
  2. Step 2: Eliminate other storage types

    Block storage is low-level and lacks metadata support; file storage is optimized for hierarchical file systems but less scalable for massive unstructured data; in-memory storage is volatile and unsuitable for large persistent files.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Object storage = scalable unstructured data + metadata + HTTP [check]
Hint: Object storage = objects + metadata + HTTP access [check]
Common Mistakes:
2. In the request flow for creating a pull request, at step 5 the Merge Worker attempts to apply the patch to the target branch. What happens if a merge conflict is detected at this step?
easy
A. The Merge Worker marks the pull request as conflicted and notifies the user to resolve manually
B. The Merge Worker retries the merge indefinitely until no conflicts remain
C. The Merge Worker discards the pull request and deletes the source branch
D. The Merge Worker automatically resolves conflicts using the latest commit's changes

Solution

  1. Step 1: Trace Merge Worker behavior at Step 5

    When a merge conflict occurs, automatic resolution is unsafe; the system flags the PR as conflicted and requires manual user intervention.
  2. Step 2: Eliminate incorrect options

    Automatic conflict resolution risks data loss; discarding PR or deleting branches is destructive; infinite retries cause resource exhaustion.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Merge conflicts -> PR marked conflicted, user notified [check]
Hint: Conflicts block merge until user resolves [check]
Common Mistakes:
3. A real-time leaderboard system must handle millions of score updates per second with low latency and provide instant rank queries. Which component is best suited to store and update scores efficiently while maintaining sorted order?
easy
A. A NoSQL document store like MongoDB for flexible schema
B. A relational database with indexed score columns
C. A distributed log like Kafka for storing score events
D. Redis Sorted Sets to maintain scores and ranks in-memory

Solution

  1. Step 1: Identify data structure for sorted order and fast updates

    Redis Sorted Sets provide O(log N) insertion and rank queries with in-memory speed, ideal for real-time leaderboards.
  2. Step 2: Eliminate other options based on latency and ordering

    Relational DBs have higher write latency and complex locking; Kafka stores events but doesn't maintain sorted order; MongoDB lacks efficient sorted queries at scale.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Redis Sorted Sets maintain sorted scores with low latency [check]
Hint: Sorted Sets keep scores sorted with fast rank queries [check]
Common Mistakes:
4. You must implement a distributed lock for a system with high contention and strict latency requirements. Which approach is best and why?
medium
A. Use Redis SETNX with a fixed TTL to minimize latency
B. Use a consensus-based lock service like etcd to ensure correctness despite latency
C. Use a database row lock with retries to handle contention
D. Use a local in-memory lock combined with periodic heartbeat checks

Solution

  1. Step 1: Evaluate Redis SETNX under high contention

    Redis SETNX with TTL (A) is fast but can cause split-brain and stale locks under network partitions, violating correctness.
  2. Step 2: Consider consensus-based lock service

    Consensus-based services like etcd (B) provide strong consistency and fault tolerance, ensuring correctness even if latency is higher.
  3. Step 3: Assess database row locks and local locks

    Database locks (C) have high latency and risk deadlocks; local locks (D) do not coordinate across nodes, failing correctness.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Consensus ensures correctness under contention despite latency [check]
Hint: Consensus beats speed for correctness under contention [check]
Common Mistakes:
5. At 10x scale, which component in the load balancer system is most likely to fail first and why?
hard
A. Load balancer routing tables, because stateful session persistence cannot shard easily
B. Health check workers, due to increased probe volume causing CPU exhaustion
C. Backend servers, because they cannot handle increased traffic without scaling
D. DNS resolvers, due to increased query volume causing cache misses

Solution

  1. Step 1: Identify stateful bottlenecks at scale

    Routing tables maintaining session persistence are stateful and hard to shard, causing scaling limits.
  2. Step 2: Compare other components

    Health checks scale horizontally; backend servers scale independently; DNS resolvers can be cached and distributed.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Stateful routing tables limit scaling due to session affinity [check]
Hint: Stateful routing tables limit scaling first [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard