Kensink Labs
★ RedisTechnologies & InfrastructureIn-memory data platform
REDIS · THE FAST LAYER YOUR DATABASE NEEDS

Redis. The unsung hero of fast software.

Your SQL database is the source of truth. Redis is the speedster that stands in front of it, answering most requests in microseconds so the database never has the breakdown. This is a field guide to what Redis is, why it is so fast, the patterns that matter, and how it quietly powers modern AI apps.

RedisCachingStreamsVector searchPostgreSQL
NEWRedis 8.8 just shipped.The latest release sharpens the data platform for real-time and AI workloads.Read the announcement
LATENCY
Sub-millisecond
THROUGHPUT
1M+ ops/sec
DATA TYPES
8 core + vectors
SINCE
2009, battle-tested
[THE SHORT VERSION]

A data structure server that lives in memory.

Redis stands for Remote Dictionary Server. It keeps data in RAM, which is why it answers in microseconds while a disk-bound database works in milliseconds. But calling it a key-value store undersells it. Redis ships purpose-built data structures, lists, sets, sorted sets, streams, and more, each tuned for a specific job. You are not bending a generic store to your problem. You are picking the right tool for it.

Where it fits
  • Caching expensive or hot reads
  • Sessions shared across many servers
  • Rate limiting and atomic counters
  • Lightweight queues and pub/sub
  • Vector search and semantic caching for AI
Where it does not
  • As your only source of truth
  • For data larger than memory you cannot shard
  • For complex relational queries and joins
  • Where full ACID transactions are mandatory
[WHY IT MATTERS]

Comparing Redis to PostgreSQL is comparing a Ferrari to a freight train.

Both are useful. They do different jobs. Redis is not here to replace your database. It stands in front of it like a bouncer, handling the requests that would otherwise pile up at the door.

Aspect
Redis
PostgreSQL / MySQL
Speed
Microseconds (in-memory)
Milliseconds (disk-bound)
Model
Specialized data structures
Relational tables, schemas
Transactions
Atomic commands, MULTI/EXEC
Full ACID guarantees
Persistence
Optional, for speed
Mandatory, for durability
Best role
Fast layer, cache, broker
The source of truth
[THE TOOLBOX]

Data structures that match the job.

This is where Redis stops being a key-value store and becomes a data structure server. Every type below is sharpened for a specific use case.

String
Values up to 512MB
Caching, atomic counters, API tokens
Hash
Field-value maps
User profiles, config objects, sessions
List
Ordered sequences
Job queues, activity logs, buffers
Set
Unique collections
Tags, unique IDs, membership tests
Sorted Set
Scored rankings
Leaderboards, priority queues, time ranges
Bitmap
Bit-level ops
Activity tracking, feature flags, A/B
HyperLogLog
Approximate counts
Unique visitors without storing every ID
Stream
Append-only log
Event sourcing, durable queues, audit trails
And the extensions, now in the open-source core
Vector search

Similarity search on embeddings, native to the core. RAG without a second database.

JSON

First-class documents with path queries. Update a field without round-tripping the whole object.

Search

Secondary indexing and full-text query over hashes and JSON.

Time series

Downsampling, retention, and range queries for metrics and IoT.

Probabilistic

Bloom and Cuckoo filters, Count-Min Sketch. Dedupe and count at scale, cheaply.

Semantic cache

Cache LLM responses by meaning, not exact string. Cut token spend and latency.

[DESIGN THE DATA MODEL]

Redis rewards a data model designed on purpose.

This is the part teams skip and regret. Redis does not impose a schema, so the discipline has to come from you. Get the key design and the data structures right and Redis is a quiet, fast asset. Get them wrong and it is the most expensive cache you will ever run.

Keys are your schema
user:123:profilehash · the user object
user:123:sessionsset · active session tokens
leaderboard:weeklysorted set · score = points
rate:ip:1.2.3.4string · counter, EX 60
cache:product:42:v5JSON · versioned for safe rollover

Namespaced, predictable, versioned. A good key tells you what it holds, who owns it, and how to invalidate it without a guess.

Let the query pick the structure
Atomic counterString + INCR
Object with fieldsHash
Ranking, top-NSorted Set
Durable queue, event logStream
Membership, tagsSet
Similarity, RAGVector

Choosing the right type is most of the performance win. Design from the access pattern, not from the entity diagram.

The principles we hold to
01

Model the access pattern, not the entity

