System Protection via Throttling and Rate Limiting: 5 Real-World Use Cases

Arpit Bhayani

Arpit Bhayani

Apr 18, 2022 • 7 min read

Play

System Protection via Throttling and Rate Limiting: 5 Real-World Use Cases

In modern distributed architectures, downstream subsystems—such as relational databases, compute workers, and external third-party APIs—have finite processing capacities. When incoming traffic exceeds these bounds, unprotected systems degrade, experience resource starvation, and collapse under pressure.

Throttling is a defensive design technique ensuring that the ingress or egress flow of data and requests across a target system remains at an acceptable, sustainable rate. This role is typically implemented by a rate limiter, which regulates traffic volume to keep the underlying infrastructure operational.


Core Throttling Strategies for Excess Traffic

When ingress traffic exceeds configured thresholds, a rate-limiting subsystem typically applies one of three handling strategies based on whether the downstream interface is synchronous, asynchronous, or security-sensitive.

                 Incoming Traffic (Spike)


                 ┌───────────────────┐
                 │   Rate Limiter    │
                 └─────────┬─────────┘
       ┌───────────────────┼───────────────────┐
       ▼                   ▼                   ▼
┌──────────────┐    ┌──────────────┐    ┌──────────────┐
│ 1. Slow Down │    │  2. Reject   │    │  3. Ignore   │
│ (Buffering)  │    │  (Drop/429)  │    │ (Deceptive)  │
└──────────────┘    └──────────────┘    └──────────────┘

1. Slowing Down (Buffering / Leaky Bucket)

  • Mechanism: The rate limiter absorbs surplus requests into an intermediate buffer (such as an in-memory queue or message broker like Amazon SQS or RabbitMQ) and drips requests to consumer nodes at a steady, manageable rate.
  • Use Case: Asynchronous background workloads, message ingestion, event-driven pipelines, and non-blocking worker pools where latency increases can be tolerated.

2. Rejecting (Fast Failure)

  • Mechanism: The rate limiter strictly caps concurrent request counts or requests-per-second (RPS). Any request exceeding the capacity limit is rejected immediately without entering downstream pipelines.
  • Status Code: Synchronous HTTP clients receive standard status codes such as 429 Too Many Requests or 503 Service Unavailable.
  • Use Case: Synchronous user-facing APIs designed for low-latency request-reply loops (e.g., an API gateway configured for 100 RPS rejecting sudden surges of 1,000,000 RPS to protect backend application instances).

3. Ignoring (Silent Dropping / Tarpitting)

  • Mechanism: The rate limiter or load balancer quietly drops the payload or bypasses processing while deceptively returning an HTTP 200 OK response to the client.
  • Use Case: Defending against automated scrapers, botnets, and malicious attackers. Returning 429 signals to the attacker that they hit a limit, incentivizing them to rotate IPs or modify evasion tactics. Returning 200 OK fools the attacker into assuming the attack is succeeding, effectively neutralizing the vector without burning backend compute.

Why Systems Require Throttling

Throttling is not merely a blunt security tool; it is a fundamental architectural requirement for high-availability systems:

  1. Preventing System Abuse: Stops rogue actors, misconfigured client scripts, or malicious actors from monopolizing compute resources.
  2. Preserving Availability for Legitimate Traffic: Even when a surge consists of 100% legitimate users (e.g., a viral social post), accepting every connection will crash the database, rendering the service offline for everyone. Throttling ensures that a subset of users receives full performance rather than all users encountering a complete outage.
  3. Controlling Cloud Consumption Costs: Auto-scaling infrastructure (such as elastic GPU clusters for machine learning inference or serverless functions) can trigger exponential billing spikes during traffic surges. Throttling enforces hard budget boundaries.
  4. Preventing Cascading Failures: Distributed systems are deeply interconnected. If an overwhelmed database halts, API servers exhaust connection pools, memory utilization spikes across worker nodes, and failure ripples through the entire dependency graph. Placing rate limiters at system boundaries isolates failures to their origin point.

5 Real-World Throttling Use Cases

Rate limiting falls into two functional categories: External (perimeter defense) and Internal (orchestration, cost governance, and subsystem isolation).

               EXTERNAL                                 INTERNAL
  ┌─────────────────────────────────┐      ┌─────────────────────────────────┐
  │ • Use Case 1: DoS Protection    │      │ • Use Case 3: Tiered Quotas     │
  │ • Use Case 2: Surge Protection  │      │ • Use Case 4: Cost Optimization │
  │                                 │      │ • Use Case 5: DB Job Pacing     │
  └─────────────────────────────────┘      └─────────────────────────────────┘

