Public-facing APIs are perpetually subjected to automated credential stuffing, algorithmic scraping, and targeted vulnerability probes. In Node.js applications backed by MongoDB, a single unsanitized query parameter like req.body.password = { $ne: null } can bypass authentication entirely by exploiting MongoDB's rich query operators.
At Curved Lab, protecting financial balances and creator analytics demanded defense-in-depth security. Here is how we architected a 3-tier distributed rate-limiting hierarchy and recursive NoSQL query sanitization pipeline that defends our API gateway without introducing measurable latency.
The 3-Tier Rate Limiting Architecture
Applying a blanket rate limit (e.g. 100 requests per 15 minutes) across an entire API is an operational anti-pattern: it is either too loose to stop brute-force attacks on login endpoints or too strict for authenticated single-page applications loading campaign analytics in parallel.
We implemented a three-tier sliding window rate limiter in Redis:
