Urgent.News

What's breaking now, across thousands of outlets.

Tech

Building a rate limiter, why even use Redis.

Well I failed a amazon OA because of a rate limiting question, So I have built this rate limiter from first principles and haven't followed any tutorial. Through this blog, I want to answer questions like: Why even use Redis to make a rate limiter? Why not just use a Node.js process? What are the issues with using Node.js? Node.js race conditions: If we use an in-memory map, async execution…

In this story, the author explains why using Redis to create a rate limiter is a better option than using a Node.js process or a standard database. When building a rate limiter from scratch, the author highlights several issues with using Node.js, such as race conditions and millisecond collisions. Race conditions occur when two requests hit within the same millisecond and read/write the same timestamps, bypassing the rate limit.

Millisecond collisions happen when two requests occur simultaneously, causing them to overwrite each other's data.

The author compares the use of a ZSET in Redis to simply using a map and array. A sorted array allows for O(logN) search time using binary search, but write-heavy operations like insertion and deletion can be costly (O(N) memory-copy operations). Redis uses a combination of a hash map and a skip list to achieve both fast lookups and efficient memory usage while performing write operations.

Traditional databases are not a viable solution because they suffer from concurrency bugs similar to Node.js. Most databases use Multi-Version Concurrency Control (MVCC), which allows stale reads while writes are in progress. This can cause the rate limit to be bypassed if a second request reads the uncommitted state before the first write finishes processing.

The express-rate-limit library, which is often used for rate limiting, also suffers from the boundary burst problem due to its fixed-window approach. This issue allows an attacker to send requests within the reset window, bypassing the limit.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Standing orders: who decides when the decision-maker is off the grid

Standing orders are pre-authorized decisions, in writing, with limits: what the on-call may do ALONE while the decision-maker is unreachable.

  • Standing orders allow on-call engineers to act independently when decision-maker is unavailable.
  • Implemented standing orders reduced duplicate charges from 212 customers to 19 within four minutes.

One Python Agent Core, Four Ways to Run It: Nova on Server, Web, TUI, and Desktop

Nova is an open-source personal AI agent runtime for developers. One Python core is available through terminal, web, desktop, and API, so you get a single local workspace for model providers, tools…

  • Nova is an open-source AI agent runtime with a single workspace.
  • It provides four interfaces: terminal, web, TUI, and desktop.
  • The agent core drives all four interfaces with consistent loop and storage.

More from Saturday 12 September →