One-liner: A DDoS (Distributed Denial of Service) attack overwhelms your system with fake traffic until real users can't get through. Defense is layered ā no single solution works alone.
ā Types of Attacks
| Type | How | Target |
|---|---|---|
| Volumetric | Flood bandwidth (Gbps UDP) | Network layer |
| Protocol | Exhaust TCP connections (SYN flood) | Transport layer |
| Application (L7) | HTTP flood, slowloris | Your app |
| Credential stuffing | Try billions of stolen passwords | Auth endpoints |
| Scraping | Extract all your data | Business logic |
| Account enumeration | Guess valid emails | User existence |
š§± Defense in Depth (Layers)
Internet
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā CDN / DDoS Scrubbing Center ā ā Cloudflare, AWS Shield
ā Filters volumetric attacks ā Absorbs Tbps-scale traffic
ā IP reputation, anycast routing ā
āāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāā
ā (clean traffic only)
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā WAF (Web Application Firewall) ā ā Cloudflare WAF, AWS WAF
ā Blocks SQLi, XSS, bad patterns ā Rate limits by IP/user-agent
ā OWASP Top 10 rules ā Bot fingerprinting
āāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā API Gateway / Load Balancer ā ā Rate limiting per API key
ā Request throttling ā IP allowlist/blocklist
ā Auth enforcement ā Quota per user tier
āāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Application Rate Limiting ā ā Redis-backed counters
ā Per-user, per-endpoint limits ā Sliding window algorithm
ā CAPTCHA triggers ā Business logic rules
āāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāā
ā
ā¼
Your Services
š Rate Limiting Abuse Cases
1. Credential Stuffing Defense
// Stricter limits on auth endpoints
rateLimiter({
"/api/login": { max: 5, window: "15min", by: "ip" },
"/api/forgot-password": { max: 3, window: "1hr", by: "ip" },
"/api/register": { max: 10, window: "1hr", by: "ip" },
});
// After 5 failures: require CAPTCHA
// After 10 failures: temp block IP for 1 hour
// Alert security team if 1000+ failures from IP range
2. API Abuse Tiers
Free tier: 100 req/day, 10 req/min
Pro tier: 10,000 req/day, 100 req/min
Enterprise: Unlimited, custom limits
// Headers to return (industry standard):
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 42
X-RateLimit-Reset: 1699999999 (unix timestamp)
Retry-After: 60 (when limit hit, return 429)
3. Slow Loris Defense
Attacker sends HTTP headers very slowly to hold connections open.
# Nginx settings
client_body_timeout 10s;
client_header_timeout 10s;
keepalive_timeout 5s 5s;
send_timeout 10s;
š¤ Bot Detection Signals
| Signal | Legitimate User | Bot |
|---|---|---|
| Request rate | ~1-2 req/sec | 100s req/sec |
| User-agent | Chrome/Firefox | Empty or spoofed |
| TLS fingerprint | Real browser | curl, Python requests |
| Behavioral pattern | Random, varied | Uniform, sequential |
| JavaScript execution | Yes | No (headless bots) |
| IP reputation | Clean | Known datacenter/VPN |
Cloudflare Bot Management and reCAPTCHA v3 automate most of this.
āļø AWS Shield Tiers
| Tier | Protection | Cost |
|---|---|---|
| Shield Standard | Automatic L3/L4 protection | Free |
| Shield Advanced | L7 protection, DDoS cost protection, 24/7 DRT | $3,000/month |
Most startups: Cloudflare Free or Pro tier is sufficient.
ā Pros
- CDN/scrubbing centers absorb traffic before it reaches you
- WAF handles OWASP Top 10 without code changes
- Rate limiting protects business logic and database
- Layered approach means no single point of failure
ā Cons
- Cloudflare/Shield costs money at scale
- Sophisticated L7 attacks (mimic real users) are hard to distinguish
- Blocking legitimate users with aggressive rate limits hurts UX
- Misconfigured WAF rules cause false positives
āļø When to Use / When NOT to Use
ā Use when:
- Any public-facing API or website (DDoS is a real threat)
- Financial or health apps (credential stuffing target)
- APIs with expensive backend operations (LLM calls, DB writes)
- Any endpoint that is unauthenticated
ā Don't over-engineer when:
- Internal-only API (behind VPN/private network)
- Early prototype with 10 users ā Cloudflare Free is enough
- Traffic is already behind authentication (harder to abuse)
Top comments (1)
That IP reputation row is where I got burned. Several proxy feeds flag whole AWS and Hetzner ranges as proxies, so a simple majority vote quietly blocks legitimate server-to-server traffic. Now I need two independent specialist sources before flagging a datacenter IP, while a single hit on residential space is enough. Residential proxies are rarer and more telling.