Deep Dive into Redis VI: Redis vs ZooKeeper vs etcd
· 阅读需 4 分钟
A Deep, Conceptual Comparison for Distributed Systems
1. High-Level Positioning
| System | Core Identity | Primary Purpose |
|---|---|---|
| Redis | In-memory data platform | Fast data access, caching, counters, queues |
| ZooKeeper | Distributed coordination service | Strong consistency, coordination, metadata |
| etcd | Distributed key-value store | Cluster configuration & service discovery |
One Sentence Summary
- Redis: “Give me data now.”
- ZooKeeper: “Coordinate distributed systems safely.”
- etcd: “Store and watch cluster state consistently.”
2. Fundamental Design Philosophy
Redis Philosophy
Speed > Everything
Memory-first
Eventual consistency (cluster)
Application-driven logic
Redis optimizes for latency and throughput.
ZooKeeper Philosophy
Correctness > Performance
Strong consistency
Coordination first
Centralized control plane
ZooKeeper optimizes for correct distributed behavior.
etcd Philosophy
Simplicity + Consistency
Raft-based consensus
Cloud-native control plane
Observability-friendly
etcd optimizes for operational clarity and reliability.
3. Core Architecture Comparison
Redis Architecture (Cluster Mode)
Client
|
┌───────────┴────────┐
│ Redis Cluster │
└───────────┬────────┘
┌───────────┴───────────┐
┌────┴────┐ ┌────┴────┐ ┌────┴────┐
│ Master1 │ │ Master2 │ │ Master3 │
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
Replicas Replicas Replicas
Key points:
- Hash slots (16,384)
- Sharding for scale
- Replication for availability
- Not consensus-based
ZooKeeper Architecture
Client
|
┌────────┴──────────┐
│ ZooKeeper Quorum │
└────────┬──────────┘
┌──────────┼──────────┐
┌────┴────┐┌────┴────┐┌────┴────┐
│ Leader ││Follower ││Follower │
└─────────┘└─────────┘└─────────┘
Key points:
- Single leader
- Zab protocol
- Linearizable writes
- Hierarchical namespace
etcd Architecture
Client
|
┌────────┴────────┐
│ etcd Cluster │
└────────┬────────┘
┌──────────┼──────────┐
┌────┴────┐┌────┴────┐┌────┴────┐
│ Leader ││ Follower││ Follower│
└─────────┘└─────────┘└─────────┘
Key points:
- Raft consensus
- Strong consistency
- Flat key-value space
- Watch-based design
4. Consistency Model (Critical Difference)
| Feature | Redis | ZooKeeper | etcd |
|---|---|---|---|
| Consistency | Eventual | Strong | Strong |
| Consensus | ❌ | Zab | Raft |
| Split-brain | Possible | Prevented | Prevented |
| Linearizable writes | ❌ | ✅ | ✅ |
Visual Consistency Comparison
Redis:
Write → Master → Async replicas
(possible stale reads)
ZooKeeper / etcd:
Write → Leader → Majority ACK → Commit
(always consistent)
5. Data Model Comparison
Redis Data Model
Key → Value
├── String
├── Hash
├── List
├── Set
├── ZSet
└── Stream
Optimized for application data structures.
ZooKeeper Data Model
/
├── app
│ ├── leader
│ ├── config
│ └── locks
- Tree-like (filesystem style)
- Znodes (small metadata)
- Ephemeral nodes
etcd Data Model
/services/app1/instances/1
/services/app1/instances/2
/config/db/timeout
- Flat KV
- Prefix-based grouping
- First-class WATCH support
6. Failure Handling
Redis Failure Model
Master crashes
↓
Replica promoted
↓
Possible data loss window
- Fast
- Not transactional
- Best-effort durability
ZooKeeper Failure Model
Leader crashes
↓
Election
↓
New leader with consistent state
- No data loss (committed)
- Slower failover
- Strong correctness
etcd Failure Model
Leader crashes
↓
Raft election
↓
New leader
- Guaranteed state safety
- Designed for automation
7. Persistence & Storage
| Aspect | Redis | ZooKeeper | etcd |
|---|---|---|---|
| Primary storage | RAM | Disk | Disk |
| Persistence | RDB / AOF | WAL + snapshot | WAL + snapshot |
| Data volume | Large | Small | Medium |
| Restart recovery | Fast | Moderate | Moderate |
Redis Persistence
RAM
│
├─ RDB (snapshot)
└─ AOF (append)
ZooKeeper / etcd Persistence
Client writes
↓
WAL (log)
↓
Snapshot
8. Typical Use Cases (MOST IMPORTANT)
Redis – When You SHOULD Use It
✔ Caching
✔ Rate limiting
✔ Distributed counters
✔ Session storage
✔ Queues / Streams
✔ Real-time analytics
✔ Leaderboards
Diagram:
User → App → Redis → Response (sub-ms)
ZooKeeper – When You SHOULD Use It
✔ Leader election
✔ Distributed locks
✔ Metadata management
✔ Kafka / HBase coordination
✔ Strong ordering guarantees
Diagram:
Services → ZooKeeper → Coordination
etcd – When You SHOULD Use It
✔ Kubernetes state
✔ Service discovery
✔ Feature flags
✔ Distributed config
✔ Cloud-native control planes
Diagram:
Nodes → etcd → Watch → React
9. Watch / Notification Capability
| Feature | Redis | ZooKeeper | etcd |
|---|---|---|---|
| Watch | Pub/Sub | Watcher | Native Watch |
| Reliability | Best-effort | Strong | Strong |
| Replay | ❌ | ❌ | ✅ |
etcd Watch Model
Client sets watch
↓
Key changes
↓
Guaranteed event delivery
10. Scalability Characteristics
| Aspect | Redis | ZooKeeper | etcd |
|---|---|---|---|
| Horizontal scale | Excellent | Poor | Limited |
| Data size | Very large | Very small | Small-medium |
| Clients | Millions | Thousands | Thousands |
Why ZooKeeper Does NOT Scale Like Redis
All writes → Leader
All coordination → Leader
This is intentional.
11. Operational Complexity
| Aspect | Redis | ZooKeeper | etcd |
|---|---|---|---|
| Setup | Easy | Hard | Medium |
| Debugging | Medium | Hard | Medium |
| Tuning | Many knobs | Many knobs | Few knobs |
| Cloud-native | Partial | No | Yes |
12. Security & Access Control
| Feature | Redis | ZooKeeper | etcd |
|---|---|---|---|
| Auth | ACL / AUTH | ACL | TLS + RBAC |
| Encryption | TLS | TLS | TLS |
| Multi-tenancy | Limited | Limited | Strong |
13. What NOT to Do (Very Important)
❌ Do NOT use Redis for:
- Distributed locks requiring strict correctness
- Leader election with safety guarantees
- Source of truth metadata
❌ Do NOT use ZooKeeper for:
- Large datasets
- High-QPS application reads
- Caching
❌ Do NOT use etcd for:
- Hot data paths
- Large object storage
- High-frequency counters
14. Decision Matrix (Quick Guide)
Need speed? ───────────▶ Redis
Need correctness? ─────▶ ZooKeeper
Need cloud control? ───▶ etcd
15. Mental Model Summary
Redis = Data Plane
ZooKeeper = Coordination Plane
etcd = Control Plane
They complement, not replace, each other.
16. Final Takeaway
- Redis is fast but not authoritative
- ZooKeeper is authoritative but heavy
- etcd is authoritative and cloud-native
The best systems often use all three, each for what it does best.