DoS vs. DDoS

Difficulty: Beginner

Question

What is the difference between a DoS and a DDoS attack, and how are web applications protected against them?

Answer

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 vs DDoS at a glance

DoSDDoS
SourcesOne machine or a fewThousands to millions of devices
Typical scaleLimited by one connectionCan exceed what any single data centre link can absorb
Blocking by IPUsually effectiveIneffective; IPs are many and often spoofed
MitigationFirewall rule, rate limitUpstream 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.

The three main attack types

  1. Volumetric: flood the network pipe. UDP floods and amplification attacks, where the attacker spoofs the victim's IP and sends small queries to open DNS, NTP or memcached servers that reply with much larger responses to the victim.
  2. Protocol: exhaust connection state in servers, load balancers or firewalls. The SYN flood sends many TCP SYNs and never completes the handshake, filling the backlog.
  3. Application layer (L7): send requests that look legitimate but are expensive, such as hitting search, login or /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.

How applications are protected

  • CDN and DDoS protection at the edge: Cloudflare, AWS Shield with CloudFront, Akamai or Google Cloud Armor absorb volumetric traffic across a global anycast network before it reaches your origin.
  • Hide the origin: only accept traffic from the CDN's IP ranges so attackers cannot bypass it.
  • Rate limiting: per IP, per user and per API key, at the WAF or API gateway and in the app (for example with a Redis token bucket).
  • Kernel and server tuning: SYN cookies, connection and header timeouts, request body size limits.
  • Autoscaling and queueing: absorb spikes, and shed load gracefully with 429 or 503 instead of crashing.
  • Cache aggressively: a cached response costs almost nothing to serve.
  • Protect expensive endpoints: CAPTCHAs or proof-of-work challenges on login and OTP endpoints, which attackers also abuse to burn SMS credits.

Why it matters in interviews

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.

Layered DDoS defence for a web app. Most attack traffic should be dropped long before it reaches application servers.
  1. Botnet traffic: Millions of requests from many IPs.
  2. Anycast CDN and scrubbing: Absorbs volumetric and protocol floods.
  3. WAF and rate limits: Filters L7 floods and abusive clients.
  4. Load balancer and autoscaling: Spreads load and adds capacity.
  5. Application: Timeouts, caching and graceful 429s.

Code examples

Application-level rate limiting in Express

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.

Nginx limits against slow and flood attacks

# 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.

Key points

  • DoS comes from one or a few sources; DDoS comes from a distributed botnet
  • Three families: volumetric, protocol (SYN flood) and application layer (HTTP flood, Slowloris)
  • Amplification attacks abuse open DNS, NTP or memcached servers with spoofed source IPs
  • Large DDoS must be absorbed upstream by a CDN or scrubbing service
  • A single crafted request (ReDoS, zip bomb) can also cause DoS

Common follow-up questions

  • How do SYN cookies defend against a SYN flood?
  • How would you distinguish a DDoS from a genuine flash-sale traffic spike?
  • What is an amplification attack and why does it need IP spoofing?
  • What is ReDoS and how would you prevent it?

Interview tips

  • Classify attacks by layer; it shows structured thinking rather than a one-line definition
  • Explain that app-level rate limiting alone cannot stop volumetric DDoS
  • Mention single-request DoS like ReDoS to show depth beyond floods

Concepts covered

Denial of Service, DDoS, Botnet, Rate Limiting, Availability

More Web Security (OWASP, JWT, XSS, CSRF) questions