SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • SSL/TLS
  • Encryption at Rest
  • Secrets Management
  • Password Management
  • RBAC
  • SAML
  • OWASP Top 10 and Common Attacks
  • DDoS Attacks and Defenses
  • Web Application Firewall (WAF)
  • Certificates and PKI
  • Multi-Factor Authentication (MFA)
  • Zero Trust
  • Key Management (KMS)
  • Data Privacy and GDPR Basics
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Advanced Security

DDoS Attacks and Defenses

Floods of fake traffic that try to knock a service over, and the layers that absorb them.

⏱ 12 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A DDoS (distributed denial of service) attack tries to make a service unusable by flooding it with fake traffic from thousands of machines, so real users cannot get through.

  • Three families: volumetric (fill the pipe), protocol (exhaust connection tables), application (make expensive requests).
  • No single fix. Each kind hits a different bottleneck, so you defend in layers.
  • Core idea: absorb the flood far away from your servers (CDN, anycast, scrubbing), then filter what is left (rate limits, WAF, bot checks).

02Concept: What is it?

"Denial of service" means users are denied the service. It is not about stealing data. The attacker just needs more traffic than you can handle. The distributed part means the traffic comes from many machines, often a botnet of hacked devices, so you cannot simply block one address.

Three families of attack

FamilyWhat it overwhelmsExamples (at a high level)
VolumetricThe network bandwidth into your siteUDP floods, and reflection or amplification, where small spoofed requests to open servers (such as DNS or NTP) cause big replies sent at the victim
ProtocolState kept by servers, firewalls and load balancersSYN flood: many half-open TCP connections fill the table
Application layerYour app, CPU and databaseHTTP floods of expensive pages, and slow connections that hold sockets open (slowloris)
Same goal, different bottlenecks
Network
🌊Volumetricthe pipe is full
Transport
🔌SYN floodconnection table is full
Application
🌐HTTP floodapp and database are busy
A defence that fixes one layer does nothing for the others.
🧠You usually cannot out-muscle it alone
Large attacks can be bigger than one company's whole internet connection. That is why the first line of defence is a provider with far more capacity than the attacker: a CDN or a DDoS protection service.

03Real-Life Example

🍵The Prank Crowd at the Shop Door
A small shop is mobbed by a thousand people who walk in, ask a question and do not buy anything. Real customers cannot get in. Locking the door is no help, because real customers are locked out too. A good shop sends greeters to the street corners to turn the crowd away early, asks everyone to take a ticket and wait, and sets up several shop doors in different streets so no single door is jammed.
The shop
DDoS defence
The crowd
Attack traffic from a botnet
Greeters on far-away street corners
CDN and anycast edge, scrubbing centres
One ticket per person
Rate limiting per client
Spotting people who are not shoppers
WAF and bot detection, challenges
Shop doors in many streets
Anycast: the same address in many places
Hiding the back-door address
Origin hiding: only the edge may reach it
Keep the till open for regulars only
Graceful degradation: protect the core path

04Why Do We Need It?

💸Lost revenue
Every minute of downtime on a shop or a payment service costs money.
🤝Lost trust
Users who cannot reach you go elsewhere, and may not come back.
🎭A cover for other attacks
A flood can distract the team while something else is attempted.
💰Extortion
Some attackers demand payment to stop or not to start.
📈Surprise bills
Auto-scaling under attack can create a huge cloud bill.
🧯Planning beats panic
Defences are far easier to set up before the first attack than during it.
You cannot prevent someone from sending traffic, so design for absorbing and filtering it.

05Where Do We Use It?

🛒Public websites and shops
Anywhere the address is public and downtime has a price.
🎮Online games
Rivals and extortionists target game servers.
🏦Finance and payments
High-value targets with strict uptime goals.
📰News and public services
Attacked during events or for political reasons.
🌐DNS and infrastructure
If DNS is down, everything behind it looks down.
🔌APIs
A cheap-to-call, expensive-to-run endpoint is a favourite target for application floods.

06Types / Parts / How It Works

Defence in layers

