Databases 6 min read

Redis Core Principles Explained with Four Diagrams

This article breaks down Redis’s core mechanisms—including its single‑threaded performance tricks, AOF and RDB persistence designs, and the evolution of high‑availability from replication to Sentinel and Cluster—using four clear diagrams to help readers master the system.

Code Farming
Code Farming
Code Farming
Redis Core Principles Explained with Four Diagrams

Redis is often praised for being fast because it runs on a single thread, but the real reasons lie in three key techniques: all data resides in memory, I/O multiplexing with epoll handles thousands of connections, and efficient data structures such as hash tables (O(1) lookups) and skip lists for ordered traversal. Official tests show single‑threaded QPS exceeding 100,000. Since Redis 6.0, multi‑threaded I/O speeds up network send/receive, while command execution remains single‑threaded, a nuance many overlook.

Redis single‑thread performance diagram
Redis single‑thread performance diagram

The Append‑Only File (AOF) persistence works opposite to MySQL’s write‑ahead log: Redis first executes the command in memory, then appends it to the log. This design records only successfully executed commands, avoids syntax‑check overhead, and does not block the current write, but it can lose the last command if the server crashes and incurs a brief pause when the main thread flushes to disk.

AOF vs MySQL WAL diagram
AOF vs MySQL WAL diagram

RDB snapshot persistence creates a point‑in‑time binary dump of the in‑memory dataset. To avoid blocking writes during snapshotting, Redis forks a child process; the child writes the snapshot while the parent continues handling requests, leveraging the operating system’s copy‑on‑write (COW) mechanism. The save command runs in the main thread and blocks, whereas bgsave is the recommended non‑blocking approach.

RDB snapshot with fork and COW
RDB snapshot with fork and COW

High availability in Redis has evolved through three tiers. Tier 1 is master‑slave replication, providing read/write separation and data backup but requiring manual failover. Tier 2 adds Sentinel nodes that monitor masters, automatically elect a new master on failure, and perform unattended failover. Tier 3 introduces Redis Cluster, a decentralized architecture that hashes keys into 16,384 slots distributed across multiple instances, enabling horizontal scaling and full read/write performance, and is the dominant production solution today.

Redis high‑availability evolution diagram
Redis high‑availability evolution diagram

Summarizing the knowledge framework: thread model (pre‑4.0 single thread, post‑4.0 async deletion, post‑6.0 multi‑threaded I/O), persistence options (AOF, RDB with COW, hybrid), and high‑availability progression (replication → Sentinel → Cluster). Understanding these three dimensions gives both breadth and depth to Redis architecture.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

High AvailabilityRedisPersistenceClusterAOFRDBThread Model
Code Farming
Written by

Code Farming

Senior engineer at a top internet giant, sharing Java, AI, tech knowledge, growth insights, and interview experiences.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.