Redis
Redis - Sub-Millisecond In-Memory Data Platform
Redis
Redis development in 2026 navigates a split ecosystem. Redis 8.6 ships JSON, TimeSeries, probabilistic structures, vector sets, and hybrid search natively — previously paid Stack modules. The March 2024 license change (BSD → SSPL → AGPL by May 2025) spawned Valkey: a Linux Foundation fork backed by AWS, Google, and Oracle. Valkey 8.1 benchmarks 8% more ops/sec, 22% lower P99, 20% less memory, and 20% lower AWS ElastiCache cost. Ubuntu 26.04 LTS ships Valkey by default. The API is identical — the choice is licensing and cost, not capability.
Build with RedisDatabase
Who Should Use Redis (or Valkey)?
Redis belongs in your architecture when your primary database cannot serve data fast enough for your latency requirements — not as a primary store, but as the hot layer in front of it. The applications that benefit most are those where a few thousand hot records account for 80% of reads, where session lookups need to be sub-millisecond across distributed servers, or where real-time features (live counters, leaderboards, event streams) require data structures that SQL databases serve awkwardly.
API Response Caching
Cache database query results, computed values, and external API responses with per-key TTL. A well-designed cache key scheme turns 50ms PostgreSQL queries into 0.2ms Redis reads for the 90% of requests that access hot data. Cache invalidation via SCAN + DEL patterns or tag-based invalidation with Redis Sets.
Session Management
Distributed session storage that's fast enough to not be the bottleneck in authentication middleware. HSET stores session data as hash fields; EXPIRE sets TTL automatically. Works identically across all application servers without sticky sessions or session affinity configurations.
Real-Time Leaderboards & Rankings
Sorted sets are purpose-built for this: ZADD adds a score, ZREVRANGE retrieves the top-N, ZRANK returns a player's rank — all O(log N). A global leaderboard with 10 million entries, updated in real time, is a single Redis sorted set. SQL's RANK() window function requires scanning millions of rows for the same result.
Rate Limiting & API Throttling
Sliding window rate limiting using Redis sorted sets (ZADD timestamps, ZREMRANGEBYSCORE expired entries, ZCOUNT active requests) is accurate, sub-millisecond, and works across distributed servers. Token bucket and fixed window implementations use INCR + EXPIRE. A Redis Lua script makes the check-and-increment atomic.
Pub/Sub & Event Streaming
Redis Streams (XADD, XREADGROUP) provide persistent, consumer-group-based message streaming with backpressure — more durable than basic pub/sub for inter-service communication. Pub/Sub (PUBLISH/SUBSCRIBE) handles fire-and-forget real-time notifications. Both patterns power WebSocket push notifications, live activity feeds, and service-to-service event propagation.
Vector Search for AI
Redis 8.0 integrates vector sets natively — store embeddings, perform approximate nearest-neighbor search, and combine vector similarity with Redis filter expressions. For applications already using Redis for caching that want to add semantic search, keeping vectors in Redis eliminates a separate vector database deployment.
When Redis Might Not Be the Best Choice
We believe in honest communication. Here are scenarios where alternative solutions might be more appropriate:
Primary persistent data store for critical business data — Redis is memory-bound; persistence (RDB/AOF) is secondary by design, and data loss on power failure without AOF configured is a real risk
Complex relational queries with JOINs and WHERE conditions — Redis has no query language for cross-key relationships; these belong in PostgreSQL or MySQL
Very large datasets where memory cost is prohibitive — 1TB of data in Redis requires 1TB of RAM; cold data belongs in a disk-based database with Redis caching only the hot subset
Applications that haven't identified a specific performance bottleneck — adding Redis without a measured problem to solve adds operational complexity without measurable benefit
Still Not Sure?
We're here to help you find the right solution. Let's have an honest conversation about your specific needs and determine if Redis is the right fit for your business.
Why Redis Remains the In-Memory Data Platform Standard
Redis 8.0 was a watershed release — JSON, TimeSeries, probabilistic structures, vector sets, and hybrid search moved from paid Stack modules into the open-source core. That's not a minor update; it's Redis acknowledging that modern applications need more than key-value storage. Whether deployed as Redis 8.6 or the Valkey 8.1 fork (22% lower P99, 20% less memory, 20% cheaper on AWS ElastiCache), the API and architecture are identical. The real Redis decision in 2026 isn't Redis vs alternatives — it's understanding which tier of your data architecture Redis belongs to: cache layer, session store, pub/sub backbone, rate limiter, or AI vector store.
#8 Overall
DB-Engines Rank (May 2026)
DB-Engines Ranking, score 147.63-22% vs Redis OSS
Valkey P99 Latency Reduction
Valkey 8.1 Benchmarks-20% vs Redis
Valkey AWS ElastiCache Cost
Amazon ElastiCache PricingValkey
Ubuntu 26.04 LTS Default
Ubuntu 26.04 Package RepositorySub-millisecond latency for all data structure operations — HSET, ZADD, LPUSH, SINTERSTORE — executed in memory with zero disk I/O on the critical path
Redis 8.0 integrates JSON, TimeSeries, probabilistic structures (Bloom/Cuckoo/Count-Min-Sketch), vector sets, and hybrid search into the open-source core — previously these were Redis Stack enterprise add-ons
Sorted sets (ZRANGEBYSCORE, ZRANK) are the canonical data structure for real-time leaderboards, priority queues, and time-windowed rate limiting — single O(log N) operations handle what would require complex SQL subqueries
Valkey 8.1 (Linux Foundation fork) delivers 8% more ops/sec, 22% lower P99 latency, 20% less memory, and 20% lower AWS ElastiCache hourly cost compared to Redis OSS — API-identical, production-proven
Pub/Sub and Streams (Redis Streams) enable real-time messaging architectures — Streams add consumer groups, persistent history, and backpressure handling that simple pub/sub lacks
Atomic Lua scripting and MULTI/EXEC transactions guarantee that compound operations (compare-and-swap, conditional updates) complete without interleaving — critical for distributed rate limiting and inventory management
Redis Cluster provides automatic data partitioning across 16,384 hash slots with client-transparent routing — horizontal scaling without application-level sharding logic
TTL (EXPIRE/PEXPIRE) applies at the key level — automatic expiry for sessions, cache entries, and OTP tokens without background cleanup jobs
Redis in Practice
Full-Page & Fragment Response Caching
Cache rendered page fragments, API response JSON, and database query results with per-key TTLs. A two-tier cache (in-process LRU + Redis distributed layer) handles both local and cross-server hot data. We implement tag-based cache invalidation using Redis Sets to invalidate groups of related keys when source data changes.
Example: SaaS dashboard caching per-tenant analytics queries — 50ms PostgreSQL → 0.2ms Redis for 85% of dashboard loads
Distributed Session Store
JWT or opaque session tokens stored in Redis HASHes with EXPIRE for automatic TTL. Stateless application servers authenticate any request without sticky sessions or shared file systems. Session invalidation (logout, password change) is an O(1) DEL operation. We implement session store for applications serving millions of concurrent sessions.
Example: Multi-region SaaS with Redis Cluster for session storage, serving 500K concurrent authenticated sessions
Real-Time Leaderboard
Sorted sets store player scores with O(log N) updates and rank lookups. ZREVRANGEBYSCORE retrieves top-N players; ZREVRANK returns any player's rank instantly. We've built global game leaderboards with 50M+ entries that return top-100 and player rank in under 1ms regardless of total user count.
Example: Mobile game global leaderboard with 10M players, sorted set updates on every match completion, P99 < 1ms
API Rate Limiting
Sliding window rate limiting with Redis sorted sets is accurate and atomic — add current timestamp, remove expired timestamps, count remaining in window, reject or allow. A Lua script makes check-and-update atomic across concurrent requests from the same client. Works across all API server instances without coordination overhead.
Example: Public API platform enforcing per-key rate limits across 20 API server instances with < 0.5ms overhead per request
Event Streaming with Redis Streams
Redis Streams (XADD, XREADGROUP, XACK) provide persistent message streaming with consumer groups, message acknowledgement, and configurable retention. For microservices communication at lower volume than Kafka justifies, Redis Streams eliminate the Kafka operational overhead while providing durability and consumer group semantics.
Example: Order processing pipeline using Redis Streams with three consumer groups: inventory, billing, and notification services
Distributed Locks & Mutual Exclusion
Redlock (multi-instance distributed lock) or single-instance SETNX-based locks handle distributed mutual exclusion for scheduled job deduplication, payment idempotency, and inventory reservation. Redis's SET NX PX command atomically sets a key only if it doesn't exist, with TTL — a correct distributed lock in a single command.
Example: Payment processor using Redis distributed locks to ensure idempotent payment execution across clustered servers
Redis Pros and Cons
Every technology has its strengths and limitations. Here's an honest assessment to help you make an informed decision.
Advantages
Sub-Millisecond Everything
Redis operates entirely in memory. Read latency is 0.1-0.3ms; write latency is similar. At P99, well-sized Redis instances consistently deliver under 1ms. This isn't achievable with disk-based databases regardless of caching — the architectural difference is fundamental.
Purpose-Built Data Structures
Strings, Hashes, Lists, Sets, Sorted Sets, Streams, HyperLogLog, Bloom Filters, and now Vector Sets — each optimized for its use case at the C implementation level. A sorted set leaderboard, a rate limiter, a job queue, a session store, and a pub/sub channel are all handled by a single Redis instance using the appropriate data structure.
Redis 8.0 Unified Core
JSON, TimeSeries, probabilistic data structures (Bloom/Cuckoo/Count-Min-Sketch), vector sets, and hybrid search are now part of the open-source Redis 8.x core — not paid enterprise add-ons. This dramatically expands what's possible with Redis without licensing complexity.
Valkey 8.1 Performance at Lower Cost
Valkey (the Linux Foundation fork backed by AWS, Google, Oracle) delivers 8% more ops/sec, 22% lower P99 latency, and 20% less memory than Redis OSS — with identical API compatibility. Amazon ElastiCache offers Valkey at 20% lower cost than Redis. Ubuntu 26.04 LTS ships Valkey as the default redis package.
Cluster for Horizontal Scale
Redis Cluster partitions data across 16,384 hash slots distributed across primary-replica node pairs. Adding nodes increases both capacity and throughput linearly. Client-transparent routing via the MOVED redirect protocol means applications don't need to know the cluster topology explicitly.
Atomic Operations for Distributed Systems
MULTI/EXEC transactions and Lua scripts execute atomically — no other client can see intermediate state. SETNX (Set if Not Exists) with PX TTL is a single-command atomic lock. These primitives enable correct distributed algorithms that would require external coordination services (ZooKeeper, etcd) in other databases.
Limitations
Memory-Bound Dataset Size
Redis stores everything in RAM. A 1TB dataset requires 1TB of RAM — at ~$5-10 per GB/month for managed Redis, large datasets become expensive. Redis Data Tiering (available in Redis Cloud) moves less-accessed data to SSD, but the architecture is fundamentally memory-first.
We implement cache eviction policies (LRU, LFU, TTL-based) to cap memory usage to the hot working set. Cold data belongs in PostgreSQL or MongoDB with Redis caching only the 20% of data that accounts for 80% of reads. We size Redis instances based on measured working set, not total dataset.
Durability Tradeoffs
Redis persistence comes in two forms: RDB (point-in-time snapshots, risk losing minutes of data) and AOF (append-only log, near-zero data loss, 10-20% slower). Without persistence configured, a Redis restart means empty cache. Without AOF, a crash means losing recent writes.
We configure AOF with appendfsync = everysec as the production default — 1-second data loss risk with acceptable write overhead. For session and cache data where loss is acceptable (data reconstructable from primary DB), we use RDB with 15-minute snapshots. Critical data never lives only in Redis.
License Complexity (Redis vs Valkey)
Redis changed from BSD to SSPL/RSALv2 in March 2024, then AGPL in May 2025. Enterprise compliance teams need to evaluate AGPL compatibility with their software distribution model. Valkey (BSD license, Linux Foundation) solves this for teams where AGPL is a concern.
We evaluate the license implications for each client's specific deployment context. For internal-use caching layers, AGPL has no practical impact. For SaaS vendors distributing software that includes Redis, we recommend evaluating Valkey as a drop-in API-compatible alternative.
No Complex Query Language
Redis has no SQL or query language. Querying across keys requires knowing key patterns, using SCAN for pattern matching, or structuring secondary indexes manually with Sets. This limits Redis to access patterns known at design time — ad-hoc queries against Redis data are impractical.
Redis is used for pre-defined access patterns, not arbitrary queries. Analytical queries on cached data belong in the primary database. We design Redis key schemes that map exactly to application access patterns — cache lookup by user ID, rate limit by IP, leaderboard by game ID.
Redis Alternatives & Comparisons
We use all of these in production — the right choice depends on your project's constraints, team familiarity, and scale requirements.
Redis vs Valkey
Learn More About ValkeyValkey Advantages
- •API-identical to Redis — zero application code changes to migrate
- •8% more ops/sec, 22% lower P99 latency, 20% less memory vs Redis OSS
- •BSD license — no AGPL compliance concerns
- •Ubuntu 26.04 LTS default, AWS/Google/Oracle backing
Valkey Limitations
- •Newer ecosystem — community smaller than Redis's established footprint
- •Redis-specific managed services (Redis Cloud, Redis Enterprise) don't apply
- •Some Redis modules have no Valkey equivalent yet
- •Less documentation and community content than Redis
Valkey is Best For:
- •Teams concerned about Redis's AGPL license
- •AWS ElastiCache deployments (20% cost savings with Valkey tier)
- •New deployments on Ubuntu 26.04 LTS
When to Choose Valkey
Valkey is the right choice for new deployments where Redis's AGPL license creates compliance concerns, or where cost savings on managed infrastructure matter. API compatibility means the switch is transparent to applications — the decision is infrastructure, not development.
Redis vs PostgreSQL
Learn More About PostgreSQLPostgreSQL Advantages
- •Durable — data persists reliably with WAL and ACID guarantees
- •SQL query language handles ad-hoc analytical queries
- •pgvector for AI vector search alongside relational data
- •No separate operational system — one database for everything
PostgreSQL Limitations
- •10-50ms typical query latency vs Redis's 0.1-0.3ms
- •Cannot serve as a high-throughput real-time cache effectively
- •No native sorted set, pub/sub, or Bloom filter implementations
- •Connection overhead makes it unsuitable for rate-limiter hot paths
PostgreSQL is Best For:
- •Primary persistent data storage
- •Complex queries and relational integrity
- •Applications where sub-millisecond latency isn't required
When to Choose PostgreSQL
PostgreSQL and Redis serve different roles — use both. PostgreSQL is your primary data store with ACID guarantees; Redis is the hot caching and real-time layer in front of it. The combination is the industry standard for production SaaS architectures.
Redis vs MongoDB
Learn More About MongoDBMongoDB Advantages
- •Persistent document storage with Atlas Vector Search for AI
- •More expressive query language than Redis
- •Horizontal scaling via sharding for large datasets
- •Atlas integrates search, vector, and operational data in one platform
MongoDB Limitations
- •Disk-based — 10-50ms latency vs Redis's sub-millisecond
- •No native pub/sub, rate limiting primitives, or sorted sets
- •Not a cache layer — it's a primary data store
- •More operational complexity for workloads that only need caching
MongoDB is Best For:
- •Document data with flexible schemas
- •AI-native applications with vector search requirements
- •Primary persistent data store for MongoDB-centric architectures
When to Choose MongoDB
MongoDB and Redis serve complementary roles, not competitive ones. MongoDB stores persistent documents; Redis caches the hot subset of MongoDB data. Use both in production architectures that need flexible storage and sub-millisecond read performance.
Why Choose Code24x7 for Redis Development?
Redis is easy to start with and easy to misuse. We've seen Redis deployments where the memory grew unbounded until the server swapped (eviction policy never configured), where cache invalidation bugs caused stale data to persist indefinitely (no TTL), and where Pub/Sub lost messages during reconnects (no Streams, no acknowledgment). We understand Redis at the architectural level — which data structure serves each access pattern, how eviction interacts with TTL, when Streams replace Pub/Sub, and how Cluster partitioning affects multi-key commands. We build Redis layers that do what they're supposed to do — make your application faster and more reliable.
Cache Architecture & Key Design
We design cache key schemas that map directly to application access patterns — namespace:entity_type:id hierarchies that enable efficient SCAN-based pattern invalidation. Eviction policies (allkeys-lru, volatile-lfu) are configured based on your data access distribution. Cache warming strategies prevent cold-start latency spikes after deployments.
Redis Cluster Design & Scaling
We design shard key distributions that avoid hash tag clustering anti-patterns. Multi-key commands (MGET, SUNIONSTORE) are handled via hash tags that co-locate required keys on the same shard. Cluster topology is designed with replication factor and failure domain separation appropriate for your availability requirements.
Redis vs Valkey Evaluation
We evaluate the Redis vs Valkey decision for every Redis engagement — AGPL compliance implications, managed service cost differential, existing tooling ecosystem, and migration complexity. Valkey is API-identical; the switch is infrastructure, not code. We make the recommendation based on your specific licensing, cost, and operational context.
Persistence & Durability Configuration
We configure RDB and AOF persistence appropriately for each data tier — AOF with everysec for session stores, RDB snapshots for pure caches. We document exactly what data survives a Redis restart and what doesn't — no 'I thought it was persistent' surprises in production.
Pub/Sub & Streams Implementation
We implement Redis Streams for durable inter-service messaging with consumer groups and acknowledgment semantics — the correct pattern for events that must not be lost. Redis Pub/Sub is reserved for fire-and-forget real-time notifications where message loss is acceptable. We choose based on your delivery guarantee requirements.
Rate Limiting & Distributed Locking
We implement sliding window rate limiting with Lua scripts that atomically check and update counters in a single round trip. Distributed locks use SET NX PX with Redlock for multi-instance mutual exclusion. Both patterns are tested under concurrent load to verify atomicity guarantees hold at production request rates.
Projects Using This Technology
Business Intelligence Dashboard
A business intelligence dashboard for our client that unified 20+ data sources and cut report generation time from hours to minutes. The platform processes 10M+ data points daily and has driven $500K in annual cost savings through operational insights.
SaaS Project Management Platform
A multi-tenant SaaS project management platform for the client that scaled from 500 beta teams to 50,000+ active users with 300% MRR growth in 6 months — running at 99.95% uptime while handling 100,000+ concurrent users at peak.
Services That Use This Technology
Questions from Developers and Teams
Valkey is an open-source fork of Redis created in March 2024 by the Linux Foundation after Redis Inc. changed its license from BSD to SSPL/RSALv2. It's backed by AWS, Google Cloud, Oracle, and Ericsson, with the former lead Redis maintainers as core contributors. Valkey 8.1 benchmarks 8% more ops/sec, 22% lower P99 latency, and 20% less memory than Redis OSS. Amazon ElastiCache offers Valkey at 20% lower cost. Ubuntu 26.04 LTS ships Valkey as its default redis-server package. The API is identical to Redis — migrating is a configuration change, not a code change. For new deployments: evaluate Valkey first, especially on AWS or Ubuntu 26.04. For existing Redis: the switch only matters if AGPL licensing or cost savings are driving factors.
Redis 8.0 was a major consolidation release: JSON (RedisJSON), TimeSeries (RedisTimeSeries), probabilistic data structures (Bloom filters, Cuckoo filters, Count-Min-Sketch, Top-K), vector sets for AI/semantic search, and hybrid search capabilities moved from separate Redis Stack modules (requiring paid licensing in production) into the open-source Redis core. This is significant — it means teams can use Redis for semantic search, time-series data, and probabilistic operations without the complexity of Redis Stack licensing. The trade-off is that Redis 8.0 also came with the license change that created Valkey.
No, for most applications. Redis is designed as an in-memory data structure store — memory-bound, with durability as a secondary concern. AOF persistence gets you near-zero data loss, but Redis is architecturally optimized for speed over durability. Critical business data (orders, payments, user accounts) belongs in PostgreSQL or MongoDB with Redis caching the hot subset. There are specific use cases where Redis as primary store makes sense — leaderboards with no backup requirement, ephemeral session data, rate limit counters — but it's the exception, not the rule.
Cache invalidation is the hardest Redis problem. The approaches we use in production: (1) TTL-based expiry — every cache key gets a TTL; stale data expires automatically; simplest but may serve stale data until TTL expires. (2) Write-through invalidation — when source data changes, delete the cache key immediately; guarantees freshness but requires careful coordination in distributed systems. (3) Tag-based invalidation — store sets of related cache keys under a tag key; when the tagged entity changes, SMEMBERS the tag set and DEL all members. Each approach has tradeoffs; we choose based on your consistency requirements and cache hit rate targets.
Pub/Sub: fire-and-forget. Messages are delivered to subscribers connected at the moment PUBLISH is called. No message persistence, no delivery acknowledgment, no consumer groups. Suitable for real-time notifications where missing a message is acceptable (live dashboards, presence indicators). Streams (XADD, XREADGROUP, XACK): persistent, durable message queues with consumer groups and acknowledgment. Messages survive connection drops and consumer failures. Each consumer group tracks its own read position; XACK confirms processing. Suitable for inter-service event streaming where message loss is not acceptable. We use Streams for everything that matters; Pub/Sub for display-layer real-time features.
Three levers: (1) Eviction policy — set maxmemory and maxmemory-policy. For caches, allkeys-lru evicts least-recently-used keys when memory is full. For mixed cache/persistent stores, volatile-lfu evicts only keys with TTL. Never leave maxmemory unset in production. (2) Key TTLs — every cache key should have a TTL. Keys without TTL accumulate indefinitely. We audit Redis keyspaces with SCAN and DEBUG OBJECT to find keys without expiry. (3) Data structure selection — HASH uses less memory than N separate STRING keys for the same object data; Redis's object encoding optimization compresses small hashes into ziplist format automatically.
Redis Cluster assigns 16,384 hash slots distributed across primary nodes. Each key maps to a slot via CRC16(key) % 16384. When a client sends a command to the wrong node, the node responds with MOVED slot destination_ip:port — the client should retry the command at the correct node. Modern Redis clients (ioredis, Lettuce, Jedis) handle MOVED redirects transparently. Hash tags override key-to-slot mapping: {user:123}:session and {user:123}:cart are forced to the same slot, enabling multi-key operations on data that logically belongs together.
Yes, Redis 8.0 integrates vector sets natively. VADD adds vectors, VSIM performs approximate nearest-neighbor search using HNSW, and VRANGE combines vector similarity with key filters. For applications already using Redis for caching where vector search is a secondary requirement, this eliminates a separate vector database deployment. The honest comparison: pgvector (PostgreSQL) and MongoDB Atlas Vector Search are more mature for production AI workloads with richer tooling. Redis vector sets are best suited for teams that want semantic search co-located with their existing Redis caching layer without adding infrastructure complexity.
Sliding window rate limiting with sorted sets is the most accurate approach: ZADD key:client_id timestamp timestamp; ZREMRANGEBYSCORE key:client_id 0 (now-window_ms); count = ZCARD key:client_id; if count >= limit reject. The critical requirement: the ZADD + ZREMRANGEBYSCORE + ZCARD sequence must be atomic — wrap in a Lua script. Alternative: fixed window with INCR + EXPIRE. Simpler but allows 2× the rate limit at window boundaries (burst at end of one window + start of next). Token bucket (maintained with HINCRBY + time calculation) allows configurable burst capacity. We choose based on your API's burst tolerance requirements.
Redis open-source (or Valkey) is free. Managed infrastructure: Redis Cloud Essentials from $0 (30MB free tier) to $200+/month for production clusters; AWS ElastiCache (Redis or Valkey) from ~$25/month for a cache.t3.micro to $500+/month for production-grade clusters; Valkey on ElastiCache runs 20% cheaper than the Redis tier. Development cost depends on cache architecture complexity, cluster configuration, data structure patterns, and integration scope. We scope specifically — describe your use case, traffic patterns, and data volume and we'll provide a detailed estimate.
Still have questions?
Contact Us
What Makes Code24x7 Different
The question we ask at the start of every Redis engagement: what specific latency problem are you solving? If the answer is vague, we help you measure first. Redis added without a measured bottleneck is complexity without benefit. Redis added to the right architectural tier — cache in front of the database, sessions in front of auth, rate limiter in front of the API — is one of the highest ROI infrastructure investments you can make. We know the difference.

