System designCore11 min

DDoS protection & WAFs

A denial-of-service attack doesn't break in; it exhausts something: bandwidth, connection tables or the work behind each request. Each kind needs a defense at a different layer, and the biggest attacks can only be absorbed by networks far larger than yours. A web application firewall guards a different door, inspecting each request for attacks hidden inside it.

1 · The problem

A DDoS attack exhausts something, and there are three things to exhaust

A regional news site expects its biggest night of the year: election results. It also expects attacks, because some people would rather its results page were down. A distributed denial-of-service (DDoS) attack sends traffic from many machines at once, often a botnet of hijacked devices, so no single source can simply be blocked. Its aim is to use up some resource the site needs:

Layer

What runs out

Election-night example

Volumetric (network)

Bandwidth into the site

Hundreds of gigabits of reflected UDP traffic

Protocol (transport)

Connection state in servers and firewalls

Millions of half-open TCP connections

Application (HTTP)

Server work per request

Floods of valid-looking searches for results

The scale is the hard part. In 2018 GitHub was hit by 1.35 terabits per second of reflected traffic. In 2023 a new HTTP/2 technique produced attacks peaking at 201 million requests a second at Cloudflare, from a botnet of only about 20,000 machines, and 398 million a second at Google. No single site's servers or links come close to absorbing that. Defense has to happen in networks built for it, layer by layer.

2 · Volumetric

Amplification turns a small request into a flood aimed at someone else

UDP doesn't check the source address of a packet, so an attacker can send a small request to some server on the internet while forging the victim's address as the sender. The server sends its much larger answer to the victim. This is a reflection attack, and when the answer is larger than the request, an amplification attack. The attacker spends a little bandwidth; thousands of innocent servers spend a lot of it on the victim.

Protocol abused

Bandwidth amplification factor (US-CERT)

DNS

28 to 54

SSDP

30.8

QOTD

140.3

CharGEN

358.8

NTP

556.9

Memcached

10,000 to 51,000

Memcached is the extreme: Cloudflare observed a 15-byte request producing a 750 KB response, a factor of 50,000. That vector produced GitHub's 1.35 Tbps attack. GitHub's monitoring saw inbound bandwidth pass 100 Gbps at one facility, and the team rerouted its traffic through a DDoS mitigation provider by changing its BGP announcements. The site was unavailable for about five minutes and intermittently for four more.

Attackerforges the sender addressOpen UDP serversDNS, NTP, memcachedProvider's edgeanycast, many sitesNews site originclean traffic onlysmall requestshuge repliesfiltered

The flood is absorbed and dropped at the provider's edge, spread across its sites by anycast. UDP replies the site never asked for are easy to filter; the problem is only the volume.

The defense for volume is more capacity than the attacker, which means a provider with a network built to absorb it: A large edge network can absorb volumetric attacks that reach terabits per second. Anycast spreads a global botnet's traffic across every site, so each absorbs only its share (Anycast & global traffic routing). The news site's own job is to make sure the attack can't go around: its origin must accept traffic only from the provider.

3 · Protocol

SYN floods fill connection tables, and SYN cookies keep no state to fill

A TCP connection starts with a three-way handshake (How data moves across a network). When a server receives a SYN, it normally stores a small record for the half-open connection and replies with a SYN-ACK, waiting for the client's final ACK. A SYN flood sends SYNs with forged sources that never complete the handshake. The server's backlog of half-open connections fills, and real users' SYNs are dropped.

SYN cookies remove the state that the flood fills. Instead of storing the half-open connection, the server encodes the essential details into the sequence number of its SYN-ACK. A real client's ACK carries that number back, and the server rebuilds the connection from it; a forged SYN never returns an ACK and costs the server nothing to remember:

The forged SYNs get answers that go nowhere, but nothing is stored for them, so the table can't fill. Only handshakes that complete create state.

Edge services do this at scale: AWS's edge network verifies incoming connections with SYN cookies before passing them on, so only completed handshakes reach the application. Other protocol attacks target TLS handshakes or firewall state tables; the common defense is the same idea, terminating connections at an edge large enough to keep the state.

4 · Application

Application attacks look like real users, so they are fought with rates, caches and signatures

Layer 7 attacks send complete, valid HTTP requests. Each one passes the network and handshake defenses; the damage is the work it causes. On election night, a botnet requesting the results search page, uncached and backed by a database query, can overload the site at a rate the network barely notices.

HTTP/2's Rapid Reset showed how cheap such requests can be. HTTP/2 limits how many streams a client may have open at once, but a stream the client cancels with a RST_STREAM frame no longer counts. Attackers opened a stream, canceled it at once, and opened another, so each connection sent requests as fast as it could while staying within the limit, and servers kept doing the work for requests already abandoned:

Google's largest, 2022
46 million/s
Rapid Reset at Cloudflare
201 million/s
Rapid Reset at Google
398 million/s

