Redis High‑Availability Architecture and Best Practices
This article explains Redis fundamentals, details the Sentinel mechanism, compares several high‑availability deployment patterns—including Sentinel with DNS or VIP, client‑direct connections, Keepalived/Haproxy, Redis Cluster, Twemproxy, and Codis—provides their advantages and drawbacks, and offers practical best‑practice recommendations for reliable production use.
Introduction
Redis is an open‑source, in‑memory key‑value store written in ANSI C that supports persistence and networking. Its design prioritises performance, making it one of the fastest NoSQL databases, while high availability is essential for 24/7 internet services.
Sentinel Principle
Redis Sentinel discovers masters via configuration files, monitors them by sending periodic INFO commands, and exchanges HELLO messages with other Sentinels to announce its presence. It uses PING to detect instance health, and a failover is triggered only after a quorum of Sentinels authorises it. The elected slave becomes the new master based on priority, replication offset, and process ID, after which Sentinels broadcast the updated configuration version.
High‑Availability Architectures
Several common Redis HA solutions are presented:
Sentinel cluster + internal DNS + custom scripts.
Sentinel cluster + VIP + custom scripts.
Client‑direct connection to a Sentinel port, then to the current master (e.g., JedisSentinelPool for Java, PHP wrappers).
Sentinel cluster + Keepalived/Haproxy.
Native master/slave with Keepalived (M/S + Keepalived).
Redis Cluster (sharding with 16384 slots, gossip protocol).
Twemproxy (proxy layer with consistent hashing).
Codis (ZooKeeper‑based routing, Codis‑Proxy, Codis‑Redis).
Each architecture is accompanied by concise pros and cons, such as sub‑second failover, transparency to applications, maintenance cost, dependency on DNS or VIP, potential split‑brain, and performance impact of proxies.
Best Practices
The author recommends primarily using Sentinel + internal DNS + custom scripts or Sentinel + VIP + custom scripts. Operational tips include deploying at least five Sentinel nodes, grouping business services under a single Sentinel cluster, defining clear port ranges, implementing scripts in Python with Paramiko for SSH reuse, disabling DNS and GSSAPI in SSH, and ensuring automatic or manual failover completes within 15 seconds.
Conclusion
The presentation emphasizes the necessity of Redis high availability, summarizes Sentinel fundamentals, compares practical HA architectures, and shares field‑tested best practices to help engineers design robust Redis deployments.
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.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
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.