In SQL you model the data and query it later. In Redis you design the key for how it will be read and written. Start from the queries: what do you fetch, by what id, how often, and pick the structure that answers that in one round trip.

02

One structure per job

A leaderboard is a sorted set, not a list you sort in the app. A session is a hash, not a JSON string you parse every read. Choosing the right type is most of the performance win, and it is a design decision, not an afterthought.

03

Keys are a schema

Namespaced, predictable keys (app:entity:id:field) are your schema. They make scanning, invalidation, and migration sane. A version segment (user:123:v5) lets you roll a cache format without a flush.

04

Every key has a lifecycle

Set a TTL by default and decide expiry on purpose. Untracked, immortal keys are how a Redis quietly fills memory and starts evicting the wrong things at the worst time.

05

Memory is the budget

Size values, compress large ones, and pick an eviction policy that matches priority (allkeys-lfu for a pure cache, volatile-lru when some keys must survive). Watch for big keys and hot keys; split or shard them before they become an incident.

06

Make it atomic

Reach for native atomic commands (INCR, SETNX), MULTI/EXEC, or a Lua script instead of read-modify-write in the app. Under concurrency, the app-side version is a race waiting to corrupt a counter or a balance.

07

Separate ephemeral from durable

Sessions, caches, and rate-limit counters have different durability, eviction, and backup needs than data you cannot recompute. Keep them in different instances or logical databases so one policy does not have to fit both.

08

Redis derives, the database owns

Treat Redis as a fast projection of a source of truth that lives elsewhere. Then a flushed cache or a lost node is a rebuild, not a data-loss incident. The discipline that keeps Redis an asset and not a liability.

[DEPLOYMENT]

A ladder you climb only when the workload forces you.

Redis scales in rungs. Each one adds resilience or capacity, and a little operating cost. Start at the bottom and climb only when the workload makes you. The four diagrams below are the topologies that matter in production.

01Standalone
One instance. The simplest thing that works, and the fastest to reason about.
Climb when: Fine for dev, prototypes, and caches you can afford to lose. No failover: if the node dies, the data and the service go with it.
02Primary + replicas
Reads fan out across replicas and you get a warm copy for backups.
Climb when: Climb here when reads outgrow one node or you want a backup that does not touch the primary. Still a manual failover (see Pattern A).
03Sentinel HA
Automatic failover. Sentinels watch, vote, and promote a replica with no human in the loop.
Climb when: Climb here the moment an unplanned primary death is unacceptable, and the dataset still fits one machine (see Pattern C).
04Cluster
The keyspace is sharded across many primaries, scaling memory and write throughput linearly.
Climb when: Climb here when the data or the write rate exceeds what one machine can hold or serve (see Pattern B).
05Active-Active
Full clusters in multiple regions, each serving local writes, merged conflict-free.
Climb when: Climb here for global low-latency writes and surviving a whole region outage. The most complex rung. Most products never need it (see Pattern D).
Redis Pattern A, a primary with read replicas. Writes go to one primary. Reads fan out across replicas, so a read-heavy app scales horizontally. Replication is asynchronous, so replicas can lag by milliseconds. Pair this with Sentinel and a failed primary is promoted automatically.
Redis Pattern C, Sentinel automatic failover. Three Sentinel processes watch the primary and replicas. When the primary stops answering, they reach a quorum, promote the healthiest replica, and tell clients the new address. No human at 3am. Sentinel gives a non-sharded deployment real high availability.
Redis Pattern B, a sharded self-healing Redis Cluster. Cluster shards the keyspace across primaries M1 to M3, each with a replica. Nodes track each other over a gossip protocol, so the cluster detects failures and reshards without a central coordinator. This is how Redis scales past one machine's memory.
Redis Pattern D, an Active-Active geo-distributed deployment. Each region runs a full cluster and serves its own clients at local latency. Regions sync bidirectionally with conflict-free replicated data types (CRDTs), so concurrent writes in different regions merge deterministically. Survives a whole region going dark.
Where it runs: managed, serverless, or your own
AWS ElastiCache

Managed Redis on AWS, with cluster mode and Multi-AZ failover.

Google MemoryStore

Managed Redis on GCP, replication and HA tiers.

Azure Cache for Redis

Managed on Azure, including Enterprise (Active-Active) tiers.

Redis Cloud

First-party managed, Active-Active, and the newest modules first.

Upstash

Serverless, per-request pricing, designed for edge and Lambda.

Self-hosted / K8s