Peaks in requests per second, reported in October 2023, against the largest attack Google had recorded the year before. Cloudflare's peak came from about 20,000 machines. Mitigations went into HTTP/2 servers, such as closing connections that abuse resets.

Defenses at this layer are about telling attackers from readers:

  • Rate limits per client, counting requests per IP or other key over a window and blocking or challenging above it (Rate limiting algorithms).
  • Caching, so a flood of identical requests is answered at the edge and never reaches the database (Content delivery networks (CDNs)). Election results can be cached for a few seconds and still be fresh.
  • Challenges for suspicious clients: a check before the request is served, applied only to traffic that looks wrong.
  • Shedding the least important work when overloaded, so the results page stays up even if search doesn't (Load shedding & backpressure).

5 · The WAF

A web application firewall looks inside each request for attacks

A DDoS attack overwhelms; an application attack sneaks. A web application firewall (WAF) sits in front of the application, often at the same edge, and inspects each HTTP request for attack patterns such as SQL injection in a form field or a script in a comment. It complements input validation in the application; it doesn't replace it.

The widely used OWASP Core Rule Set shows how a WAF decides without blocking too much. Rules don't block on their own. Each matching rule adds to the request's anomaly score according to its severity, and the request is blocked only when the total reaches a threshold, by default 5, the score of one critical match. Raising the threshold lets many attacks through, so it's done only temporarily while tuning.

Paranoia level

What it adds

False alarms

1

Rules that hardly ever fire on legitimate traffic

Rare

2

More rules, detecting more attacks

Some, needing tuning

3

Rules for specialized attacks

More

4

Very aggressive rules that catch almost everything

A lot of legitimate traffic flagged

Each level includes the ones below it, and every step up trades false alarms for coverage. False alarms are fixed with rule exclusions for specific fields, such as allowing HTML in the news site's article editor. A practical rollout runs new rules in a detection-only mode first, reviewing what they would have blocked, before letting them block. A WAF rule is also code running on every request: a bad one can take a site down on its own (Edge computing describes one that did).

6 · Architecture

Put everything behind the edge, and close every way around it

Most DDoS protection is decided before any attack, by where traffic can enter. A DDoS-resilient architecture starts from the edge: serve through services that run on a global edge network and reduce the attack surface behind them. For the news site that means:

  1. Every public name points at the edge

    DNS, the website, the results API and images all resolve to the protection provider, never to origin addresses.

  2. The origin accepts only the edge

    Firewall rules or private connections allow traffic only from the provider. An attacker who finds the origin's address still can't reach it.

  3. Expose nothing else

    No admin panels, databases or test servers on public addresses (Network segmentation & zero trust).

  4. Cache aggressively at the edge

    Results pages for seconds, images for days, so floods are served from the edge.

  5. Prepare the night

    Rate-limit rules tested, the provider's contact and escalation path known, and a runbook for turning on stricter challenges.

Autoscaling is for real surges in readers (Autoscaling); attack traffic should be stopped at the edge before it reaches anything that scales, so scale for the expected readers and let the edge absorb the rest.

7 · In practice

Match each defense to the resource being exhausted

Attack

Defense

Where

Volumetric, reflection and amplification

Absorb and filter in a network larger than the attack

Provider's edge, anycast

SYN flood and other protocol attacks

SYN cookies, connections terminated at the edge

Edge

HTTP floods

Rate limits, caching, challenges, shedding

Edge and application

Injection and other request attacks

WAF rules with anomaly scoring, plus input validation

Edge and application

Going around the edge

Origin accepts only the provider

Origin firewall

For the news site, the checklist:

  • Serve everything through a protection provider's edge, with anycast to spread attacks.
  • Lock the origin to the provider's addresses.
  • Cache what can be cached, even for seconds.
  • Rate-limit expensive endpoints per client, and know how to tighten limits quickly.
  • Run the WAF at a paranoia level you can tune, in detection mode before blocking, with exclusions for real false alarms.
  • Roll out WAF and rate-limit rules in stages, like code.
  • Rehearse the attack night: who to call, which switches to flip, what to shed.

Check yourself

5 questions

1. Why can an attacker with modest bandwidth send hundreds of gigabits at a site using memcached or NTP?
2. How do SYN cookies defeat a SYN flood?
3. What made HTTP/2 Rapid Reset so effective?
4. Why does the OWASP Core Rule Set block on an anomaly score rather than on any single rule match?
5. The site sits behind a protection provider, but attackers flood the origin's IP directly. What was missed?

Takeaways

Remember this

  • DDoS attacks exhaust bandwidth, connection state or per-request work, and each needs a defense at its own layer.
  • Reflection and amplification turn small forged UDP requests into floods; only a network larger than the attack, using anycast, can absorb them.
  • SYN cookies keep no state for half-open connections, so SYN floods can't fill the backlog.
  • Application-layer floods look like real users; fight them with per-client rate limits, edge caching, challenges and shedding.
  • A WAF inspects requests for attacks, scoring rule matches against a threshold; tune false alarms, and lock the origin so nothing goes around the edge.