Skip to content

emka.web.id

writing knowledge, recording civilization

Menu
  • Home
  • Tutorial
  • Search
Menu

Why Redis is actually fast

Posted on December 3, 2026

The most common misconception I hear from junior engineers and even seasoned architects is that Redis is fast simply because it lives in memory. If that were the only factor, any application with a large enough hash map in RAM would perform identically. But as anyone who has managed a high-traffic production environment knows, that is simply not the case. The performance of Redis is not a byproduct of its storage medium alone; it is the result of a series of deliberate, almost obsessive engineering trade-offs that prioritize low latency and high throughput at the architectural level.

To understand why Redis consistently hits sub-millisecond response times while handling hundreds of thousands of operations per second, we have to look past the “In-Memory” label and dissect how it manages state, handles concurrency, and interacts with the Linux kernel.

The Latency Hierarchy and the Disk Bottleneck

The hardware reality is our starting point. If you look at the classic latency numbers every programmer should know, a main memory reference takes about 100 nanoseconds. Reading 1MB sequentially from an NVMe SSD takes about 200,000 nanoseconds. That is a 2,000x difference. By eliminating the disk seek and the heavy lifting of the filesystem layer during the hot path of execution, Redis removes the single biggest bottleneck in traditional RDBMS like PostgreSQL or MySQL.

Traditional databases have to manage complex buffer pools, write-ahead logs (WAL), and checkpoints to ensure that data eventually makes it to the spinning rust or NAND flash. Redis flips this. It treats the disk as an afterthought, an asynchronous persistence layer (via RDB snapshots or AOF logs), allowing the primary execution thread to operate at the speed of light or at least, the speed of your DDR4/DDR5 channels.

The Paradox of the Single-Threaded Event Loop

Perhaps the most controversial aspect of Redis for those coming from the world of Java or Go is its single-threaded nature. In an era where we have 64-core EPYC processors, why would a performance-critical system limit itself to one core?

The answer lies in the hidden costs of concurrency. When you have multiple threads accessing shared data structures, you need locks. You need mutexes. You have to deal with thread synchronization, context switching, and the overhead of the CPU scheduler moving threads between cores. In many high-concurrency systems, the CPU spends more time managing the competition between threads than actually executing business logic.

Redis uses a single-threaded event loop based on the Reactor pattern. By executing commands serially, Redis completely eliminates the need for locks. There are no race conditions within the data structures, no deadlocks, and no context-switching overhead. This simplicity allows the CPU to stay focused on the task at hand: manipulating strings, hashes, and sets in memory. It turns out that a single thread doing one thing at a time, very efficiently, is often faster than sixteen threads fighting over a single mutex.

IO Multiplexing and the Magic of epoll

If Redis is single-threaded, how does it handle 10,000 concurrent client connections? This is where the Linux kernel does the heavy lifting. Redis utilizes IO Multiplexing, specifically the epoll system call on Linux (or kqueue on BSD/macOS).

In the old days of networking, you would create a new thread for every incoming connection. That doesn’t scale. With epoll, Redis asks the kernel to monitor a massive list of file descriptors (sockets). The kernel puts the Redis process to sleep and wakes it up only when there is actual data to be read or a socket is ready to be written to.

Instead of the Redis process constantly polling “Is there data yet?”, it remains idle until the kernel says, “Hey, these five clients just sent their commands.” Redis then iterates through those specific ready-to-process events in a single burst. This O(1) efficiency in event notification is what allows a single thread to multiplex across thousands of active users without the performance degrading as the connection count grows.

Bespoke Data Structures over Generic Collections

Redis does not use generic “one-size-fits-all” data structures. Every structure in Redis is a highly optimized C implementation designed for a specific memory-vs-speed trade-off.

Take the Simple Dynamic String (SDS). In standard C, strings are null-terminated, meaning finding the length of a string is an O(N) operation because you have to scan for the \0 character. Redis uses SDS, which stores the length of the string at the beginning of the buffer. Getting the length becomes O(1). SDS also handles “binary safety,” allowing you to store raw bytes (like an image or a serialized Protobuf) without fearing that a stray null byte will truncate your data.

Then there are Skip Lists, used for Sorted Sets (ZSETs). While many databases use B-Trees or Red-Black Trees, Redis uses Skip Lists because they provide O(log N) search time but are significantly easier to implement and maintain. They allow for efficient range queries and are optimized for the concurrent-read, single-write profile of the Redis event loop.

For smaller datasets, Redis uses “Ziplists” or “Intsets” tightly packed, memory-efficient representations that avoid the pointer overhead of a full-blown linked list or hash table. When the collection grows past a certain threshold, Redis “promotes” the data structure to its more complex, scalable version. This “adaptive” approach ensures that even small keys don’t waste precious cache lines.

The RESP Protocol and the Move to Multi-threading

Efficiency extends to the wire. Redis uses RESP (Redis Serialization Protocol), which is a simple, human-readable yet performance-oriented protocol. It’s easy to parse and requires very little CPU overhead compared to complex formats like JSON or XML.

However, we must address the evolution of Redis. Starting with Redis 6.0, the “single-threaded” claim became slightly more nuanced. The creators realized that while the command execution was fast, the process of reading from the network, parsing the protocol, and writing the response back to the socket was becoming the bottleneck on modern 10Gbps+ networks.

Redis 6.0 introduced threaded IO. In this model, the core “brain” of Redis remains single-threaded to keep the data structures lock-free, but it offloads the “grunt work” of reading and writing to the network sockets to helper threads. This hybrid approach allowed Redis to double its throughput on multi-core machines without sacrificing the architectural simplicity that made it reliable in the first place.

Practical Implications: When Redis Isn’t Fast

Understanding why Redis is fast also means understanding its Achilles’ heel. Because it is single-threaded at its core, any command that takes O(N) time like KEYS * or a heavy LREM on a million-element list will block every other client. In a multi-tenant or high-scale environment, a single poorly optimized query is a “Stop the World” event.

This is why we use SCAN instead of KEYS and why we are careful with large Lua scripts. The speed of Redis is a contract: it promises to be incredibly fast as long as you promise not to block the loop.

Redis is a masterclass in mechanical sympathy. It understands the CPU, it understands the kernel, and it respects the hierarchy of memory. It’s not just “in-memory”; it’s an engine designed to do as little unnecessary work as humanly possible.

Terbaru

  • Why Redis is actually fast
  • The Fake 2FA Scandals and Fake AI Apps on Microsoft Store
  • Stop Overengineering Your Infrastructure: Docker Compose vs Kubernetes Resources
  • Traefik 3.8 New Feature: Yaegi v2 and the Gateway API Finally Make Custom Plugins Worth the Effort
  • Raspberry Pi OS: Why the November Update is a Win for Minimalism
  • React Can useState Hook Explained in 60 Seconds
  • How Do You Build an MMO Solo?
  • NixOS 26.11 “Zokor” Might Be the Most Practical Release for Desktop Power Users Yet
  • Why Your AWS Bill Can Just Tripled Overnight?
  • Why Indonesia’s Battle with Google is a Dangerous Game of Chicken
  • SYS010 Malware Explained: How Malvertising on Meta Bypasses MFA and Hijacks Your Digital Identity
  • Linux Mint 27 Adrien: Why This Version Jump is Make Sense?
  • NFS2ROOT: A 12-Year Reminder That Your Linux Kernel Is Never Truly Safe
  • The Death of Browsing and the Rise of the “Answer Engine Economy”
  • What’s new in Proxmox VE 9.3?
  • Why Your Morning Routine Needs an API: The Art of iOS Automation
  • Proof of Work is the New Certification: 5 AWS Projects to Build Before 2027
  • Omarchy is Our first agentic operating system
  • The Death of Popper.js: Why CSS Anchor Positioning is the New Standard for Connected UI
  • Why Your 2027 Cloud Career Depends on Moving Beyond Basic AWS Services
  • Why Discord is Ditching Electron for Rust: Is GPUi Actually the Future?
  • The End of the KDE Era: Why KaOS 2026.11 Is a Bold, Dangerous Gamble
  • The $2 Billion Code: Why GTA 6 is a Technical Miracle and a Hardware Nightmare
  • LibreDB Studio Explained
  • PHP 8.6 Is Officially Out: What’s New, What Breaks, and How We’re Upgrading
  • Rewriting Legacy Apps: 4 Data Migration Strategies That Actually Work
  • How to Install Clean Windows 11 Without Any Bloatware (Step-by-Step Guide)
  • IP Address Rate Limiting is Flawed—Here is the Right Way to Do It
  • Are Fedora 45 Stuck in Its Comfort Zone? A Short Review
  • Hacktober Recap 2026, A Month Full of Dangerous CVE: eMudhra, Gitlab, Brotli, PHP, NodeJS etc
  • Canonical: Ubuntu coming soon to Snapdragon X2 Series platforms
  • Finally, wolfSSL adds post-quantum algorithms!
  • How to Run Gemma Embedding Models Using Docker
  • Deploy Nginx Rootful Container with Podman
  • How to Sandboxing Browser on Linux Desktop with Flatpak
  • Ternary Bonsai 2.5 at 215 TPS! Splash + DFlash2 on Apple M5 Max
  • When to use an MCP server vs CLI with DevTools for agents
  • Your MCP Server Is a Search Result Now
  • AI Roadmap: How To Become An Agentic Operations Manager In 2027
  • What Does a Machine Learning Data Scientist Do?

©2026 emka.web.id | Design: Newspaperly WordPress Theme