Full control via the Redis Operator. You own tuning, upgrades, and the pager.

Managed services take the pager for failover, patching, and backups, at a premium and with less tuning control. We help you pick the rung and the host that fit the workload, then hand over infrastructure as code either way.

[PERSISTENCE]

In-memory, but not amnesiac.

Redis lives in RAM, so a naive setup loses everything on restart. It does not have to. Three durability modes trade speed against how much you can afford to lose.

RDB snapshots

fast recovery

A point-in-time fork of the dataset to disk. Compact, quick to load, ideal for backups. The trade is the window between snapshots, which is lost on a crash.

Best for: Backups and fast restarts

AOF log

durability

Every write command is appended to a log and replayed on startup. Slower writes, far smaller loss window. The choice when the data actually matters.

Best for: Minimal data loss

Hybrid

production default

An RDB snapshot for fast recovery plus an AOF tail for the writes since. You get quick startup and a tiny loss window. This is what we run in production.

Best for: Use this
[PATTERNS THAT EARN THEIR KEEP]

The handful of patterns that do most of the work.

Redis is not magic, it is architecture. These are the patterns we reach for again and again, with the core commands behind each.

01

Cache-aside

The default. Check the cache, fall back to the database on a miss, write the result back with a TTL. Resilient: if Redis is down, the app still works, just slower.

GET keymiss → query DBSET key value EX ttlreturn
02

Write-through / write-behind

Write-through keeps cache and database in lockstep for strong consistency. Write-behind acknowledges from Redis instantly and flushes to the database in the background for raw write speed.

write Redis→ write DB (sync or async)ack
03

Rate limiting

Atomic counters with a TTL give you distributed rate limiting that actually holds across many servers. One INCR, one EXPIRE, a decision in microseconds.

INCR user:rlEXPIRE 60 (first hit)over limit → reject
04

Distributed locking

SET NX with a unique token and a timeout gives one worker exclusive access across a fleet. Prevents double-charging, duplicate jobs, and racing cron runs.

SET lock val NX PX 30000own it → workDEL lock when done
05

Pub/Sub & cache invalidation

Publish a change event and every service drops its stale copy. Keeps distributed caches coherent. For delivery you can rely on, reach for Streams instead.

update DBPUBLISH user:123:invalidatesubscribers clear cache
06

Streams & event sourcing

An append-only log with consumer groups. Multiple services read the same events independently, track their own position, and replay history to rebuild state.

XADD events * ...consumer groups track offsetreplay = rebuild state
[REDIS FOR AI]

The same speed, now under your AI stack.

AI apps put new demands on data: embeddings to search, LLM calls to cache, conversations to remember. Redis spent fifteen years getting fast at exactly the things these workloads need.

Vector search

Store embeddings next to their metadata and run similarity search in one system. Simpler RAG, fewer moving parts.

Semantic cache

Cache LLM answers by meaning. A near-identical question hits the cache, not the model, cutting cost and latency.

Agent memory

Short-term state between steps and long-term history across sessions, with LangChain, LangGraph, and LlamaIndex integrations.

Feature & rate control

Per-tenant rate limits and feature flags for AI features, enforced atomically across every server.

In 2024 Redis folded vector search, JSON, and search into the open-source core. For most retrieval workloads that means one less database to operate, sync, and secure.

[AI-ASSISTED DEVOPS]

Deploying Redis with an AI in the loop.

An assistant can stand up Redis infrastructure fast. Speed is the easy part. These are the guidelines we hold to so AI-assisted DevOps stays an accelerator and not an outage generator.

01

Generate the infra, review the failure modes

Let an assistant scaffold the Terraform or Helm for your chosen rung, then have a human review exactly the parts AI gets wrong under pressure: failover behavior, persistence (RDB plus AOF), eviction policy, and memory limits. The boilerplate is automatable. The durability decisions are not.

02

Codify the key schema as a registry

Have AI maintain a typed registry of key patterns and TTLs (the schema from the section above) and the thin cache-layer abstraction over it. The app never sprinkles raw key strings, and the model has one place to reason about your data model.

03

AI writes the runbooks, you run the drill

Generate runbooks for the operations you hope never to need: failover, restore from snapshot, and resharding. Then actually rehearse them in staging. An untested runbook, AI-written or not, is a guess.

04

Eval and load-test as code

AI scaffolds the load test and the eval harness; you set the SLOs that decide pass or fail: p99 latency, cache hit rate, and behavior under eviction. Numbers gate the deploy, not vibes.

05

Observability wired from the first commit

Have the assistant emit dashboards and alerts for hit rate, latency, evictions, and memory fragmentation alongside the infra. Observability written after an incident is observability you did not have during it.

06

Guardrails on the agent

An AI operator gets least-privilege ACLs, never FLUSHALL, KEYS, or CONFIG SET on production, plan-and-approve before any apply, secrets from a vault not the prompt, and staging before prod. Speed from automation, safety from the rails around it.

The one rule that matters: the AI proposes, a human approves anything that touches production durability or data. Generated infrastructure, runbooks, and dashboards get reviewed against the data model and the failover behavior before they ship. That is how you get the speed without betting the database on it.

[HOW IT GOT HERE]

One technology, adapting through every era.

Redis kept its principles, simplicity and speed, while growing from a caching layer into a full data platform. The short version of a long run.

  1. 2009

    Born at a startup to fix a workload SQL could not. Strings, lists, sets, sorted sets. Open-sourced on Hacker News.

  2. 2010

    Pub/Sub and Hashes. Redis becomes a messaging backbone, not just a cache.

  3. 2012

    Lua scripting. Atomic, server-side logic, no race conditions.

  4. 2015

    Redis Cluster. Horizontal scale past one machine's memory.

  5. 2018

    Streams. A durable, replayable log for event-driven systems.

  6. 2024

    Vector search, JSON, and search fold into the open-source core. Redis goes AI-native.

  7. 2025

    Redis 8.8. The latest release sharpens the data platform for real-time and AI workloads.

[DISCIPLINE, NOT MAGIC]

A healthy Redis is a happy Redis.

The difference between a Redis that saves your database and one that becomes a new liability is operational discipline. The short list we hold ourselves to.

Do
  • Namespace keys: service:entity:id
  • Put a TTL on everything
  • Pick an eviction policy on purpose (allkeys-lfu, volatile-lru)
  • Pool connections; never one per request
  • Add circuit breakers so the app degrades gracefully
  • Watch hit rate, latency, and memory fragmentation
Don’t
  • Treat Redis as your only source of truth
  • Mix ephemeral and persistent data in one instance
  • Run KEYS * or FLUSHALL in production
  • Store large blobs uncompressed
  • Use Pub/Sub for messages you cannot lose
  • Ship it without monitoring
[COMMON QUESTIONS]

Questions we get asked.

Is Redis a database or a cache?
Both, and that is the point of confusion. Redis is an in-memory data store. Most teams first meet it as a cache in front of PostgreSQL, but it is also a capable primary store for the right workloads, a message broker, a rate limiter, and now a vector store for AI. We treat your relational database as the source of truth and let Redis be the fast layer in front of it unless a workload genuinely calls for more.
Will I lose data if Redis restarts?
Only if you configure it to. Redis keeps data in memory for speed, but it persists to disk with RDB snapshots, an append-only file (AOF), or both. Production runs the hybrid mode: fast recovery from snapshots plus minimal loss from the AOF. We tune the durability knobs to the data, sessions and caches can be looser, anything you cannot recompute is not.
Redis or just add more PostgreSQL?
Postgres is remarkably capable and we reach for it first. Redis earns its place when you need sub-millisecond reads on hot data, atomic counters at high write rates, rate limiting, sessions shared across servers, lightweight queues, or pub/sub fan-out. The test is simple: if the database is doing repeated, expensive work to answer the same question, a cache in front of it is usually the cheaper win.
Do I still need a separate vector database for RAG?
Often no. Since Redis folded vector search, JSON, and search into the core, you can store embeddings next to their metadata and run similarity search in one system. For small to mid-scale retrieval that removes a whole moving part. A dedicated vector store earns its place at large scale or with specialized indexing needs.
How do you keep Redis from becoming a liability?
Discipline. Namespaced keys, a TTL on everything, an eviction policy chosen on purpose, connection pooling, circuit breakers so the app degrades gracefully when Redis is unavailable, and no KEYS or FLUSHALL in production. We also make it observable: hit rate, memory fragmentation, and latency tracked from day one.
DEPLOY HIGH-PERFORMANCE REDIS

Save your database
from the crash.

Most outages are a database doing the same expensive work over and over until it falls over. Redis, deployed with discipline, takes that pressure off. We design the cache strategy, the invalidation, the failover, and the observability, then hand you the source. Clear TTLs, real monitoring, no lock-in.