Use Case 1: Preventing Catastrophic Denial-of-Service (DoS) Attacks (External)

  • Context: An external entity attempts to flood public endpoints with traffic to bring down the application.
  • Architecture: The rate limiter sits at the edge (CDN, Reverse Proxy, or API Gateway). It tracks telemetry metrics such as client IP, user agent, or session tokens.
  • Action: If a specific entity exceeds healthy behavioral thresholds, the rate limiter aggressively drops the surplus traffic before packets reach application servers.

Use Case 2: Gracefully Handling Viral Traffic Surges (External)

  • Context: An application experiences an unexpected spike in legitimate traffic (e.g., a high-profile media mention or flash sale). The infrastructure cannot auto-scale quickly enough to absorb the spike.
  • Architecture: An ingress rate limiter serves as a gatekeeper for incoming HTTP sessions.
  • Action: Rather than allowing the database to crash—causing a site-wide HTTP 500/503 outage—the rate limiter admits a fixed volume of sessions that the current database connection pool can comfortably handle. Surplus requests are throttled, queued in a waiting room, or shown an informative retry message. Partial availability is favored over complete collapse.

Use Case 3: Rationing Compute Capacity via Multi-Tiered Pricing (Internal)

  • Context: A CI/CD platform (such as CircleCI or GitHub Actions) provides compute time across tiered customer tiers:
    • Tier 1 (Free): 200 build minutes/month
    • Tier 2 ($5/mo): 1,000 build minutes/month
    • Tier 3 ($50/mo): Unlimited build minutes
  • Architecture:
User Trigger ──▶ API Server ──▶ Internal Rate Limiter ──▶ Trigger Build Workers


                                Consumption Store
                               (Redis / PostgreSQL)
  • Action: When an API server receives a trigger_build request, it synchronously queries the internal rate limiter. The limiter reads historical consumption statistics from a fast datastore. If the tenant has exhausted their allocated quota, the build is blocked. If quota remains, the job is dispatched to build workers, which periodically stream consumption metrics back to the store.

Use Case 4: Guarding Against Runaway Third-Party API Costs (Internal)

  • Context: An internal application integrates with an external, specialized third-party service (e.g., a complex proprietary LLM or computer vision vendor) that charges on a metered pay-per-call basis (such as $5 per invocation).
  • Architecture: Internal worker nodes do not dispatch outbound HTTP requests directly to the external vendor.
  • Action: A localized egress rate limiter sits between internal background workers and the external vendor. Every worker must obtain a token from the rate limiter before invoking the vendor’s API. This protects the organization against unbounded financial liability caused by software loops, runaway retry cascades, or sudden spikes in internal job processing.

Use Case 5: Protecting Unprotected Downstream Subsystems During Batch Workloads (Internal)

  • Context: Performing bulk data operations—such as executing a hard delete of 1,000,000 rows in an ACID-compliant relational database. Executing this in a single transaction triggers large-scale table locks, fills write-ahead logs (WAL), creates severe disk I/O bottlenecks, and stalls transactional read/write traffic from live users.
  • Architecture: The database engine does not self-throttle query executions. The responsibility shifts to the batch runner via a paced throttling mechanism.
  • Action: The internal job splits the million-row operation into discrete chunks (e.g., deleting 1,000 rows every minute or distributing the workload across off-peak 24-hour windows). By pacing operations, resource contention is smoothed across time, insulating the unprotected storage engine from sudden degradation.

Key Architectural Takeaways

AttributeExternal Rate LimitingInternal Rate Limiting
PlacementEdge, API Gateways, Load BalancersMicroservices, Job Workers, Message Handlers
Primary ObjectivePerimeter defense, DoS prevention, user fair useCost allocation, downstream protection, SLA enforcement
Handling MechanismFast reject (429), Deceptive 200 OK, Edge QueueIn-memory token bucket, Leaky bucket, Distributed locks
Target SystemsIngress Web/App ServersRelational DBs, Third-party APIs, Worker clusters
  1. Beyond Edge Security: Rate limiting is not purely an edge-level, anti-DDoS tool. Internal rate limiting is essential for multi-tenant fairness, protecting legacy components, and capping outbound third-party costs.
  2. Degrade Gracefully: Designing systems to return deterministic error signals or buffer excess requests is preferable to letting critical database connections saturate and fail unpredictably.
  3. Decouple Policy from Transport: Whether throttling synchronously at the gateway or pacing operations asynchronously across message queues, ensure that traffic limits match the proven capacity of the underlying persistent storage.
Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses