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 token4 bucket, sliding window, and fixed window algorithms to protect against brute force5 attacks, credential stuffing, resource exhaustion, and API abuse. The engineer configures6 per-user, per-IP, and per-endpoint rate limits using Redis-backed counters, API7 gateway plugins, or application middleware, and implements proper HTTP 429 responses8 with Retry-After headers.9domain: cybersecurity10tags:11- api-security12- rate-limiting13- throttling14- redis15- token-bucket16- abuse-prevention17subdomain: api-security18version: 1.0.019author: oyi7720license: Apache-2.021nist_csf:22- PR.PS-0123- ID.RA-0124- PR.DS-1025- DE.CM-0126category: cybersecurity27metadata:28 source: https://skillmd.com/skills/oyi77/implementing-api-rate-limiting-and-throttling29---3031# Implementing Api Rate Limiting And Throttling3233## Overview3435Cybersecurity skill for implementing api rate limiting and throttling. Follows industry best practices and security standards.3637## When to Use38**Trigger phrases:**39- "implementing api rate limiting and throttling"40- "Implements API rate limiting and throttling controls using token bucket, sliding"414243- Protecting authentication endpoints against brute force and credential stuffing attacks44- Preventing API abuse and resource exhaustion from automated scripts and bots45- Implementing fair usage quotas for different API consumer tiers (free, premium, enterprise)46- Defending against denial-of-service attacks at the application layer47- Meeting compliance requirements that mandate API abuse prevention controls4849**Do not use** rate limiting as the sole defense against attacks. Combine with authentication, authorization, and WAF rules.505152## When NOT to Use5354- When you lack proper authorization for testing55- For production systems without change management56- When the task requires legal or compliance expertise beyond technical scope575859## Prerequisites6061- Redis 6.0+ for distributed rate limit counters (or in-memory for single-instance deployments)62- API framework (Express.js, FastAPI, Spring Boot, or Django REST Framework)63- Monitoring system for rate limit metrics (Prometheus, CloudWatch, Datadog)64- Understanding of the API's normal traffic patterns and peak usage65- Load testing tool (k6, Gatling, or Locust) for validating rate limit behavior6667## Workflow6869```python70# Example: IOC detection71import re7273IOC_PATTERNS = {74 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",75 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",76 "hash_md5": r"\b[a-f0-9]{32}\b",77 "hash_sha256": r"\b[a-f0-9]{64}\b",78}7980def extract_iocs(text: str) -> dict:81 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}82```83841. **Assess Requirements** — Evaluate current environment and define api rate limiting and throttling implementation requirements.852. **Design Architecture** — Plan the api rate limiting and throttling architecture, including components, integrations, and data flows.863. **Configure Components** — Set up and configure each api rate limiting and throttling component according to best practices.874. **Test Integration** — Validate that all components work together. Run functional and security tests.885. **Deploy to Production** — Roll out the implementation with monitoring and rollback capabilities.896. **Validate and Document** — Verify the implementation meets requirements. Document configuration and runbooks.9091## Tools9293- **Configuration Management** — Infrastructure as code and automation94- **Monitoring Stack** — Observability and alerting95- **Documentation Platform** — Runbooks and architecture docs969798## Process991001. **Design** — Define interface, identify patterns, plan implementation1011. **Implement** — Write code following existing conventions, add tests1021. **Verify** — Run tests, check integration, validate behavior103104## Verification105106- [ ] All api rate limiting and throttling procedures executed completely and documented107- [ ] Findings validated against multiple data sources108- [ ] False positives identified and filtered109- [ ] Results documented with evidence and timestamps110- [ ] Recommendations provided with risk-based prioritization111112## Anti-Rationalization Table113114| Rationalization | Reality |115|---|---|116| "We are too small to be targeted" | Automated attacks target everyone. Size does not matter. |117| "Security slows us down" | A breach slows you down 100x more. Build security in from the start. |118| "We will fix it after launch" | Vulnerabilities in production are exploited within hours. Fix before deploy. |