Difficulty: Beginner
What is the difference between a DoS and a DDoS attack, and how are web applications protected against them?
A Denial of Service (DoS) attack tries to make a service unavailable by exhausting its resources, such as bandwidth, CPU, memory or connections. A DoS comes from one source or a few, so blocking that source usually stops it. A Distributed Denial of Service (DDoS) uses thousands or millions of machines, typically a botnet of hacked devices, so the traffic comes from everywhere at once and cannot be stopped by blocking a single IP.
| DoS | DDoS | |
|---|---|---|
| Sources | One machine or a few | Thousands to millions of devices |
| Typical scale | Limited by one connection | Can exceed what any single data centre link can absorb |
| Blocking by IP | Usually effective | Ineffective; IPs are many and often spoofed |
| Mitigation | Firewall rule, rate limit | Upstream scrubbing, anycast CDN, autoscaling |
Botnets like Mirai were built from insecure IoT devices such as cameras and routers with default passwords. Attackers also rent "booter" services, which makes DDoS cheap to launch.
/checkout endpoints at high rate, or Slowloris, which holds connections open by sending headers very slowly. The 2023 HTTP/2 Rapid Reset attack (CVE-2023-44487) abused stream cancellation to overwhelm servers with very few connections.Not every DoS is a flood. A single crafted request can cause DoS: a regular expression with catastrophic backtracking (ReDoS), a zip bomb, deeply nested JSON, or an unbounded database query.
Availability is one third of the CIA triad. For a payments or ticketing service during a flash sale, being down for minutes means real revenue loss. Interviewers often follow up by asking you to tell a DDoS apart from a legitimate traffic spike, such as an IPL ticket sale, so think about signals like request patterns, user agents and conversion rates.
import rateLimit from 'express-rate-limit';
// Tight limit on an expensive, frequently abused endpoint
const otpLimiter = rateLimit({
windowMs: 10 * 60 * 1000, // 10 minutes
limit: 5, // 5 OTP requests per window per key
standardHeaders: 'draft-7',
legacyHeaders: false,
keyGenerator: (req) => req.body.phone ?? req.ip,
});
app.use(express.json({ limit: '100kb' })); // cap body size
app.post('/auth/send-otp', otpLimiter, sendOtpHandler);
Rate limits in the app stop small-scale abuse and L7 floods that slip past the edge. They do not stop large volumetric DDoS, which must be handled upstream. Use a shared store like Redis when running multiple instances.
# http block
limit_req_zone $binary_remote_addr zone=perip:10m rate=10r/s;
limit_conn_zone $binary_remote_addr zone=conns:10m;
# server block
client_header_timeout 10s; # defeats Slowloris-style slow headers
client_body_timeout 10s;
client_max_body_size 1m;
limit_conn conns 20;
location /api/ {
limit_req zone=perip burst=20 nodelay;
proxy_pass http://app_upstream;
}
Timeouts close slow connections early, and per-IP request and connection limits reduce the impact of single-source DoS before requests reach Node or Java.
Denial of Service, DDoS, Botnet, Rate Limiting, Availability