LayerDefenceStops mostly
EdgeCDN and anycast, which spread traffic over many sitesVolumetric, and some HTTP floods
NetworkScrubbing centres, upstream filtering, ISP blackholing as a last resortVolumetric, protocol
TransportSYN cookies, connection limits, timeoutsSYN floods, slow connections
ApplicationRate limiting, WAF, bot management, challenges (CAPTCHA)HTTP floods, bots, scrapers
OriginHide the origin address, accept traffic only from the edgeBypassing the edge
DesignCache static answers, queue expensive work, shed load, degrade featuresEverything that gets through
CapacityOver-provision, and auto-scale with a budget capModerate spikes
Layers a request goes through
🤖Botnet and real users
→↓
🌍Anycast edge / CDNabsorbs volume
→↓
🧹WAF, rate limitsfilter patterns
→↓
🖥️Originhidden, edge-only
Each layer removes some bad traffic, so the origin sees only what is left.
Untrusted traffic Absorb Filter Protected

Autoscaling: friend and foe

Adding servers under attack can keep you up, but you may pay for the attacker's traffic. Use a maximum size and alerts on cost, and prefer filtering to scaling for traffic you do not want.

VisualizerPick an attack, then switch defences onStart with no defences and choose each attack in turn. Then try to keep real users served. Notice that the CDN is great for volumetric floods but SYN cookies and the WAF each help only some attacks.
Type of attack
Defences (turn on and off)
Volumetric flood (UDP / reflection). Unit: Gbps. Bottleneck: the network link into your data centre.
Attack traffic sent80 Gbps
Attack reaching your origin80 Gbps
Real users' traffic1 Gbps
Origin capacity10 Gbps
Real users served
12%
Attack reaching origin
80
Gbps
Server cost
1×
fixed
With no defences, 80 Gbps of attack meets 10 Gbps of capacity. The bottleneck is the network link into your data centre, so about 88% of real users are turned away.

A teaching model with fixed, made-up numbers: each defence cuts a set share of one kind of attack, or none. Rate limiting and the WAF can also block a few real users by mistake (3% each here). Real attacks mix several types at once, and real defences are tuned live.

07How to Use It / Steps / Implementation

Getting ready (before it happens)

  1. 1
    Put a CDN or DDoS service in front
    Use one with far more capacity than any attacker, and with a global edge network.
  2. 2
    Hide the origin
    Allow traffic only from the edge networks, and keep the real origin address private.
  3. 3
    Cache and shed load
    Serve what you can from the edge. Make expensive endpoints optional under pressure.
  4. 4
    Rate limit by sensible keys
    By client, key, token or path, with tighter limits on login, search and other costly calls.
  5. 5
    Turn on WAF and bot rules
    Start in monitor mode, tune it, then block. Add challenges for suspicious clients.
  6. 6
    Harden the servers
    SYN cookies, sane timeouts, connection limits and capped request sizes.
  7. 7
    Cap auto-scaling
    Set a maximum and a budget alert so a flood does not become a surprise bill.
  8. 8
    Write a runbook and practise
    Who to call at the provider, how to turn on stricter modes, how to talk to customers.

During an attack

  1. Confirm it is an attack, and not a popular launch: look at where traffic comes from and what it asks for.
  2. Declare an incident and follow your runbook. Contact the provider early.
  3. Raise protection (stricter rate limits, challenge mode, block countries you do not serve) and accept some false positives.
  4. Protect the core path (login, checkout) and switch off nonessential features.
  5. Communicate on the status page, and review afterwards.
⚠️Blackholing is a last resort
Asking an ISP to drop all traffic to the target address stops the flood, but it also finishes the attacker's job for them: the victim is offline. Use it only to protect everything else on the network.

08Key Terms to Know

TermMeaning in easy words
DoS / DDoSDenial of service / distributed denial of service: making a service unusable by overload
BotnetA network of hacked machines controlled by an attacker
Volumetric attackAn attack that fills your bandwidth
Amplification / reflectionSmall spoofed requests to open servers that return big replies to the victim
SYN floodMany half-open TCP connections that fill the server’s connection table
SYN cookiesA way to answer connections without storing state until the handshake finishes
SlowlorisHolding many connections open with very slow requests
Scrubbing centreA site that cleans attack traffic and forwards the good traffic
AnycastOne address announced from many places, so traffic is spread out
WAFWeb application firewall: filters HTTP requests
Rate limitingCapping how many requests a client can make
BlackholingDropping all traffic to an address, to protect the rest of the network
Origin hidingKeeping the real server address private and accepting only edge traffic
Graceful degradationTurning off nonessential features to keep the core working

