Recommended resources
The freely available resources this lesson will direct you to.
- [PDF] AWS Best Practices for DDoS Resiliency - AWS Whitepaperdocs.aws.amazon.com
- XDP in Practice: DDoS Mitigation @Cloudflare | PDF - Slidesharewww.slideshare.net
- DDoS Architecture Diagrams and White Paper - F5www.f5.com
- Defending from DDoS Attacks - Cloudflarewww.youtube.com
- [PDF] A better architecture to fight DDoS - Nokiawww.nokia.com
- William Hill: High-performance DDOS Protection with AWSwww.youtube.com
Hello! Welcome back.
In our previous lessons, we designed sophisticated defenses for specific layers of the network stack: a SYN proxy for Layer 4 and a behavioral analysis engine for Layer 7. While powerful, these are individual components. Real-world DDoS attacks are often multi-vector, blending high-volume network floods with subtle application-layer attacks. A robust defense requires an integrated system that can counter all of these tactics efficiently.
This brings us to today's goal: Architect a multi-layer traffic scrubbing pipeline that sequences inspection stages and fast-paths clean traffic. We will design the complete end-to-end system that intelligently combines different inspection techniques into a single, high-performance pipeline. We'll focus on the architectural "first principle" of why the order of these stages is critical for both security and performance.
1. The Core Principle: Layered Defense and Economic Asymmetry
The fundamental principle behind a scrubbing pipeline is to create an economic asymmetry that favors the defender. An attacker can generate malicious traffic cheaply, so the defense must be able to discard it even more cheaply. Applying a computationally expensive analysis (like full L7 inspection) to every single incoming packet would be prohibitively slow and would allow an attacker to overwhelm the defense itself.
The solution is a layered defense, where traffic passes through a sequence of inspection stages. Each stage is progressively more sophisticated and computationally expensive. The goal is to drop the vast majority of malicious traffic at the earliest, cheapest stages, preserving the powerful but expensive later stages for the most subtle and complex threats.
This concept is well-articulated in a foundational document from Riverhead Networks (an early pioneer in DDoS mitigation, later acquired by Cisco). Their Multi-Verification Process (MVP) provides an excellent mental model for a staged pipeline.
This technical note, 'DDoS Mitigation,' outlines a multi-stage architecture for traffic scrubbing. It introduces the core modules of a pipeline and, most importantly, discusses the critical nature of their sequencing.
Please read the sections 'The Riverhead MVP Architecture' and 'Five-step DDoS Mitigation'. Focus on understanding the five distinct modules: Packet Filtering, Anti-spoofing, Anomaly Recognition, Protocol Analysis, and Weighted Fair Queuing. We will use this as the blueprint for our design.
2. Architecting the Scrubbing Pipeline: Stage by Stage
Let's design our pipeline by integrating the concepts from the Riverhead paper with modern technologies and the components we've previously discussed. We'll visualize this as traffic flowing from the untrusted internet on the left to our protected origin server on the right.

Stage 1: The Packet Filtering Layer (Line-Rate Blocking)
- Purpose: To discard the most obvious junk and high-volume flood traffic at the fastest possible speed, directly at the network interface.
- Checks:
- Static Blacklists: Dropping traffic from known bad IP addresses or entire malicious networks.
- Stateless ACLs: Filtering based on simple packet header fields (e.g., blocking non-essential protocols, malformed packets, invalid TCP flag combinations).
- Geo-IP Filtering: Blocking traffic from regions where you have no legitimate users.
- Technology: To achieve line-rate performance for 10Gbps+ networks, this logic must run as close to the hardware as possible. In modern systems, this is a perfect use case for XDP (eXpress Data Path), which allows you to run eBPF programs directly in the network driver.
The following presentation from Cloudflare provides an excellent overview of how XDP is used to build the very first stage of a DDoS mitigation pipeline.
Netdev 0x13 - XDP based DDoS Mitigation
This Netdev talk, 'XDP based DDoS Mitigation,' details how Cloudflare built its foundational DDoS filtering layer. It provides critical insights into how to perform packet filtering at extreme speeds.
Please watch these two segments: XDP/eBPF Introduction (04:20 - 05:30): Focus on how XDP allows for immediate 'pass' or 'drop' decisions at the earliest point and the concept of chaining programs with tail calls, which is the mechanism for building our pipeline. Converting Classic BPF to eBPF (08:02 - 11:06): This section gives a sense of the engineering challenges. The key takeaway is the immense focus on instruction count and efficiency to run logic for hundreds of rules within a tiny performance budget. This underscores why we do only the simplest checks here.
Stage 2: The Anti-Spoofing Layer (Source Verification)
- Purpose: To verify that a packet's source IP address is legitimate and not forged (spoofed). This is a critical step before any behavioral analysis.
- Checks:
- TCP SYN Cookies: As we've discussed previously, this is a strong challenge-response mechanism for TCP traffic. By acting as a SYN proxy, we ensure the source IP can complete a three-way handshake.
- DNS Authentication: For DNS traffic (often over UDP), this involves techniques to verify that a request is likely from a real client, not a spoofed source in a reflection/amplification attack.
- Protocol Analysis: Ensuring packets conform to their respective RFC standards. Malformed packets are often a sign of primitive attack tools.
- Critical Sequencing: The Riverhead paper highlights why this stage must come before anomaly detection. If you perform behavioral analysis on spoofed traffic, an attacker could evade detection by making traffic from one machine look like it's coming from thousands. Worse, they could frame thousands of innocent IPs, causing your system to block them (a secondary denial of service).
Let's revisit the 'DDoS Mitigation' paper to understand the importance of this stage's placement.
Please read the section 'Critical Sequence'. This short but vital section explains the architectural reasoning for why anti-spoofing must precede anomaly recognition.
Stage 3: The Behavioral Layer (Anomaly & Rate Analysis)
- Purpose: Now that we've filtered out junk and spoofed traffic, we can analyze the behavior of legitimate sources. The goal is to catch compromised machines or botnets that are using their real IP addresses to launch attacks.
- Checks:
- Stateful Rate Limiting: Limiting connection rates or request rates per source IP.
- Anomaly Detection: This is where the behavioral baselining from our previous lesson comes in. We compare the current traffic patterns (request rate, packet size distribution, URL entropy, etc.) for each source against its learned "normal" profile. Deviations increase a source's anomaly score.
- Technology: This stage relies on maintaining state (flow tables, counters per IP) and performing more complex analysis. The data path is responsible for the enforcement (rate limiting), while the analysis can happen in a near-real-time control plane that updates policies, as we discussed previously.
Stage 4: The Application Layer (Deep L7 Inspection)
- Purpose: This is the final and most resource-intensive inspection stage, designed to catch attacks hidden inside what appears to be a legitimate user session.
- Checks:
- Web Application Firewall (WAF): Applying signature-based rules to look for known attack patterns (e.g., SQL injection, XSS).
- Advanced Behavioral Analysis: Correlating activity across multiple requests within a single session to detect malicious intent (e.g., scraping, credential stuffing).
- Bot Detection: Employing active and passive fingerprinting to distinguish human users from automated bots.
- Challenge-Response: Issuing CAPTCHAs or other challenges to highly suspicious but not yet confirmed malicious sources.
- Technology: This is typically implemented in a full reverse proxy (like Nginx, Envoy, or a custom-built service) that can parse and understand the full application protocol (e.g., HTTP/2).
The following diagram from Alibaba Cloud's security architecture shows a similar multi-tier approach, starting at edge nodes and escalating to specialized Anti-DDoS and WAF nodes.

