mediumSystem Design

How do you protect a Node.js API against Denial of Service (DoS) and brute-force attacks?

617 views
01

Understand the problem

Discuss architectural and middleware strategies for rate-limiting incoming API requests.

securityapimiddleware
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Stricter limiter on the login route
import rateLimit from 'express-rate-limit';

const loginLimiter = rateLimit({
  windowMs: 15 * 60_000,
  max: 5,                          // 5 attempts / 15 min / IP
  standardHeaders: true,
  message: 'Too many attempts, try later',
});
app.post('/login', loginLimiter, loginHandler);
app.use(express.json({ limit: '50kb' }));   // cap payload size
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.