Implementing Api Rate Limiting And Throttling
Overview
Cybersecurity skill for implementing api rate limiting and throttling. Follows industry best practices and security standards.
When to Use
Trigger phrases:
"implementing api rate limiting and throttling"
"Implements API rate limiting and throttling controls using token bucket, sliding"
Protecting authentication endpoints against brute force and credential stuffing attacks
Preventing API abuse and resource exhaustion from automated scripts and bots
Implementing fair usage quotas for different API consumer tiers (free, premium, enterprise)
Defending against denial-of-service attacks at the application layer
Meeting compliance requirements that mandate API abuse prevention controls
Do not use rate limiting as the sole defense against attacks. Combine with authentication, authorization, and WAF rules.
When NOT to Use
- When you lack proper authorization for testing
- For production systems without change management
- When the task requires legal or compliance expertise beyond technical scope
Prerequisites
- Redis 6.0+ for distributed rate limit counters (or in-memory for single-instance deployments)
- API framework (Express.js, FastAPI, Spring Boot, or Django REST Framework)
- Monitoring system for rate limit metrics (Prometheus, CloudWatch, Datadog)
- Understanding of the API's normal traffic patterns and peak usage
- Load testing tool (k6, Gatling, or Locust) for validating rate limit behavior
Workflow
# Example: IOC detection
import re
IOC_PATTERNS = {
"ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
"domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
"hash_md5": r"\b[a-f0-9]{32}\b",
"hash_sha256": r"\b[a-f0-9]{64}\b",
}
def extract_iocs(text: str) -> dict:
return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
- Assess Requirements — Evaluate current environment and define api rate limiting and throttling implementation requirements.
- Design Architecture — Plan the api rate limiting and throttling architecture, including components, integrations, and data flows.
- Configure Components — Set up and configure each api rate limiting and throttling component according to best practices.
- Test Integration — Validate that all components work together. Run functional and security tests.
- Deploy to Production — Roll out the implementation with monitoring and rollback capabilities.
- Validate and Document — Verify the implementation meets requirements. Document configuration and runbooks.
Tools
- Configuration Management — Infrastructure as code and automation
- Monitoring Stack — Observability and alerting
- Documentation Platform — Runbooks and architecture docs
Process
- Design — Define interface, identify patterns, plan implementation
- Implement — Write code following existing conventions, add tests
- Verify — Run tests, check integration, validate behavior
Verification
Anti-Rationalization Table
| Rationalization |
Reality |
| "We are too small to be targeted" |
Automated attacks target everyone. Size does not matter. |
| "Security slows us down" |
A breach slows you down 100x more. Build security in from the start. |
| "We will fix it after launch" |
Vulnerabilities in production are exploited within hours. Fix before deploy. |
1---2name: implementing-api-rate-limiting-and-throttling3description: Use when implements API rate limiting and throttling controls using token bucket, sliding window, and fixed window algorithms to protect against brute force attacks, credential stuffing, resource exhaustion, and API abuse. The engineer configures per-user, per-IP, and per-endpoint rate limits using Redis-backed counters, API gateway plugins, or application middleware, and implements proper HTTP 429 responses with Retry-After headers.4license: Apache-2.05---67# Implementing Api Rate Limiting And Throttling89## Overview1011Cybersecurity skill for implementing api rate limiting and throttling. Follows industry best practices and security standards.1213## When to Use14**Trigger phrases:**15- "implementing api rate limiting and throttling"16- "Implements API rate limiting and throttling controls using token bucket, sliding"171819- Protecting authentication endpoints against brute force and credential stuffing attacks20- Preventing API abuse and resource exhaustion from automated scripts and bots21- Implementing fair usage quotas for different API consumer tiers (free, premium, enterprise)22- Defending against denial-of-service attacks at the application layer23- Meeting compliance requirements that mandate API abuse prevention controls2425**Do not use** rate limiting as the sole defense against attacks. Combine with authentication, authorization, and WAF rules.262728## When NOT to Use2930- When you lack proper authorization for testing31- For production systems without change management32- When the task requires legal or compliance expertise beyond technical scope333435## Prerequisites3637- Redis 6.0+ for distributed rate limit counters (or in-memory for single-instance deployments)38- API framework (Express.js, FastAPI, Spring Boot, or Django REST Framework)39- Monitoring system for rate limit metrics (Prometheus, CloudWatch, Datadog)40- Understanding of the API's normal traffic patterns and peak usage41- Load testing tool (k6, Gatling, or Locust) for validating rate limit behavior4243## Workflow4445```python46# Example: IOC detection47import re4849IOC_PATTERNS = {50 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",51 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",52 "hash_md5": r"\b[a-f0-9]{32}\b",53 "hash_sha256": r"\b[a-f0-9]{64}\b",54}5556def extract_iocs(text: str) -> dict:57 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}58```59601. **Assess Requirements** — Evaluate current environment and define api rate limiting and throttling implementation requirements.612. **Design Architecture** — Plan the api rate limiting and throttling architecture, including components, integrations, and data flows.623. **Configure Components** — Set up and configure each api rate limiting and throttling component according to best practices.634. **Test Integration** — Validate that all components work together. Run functional and security tests.645. **Deploy to Production** — Roll out the implementation with monitoring and rollback capabilities.656. **Validate and Document** — Verify the implementation meets requirements. Document configuration and runbooks.6667## Tools6869- **Configuration Management** — Infrastructure as code and automation70- **Monitoring Stack** — Observability and alerting71- **Documentation Platform** — Runbooks and architecture docs727374## Process75761. **Design** — Define interface, identify patterns, plan implementation771. **Implement** — Write code following existing conventions, add tests781. **Verify** — Run tests, check integration, validate behavior7980## Verification8182- [ ] All api rate limiting and throttling procedures executed completely and documented83- [ ] Findings validated against multiple data sources84- [ ] False positives identified and filtered85- [ ] Results documented with evidence and timestamps86- [ ] Recommendations provided with risk-based prioritization8788## Anti-Rationalization Table8990| Rationalization | Reality |91|---|---|92| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |93| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |94| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |