Why Is Redis So Fast? Secrets of Its Speed and Single-Threaded Design
This article explains what Redis is, outlines its common data structures and persistence options, and delves into why Redis achieves exceptionally high performance through in‑memory storage, a single‑threaded event loop, multiplexed I/O, and simple data models, providing interview‑ready insights.
1. Introduction
Almost every Java interview asks about caching; concepts such as the 80/20 rule, hot and cold data, cache avalanche, penetration, warm‑up, update, and degradation are frequently discussed. The most common cache servers are Redis and Memcached, with Redis being the author's primary choice.
If you have never been asked why Redis is single‑threaded or why it is so fast, this article will give you a lucky chance to learn the answers, and even help interviewers test candidates.
2. Redis Overview
Redis is an open‑source, in‑memory data‑structure store that can serve as a database, cache, and message broker.
It supports various data structures: strings, hashes, lists, sets, sorted sets (ZSet), bitmaps, HyperLogLog, and geospatial indexes. The most common types are String, List, Set, Hash, and ZSet.
Redis provides replication, Lua scripting, LRU eviction, transactions, and persistence options (snapshotting and AOF). High availability is achieved via Sentinel and Cluster. Persistence can be disabled to use Redis purely as a fast cache.
Redis stores data in memory, eliminating disk I/O bottlenecks and delivering extremely low latency.
Images illustrating disk‑based vs. memory‑based databases:
3. How Fast Is Redis
Redis uses a single‑process, single‑threaded model written in C. Official benchmarks show over 100,000 QPS, comparable to multi‑threaded in‑memory KV stores like Memcached.
The graph demonstrates the order‑of‑magnitude performance that interviewees should be able to cite.
4. Why Redis Is So Fast
All operations are in‑memory, giving O(1) access similar to a HashMap.
Simple, purpose‑built data structures.
Single‑threaded event loop avoids context switches and lock contention.
Multiplexed non‑blocking I/O (select/poll/epoll).
Custom VM and protocol reduce system‑call overhead.
The article then explains the multiplexed I/O model, where a single thread monitors many connections using select/poll/epoll, processing only ready events.
5. Why Redis Is Single‑Threaded
Because Redis operations are memory‑bound, CPU is rarely the bottleneck; the main limits are memory size and network bandwidth. A single thread simplifies implementation and avoids locking overhead.
Note that Redis does spawn background threads or processes for persistence and, since version 4.0, some operations can use multiple threads.
6. Extensions
Other process models worth knowing for interviews:
Single‑process multi‑threaded: MySQL, Memcached, Oracle (Windows).
Multi‑process: Oracle (Linux).
Nginx: Master‑Worker model with either single‑process or multi‑process startup.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