3. The Feedback Loop and Fast-Pathing
A crucial design element that ties these stages together is the feedback loop. The intelligence gathered in the slow, deep later stages must be used to update the fast, simple earlier stages.
- Example: If the L7 Bot Detection engine (Stage 4) definitively identifies an IP as part of a malicious botnet, the control plane should immediately add that IP to the blacklist used by the XDP filter (Stage 1).
- Benefit: The next time a packet from that IP arrives, it will be dropped instantly at line-rate in Stage 1, consuming virtually no resources. It never even reaches the more expensive stages.
This feedback mechanism is what enables fast-pathing. While every packet conceptually flows through the pipeline, a well-architected system has several ways to accelerate legitimate traffic:
- Whitelist Bypass: Traffic from known-good, trusted sources (e.g., payment partners) can have rules that allow it to bypass certain intensive checks, like behavioral analysis.
- Efficient Dropping: As described above, the feedback loop ensures malicious traffic is dropped at the earliest possible stage, effectively fast-pathing the remaining legitimate traffic by reducing congestion in the later stages.
- Dynamic Rule Management: The XDP video touches on a fascinating implementation detail: enabling and disabling rules at near-zero runtime cost by rewriting compiled eBPF code. This allows the control plane to dynamically adjust the Stage 1 filter set with extreme agility.
Netdev 0x13 - XDP based DDoS Mitigation
Let's revisit the XDP video to see how this dynamic rule management and feedback loop is implemented.
Please watch these segments: The Feedback Loop (02:10 - 02:52): Note the architecture: sample at the edge, analyze centrally, and push rules back to the edge. Crucially, they emphasize sampling before dropping to maintain visibility. Dynamic Rule Toggling (12:56 - 14:10): This is a deep architectural detail. The key idea is that they can turn entire rule checks on or off without recompiling or restarting, allowing the feedback loop to be highly responsive. Debugging and Visibility (14:10 - 16:47): This explains how they get visibility into what the fast path is dropping, which is essential for tuning and ensuring no legitimate traffic is blocked (avoiding false positives).
Conclusion
In this lesson, we have designed a complete, multi-layer DDoS mitigation pipeline. We moved from designing individual components to architecting an integrated system, emphasizing the critical importance of sequencing and feedback loops.
Key Takeaways:
- Sequenced Inspection is Key: A scrubbing pipeline is architected in stages, from the fastest/cheapest (stateless packet filtering) to the slowest/most expensive (stateful L7 analysis).
- Drop Traffic Early and Cheaply: The primary goal is to shed the vast majority of malicious traffic at the earliest stages to protect the more resource-intensive later stages.
- The Pipeline Stages: A typical pipeline consists of (1) Packet Filtering, (2) Anti-Spoofing, (3) Behavioral Analysis, and (4) Application Inspection.
- Anti-Spoofing is a Critical Prerequisite: You must validate the source of traffic before you can meaningfully analyze its behavior.
- The Feedback Loop Enables Fast-Pathing: Intelligence from deep inspection layers must be fed back to update policies at the network edge, allowing malicious traffic to be blocked more efficiently over time.
Preview of the Next Lesson:
We've now mentioned Bot Management as a key function within our pipeline's application layer. This is a complex and fascinating field in its own right. In our next module, we will begin a deep dive into this topic, starting with the learning outcome: Design a data collection pipeline for an IP reputation system using honeypots, threat intelligence feeds, and application logs. We will start building the foundational component for any advanced bot detection system: knowing which IPs are good, bad, and ugly.