09Pros, Cons and Trade-offs

✅ Pros
  • Keeps real users served during an attack
  • Layers cover different attack types
  • A CDN also speeds up normal traffic
  • Planning cuts the time to recover
  • Rate limits also stop scrapers and abuse
⚠️ Cons
  • Protection services cost money
  • Filters can block real users (false positives)
  • Needs tuning and practice
  • Adds a dependency on a provider
  • No defence is complete against a determined attacker

Trade-offs

ChoiceWe gainWe lose
Strict rate limitsFewer bad requestsReal heavy users may be blocked
CAPTCHA challengeStops simple botsAnnoys users, hurts accessibility
Auto-scale upStays availablePays for attack traffic
Over-provisionHeadroom for spikesIdle cost all year
Block regionsCuts a lot of noiseBlocks real users and travellers
Outsource to a DDoS providerHuge capacity and experienceCost and lock-in

10Common Problems and Mistakes

Common mistakes

  1. Exposing the origin. If attackers learn the real address, they go around the CDN.
  2. Relying on one layer. A WAF does not stop a bandwidth flood.
  3. No cap on auto-scaling. The attack becomes a cost attack.
  4. Starting the plan during the attack. No contacts, no runbook, no tested rules.
  5. Mistaking a launch for an attack. A viral post looks like a flood. Check where traffic comes from.
  6. Leaving expensive endpoints unprotected. Search, export or login can be hit cheaply and cost you a lot.
  7. Open services that can be reflected. Do not run open DNS or NTP resolvers that amplify attacks against others.

Things to watch

🔍Telling real from fake
Compare traffic with normal patterns: sources, user agents, paths, request rates.
🧪Test your defence
Run load tests and game days with your provider, with permission.
📉Collateral damage
Filters that are too tight turn the attack into an outage for real users.
🌐DNS as a weak point
Use a resilient DNS provider, or your name will not resolve while you are under attack.

11Real-World Examples

☁️CDN and DDoS services
Cloudflare, Akamai, Fastly and the big cloud providers sell edge networks with built-in DDoS absorption.
🛡️Cloud protection
AWS Shield, Google Cloud Armor and Azure DDoS Protection are examples of managed protection.
📶Record-sized floods
Providers regularly publish reports of very large attacks, which is why capacity at the edge matters.
🔌IoT botnets
Cheap connected devices with default passwords have powered large botnets.
🧰Linux SYN cookies
A standard kernel feature that keeps a server responsive under a SYN flood.
🌍Anycast DNS
Root and major DNS services use anycast so no single site can be knocked out.
Mini case: an HTTP flood on search
🤖60k req/s of searchesfrom a botnet
→↓edge cache + WAF + rate limit
🧹Edgedrops most, caches the rest
→↓a few k req/s
🖥️Originhealthy, users served
The edge and WAF turn a flood into a trickle, and the origin stays healthy.

12Related Topics to Read Next

Anycast Routing→

Spreads attack traffic across many sites.

CDN→

Absorbs and caches traffic far from your servers.

Rate Limiting→

Caps requests per client to blunt application floods.

Web Application Firewall (WAF)→

Filters HTTP requests and bots.

Firewalls and VPN→

Network-level rules and origin protection.

Auto-Scaling Policies→

Scaling helps, but must be capped.

Incident Management and Postmortems→

How to run the response when an attack hits.

DNS→

A common target, and a single point of failure if weak.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔DDoS: many machines flood you so real users cannot get in.
  • ✔Types: volumetric, protocol (SYN), application (HTTP, slowloris).
  • ✔Absorb: CDN, anycast, scrubbing. Far from the origin.
  • ✔Filter: rate limits, WAF, bot checks, SYN cookies.
  • ✔Protect the origin: hide it, edge-only access.
  • ✔Scaling: cap it, or the attack becomes a cost attack.
  • ✔Prepare: runbook, provider contacts, game days.
  • ✔One line: “Absorb the flood at the edge, filter what is left, and keep the core path alive.”
← Previous
OWASP Top 10 and Common Attacks
Next →
Web Application Firewall (WAF)