Source
Wikipedia: Redis
Redis history, architecture fundamentals, and the role of in-memory storage in modern systems.
Official site
Redis
Official documentation on data structures, persistence, replication, Sentinel, and Cluster.
Redis is an in-memory key-value store with rich data structures and extremely low latency. In system design, Redis is often used as a dedicated operational layer: cache, sessions, counters, queues/streams, and fast stateful primitives for high-throughput systems.
History and context
First public release
Redis appears as an open-source in-memory key-value store focused on very low latency.
Data model and use-case expansion
Beyond plain caching, Redis becomes widely used for rate limiting, queues, leaderboards, and session storage.
HA and scaling patterns mature
Replication, Sentinel, and Redis Cluster practices establish the baseline production approach for failover and sharding.
Cloud-first operations
Managed Redis becomes standard for many teams, shifting focus to SLA, observability, and memory cost control.
Core architecture elements
Event loop and atomic commands
Commands execute in a sequential event loop, simplifying concurrency behavior and keeping latency predictable.
In-memory data structures
Strings, Hashes, Lists, Sets, Sorted Sets, and Streams solve many workloads without a heavyweight query planner.
Durability: RDB and AOF
Redis supports multiple durability modes: snapshot persistence, append-only logging, and mixed strategies.
Replication and Cluster
Primary/replica topology, Sentinel, and hash-slot sharding in Redis Cluster provide HA and horizontal scale.
Redis Data Structures: why it is more than key/value
Redis stores typed structures and exposes specialized commands per type. This makes it more than a cache and enables practical stateful primitives with atomic operations.
Redis Data Structures: more than key/value
In Redis, a key points not just to a raw value but to a typed in-memory structure with specialized atomic commands.
Why Redis is not "just key/value"
- Redis values are typed (String/Hash/List/Set/ZSET/Stream), not opaque blobs.
- Server-side atomic operations reduce round-trips and simplify concurrency control.
- Each type provides domain primitives: leaderboards, queues, counters, event feeds, approximate analytics.
- Data structures + TTL + persistence + replication form a full operational data layer.
String
Universal type for cache entries, counters, flags, and compact JSON payloads.
Key commands
Typical use cases
- Cache-aside
- Session token
- Atomic counters
Example
SET user:1001:profile '{"name":"Alice"}' EX 300
INCR page:home:viewsHigh-Level Architecture
The diagram below shows a high-level Redis setup in a product system: client layer, command execution path, in-memory model, durability pipeline, and cluster/failover mechanics.
System view
Redis is typically used as an in-memory operational layer for low-latency reads/writes, often placed in front of durable transactional databases.
Latency profile
System design use cases
Operational trade-offs
Read / Write Path through components
The diagram combines write and read paths with operational notes: how Redis commands are routed, executed, and acknowledged in single-node and cluster topologies.
Read/Write Path Explorer
Interactive walkthrough of how Redis commands move through instance/cluster components.
Write path
- Application sends write command (`SET`, `HSET`, `XADD`) to Redis endpoint.
- In cluster mode, command is routed to hash-slot owner primary; cross-slot operations require key design discipline.
- Primary applies mutation in RAM and asynchronously replicates to replicas via PSYNC.
- Durability is tuned with RDB/AOF; latency vs safety depends on `appendfsync` and persistence settings.
When to choose Redis
Good fit
- Hot-data caching and API acceleration with sub-ms requirements.
- Session storage, rate limiting, distributed counters, and leaderboards.
- Pub/Sub and Streams for real-time events and lightweight queueing.
- Workloads where simple access patterns and speed matter more than complex ad-hoc queries.
Avoid when
- As the only source of truth for critical business data without a well-designed persistence strategy.
- Complex analytics and arbitrary join-heavy querying over large datasets.
- Workloads where active data volume significantly exceeds available RAM.
- Teams not ready to manage eviction policy, replication lag, and backup/recovery operations.
Practice: DDL and DML
Below are practical Redis commands: DDL-like keyspace/config operations and DML data read/write commands.
DDL and DML examples in Redis
Redis has no classic SQL DDL, but DDL-like operations define keyspace, durability, and access policy.
The DDL-like layer in Redis is mostly operational schema: durability settings, ACL boundaries, and structural primitives such as consumer groups.
Configure durability and memory policy
CONFIG SETDefine AOF behavior and eviction strategy under RAM limits.
CONFIG SET appendonly yes
CONFIG SET appendfsync everysec
CONFIG SET maxmemory 4gb
CONFIG SET maxmemory-policy allkeys-lruPrepare stream topology with consumer group
XGROUP CREATECreate stream + consumer group as a structural base for event processing.
XGROUP CREATE orders:events order-service 0 MKSTREAMACL profile for application user
ACL SETUSERRestrict application access by namespace and command groups.
ACL SETUSER app on >S3cr3t
~app:*
+@read +@write
-FLUSHALL