Redis development for caching, queues and real-time features

Redis is an in-memory data store that the Redis documentation describes as usable as a database, cache, streaming engine and message broker. We use it behind web and mobile products for caching, background job queues, short-lived state such as sessions, and real-time features, and we are careful about what it should not be trusted with.
Redis
  • Caching in front of a slower database
  • Queues and background jobs
  • Short-lived state with expiry times
  • Persistence and security set up on purpose

When Redis is the right choice

Redis suits workloads that are fast, small and can tolerate its trade-offs:

  • You want a cache in front of a slower store. Cached entries are copies of data kept elsewhere, so evicting them is usually safe.
  • You need queues or event processing. Lists suit simple queues, and streams suit event processing with at-least-once delivery.
  • A small set of keys receives most of the reads. Redis eviction policies are designed for that pattern.
  • You have short-lived state with a natural lifetime, such as counters, rate-limit windows or sessions, and want expiry times and atomic operations.

When Redis is not the right choice

Redis is not the answer to every data need:

  • Your data set must fit in memory. Redis keeps its data in RAM, and you cap it with a memory limit.
  • You cannot lose any data. Snapshots can lose the most recent minutes, the append-only log can lose about a second with the usual setting, and acknowledged writes can be lost in a failover. Keep a durable database as the system of record.
  • Untrusted clients would connect directly. Redis is designed to be reached by trusted clients inside trusted environments, so mobile apps and browsers should go through your application.
  • You need rollback. Redis transactions run commands together but do not roll back.

What we build with Redis

Typical projects, described in general terms.

Caching

Keeping the results of slow queries or API calls in memory with expiry times, so pages and endpoints answer faster.

Queues and background jobs

Lists or streams that feed workers for emails, imports, reports and other work that should not block a request.

Sessions and counters

Short-lived state with a time to live, and atomic counters for limits and quotas.

Real-time messaging

Publish and subscribe for live updates, and streams when messages must not be lost if a consumer is down.

Secure setup

Access control lists, encrypted connections, and a firewall so the server is never exposed to the open internet.

Capacity and persistence

Choosing a memory limit, an eviction policy and a persistence setting that match what the data is worth.

What Redis gives you

Redis stores strings, hashes, lists, sets, sorted sets and streams, and its documentation also lists JSON, geospatial, bitmap and probabilistic types. Keys can expire on their own. Publish and subscribe sends messages to channels with at-most-once delivery, while streams are an append-only log that persists messages and supports at-least-once delivery. Transactions and Lua scripts run commands in isolation. Client-side caching lets an application keep copies of keys that the server invalidates when they change.

For durability, Redis offers snapshots, an append-only file, both together, or neither, which is sometimes chosen for a pure cache. Replication is asynchronous by default, and Redis Cluster shards data across nodes. Access control lists limit each user to chosen commands, keys and channels, and connections can use TLS.

What we get right when running it

  • Memory and eviction: with the no-eviction policy, writes return errors at the memory limit, and policies that evict only keys with expiry times behave the same when no keys have one. We choose the policy to match how the application reads, and leave memory free for replication and persistence buffers.
  • Durability: the default append-only setting writes to disk every second. A primary with persistence turned off that restarts empty can wipe its replicas, so we plan restarts as well as backups.
  • Key names: Redis has no namespaces, so we use a clear object-type:id pattern and keep keys short.
  • Security: the default user has no password, so the server is never exposed directly. We set access control lists, use TLS, and firewall the port.
  • Slow commands: Redis mostly runs commands on one thread, so a slow command or a KEYS call stalls every client. We use SCAN and watch the slow log.
  • Connections: long-lived connections with pooling. Multiplexing cannot support blocking pops.

How we work

  1. Decide what it is for: a cache, a queue, short-lived state or a data store, because each needs different settings
  2. Set the limits first: memory limit, eviction policy and persistence, written down with the reason
  3. Lock it down: access control lists, TLS and a firewall before any data goes in
  4. Hand over properly: the configuration in your repository, and notes on what happens when the server restarts or fills up

Frequently asked questions

Is Redis a replacement for our main database?

Redis documents data-loss windows: minutes with snapshots, about a second with the append-only log, and possible loss of acknowledged writes in a failover. Whether it can be a system of record depends on how much loss is acceptable. For most business data, it sits beside a durable database.

What happens when the cache fills up?

It depends on the eviction policy. With no eviction, new writes get errors. With a policy such as allkeys-lru, Redis evicts keys to stay under the limit. We choose the policy to match how your application reads its data.

Can mobile or browser clients talk to Redis directly?

Redis's security documentation says it is designed for trusted clients in trusted environments, so untrusted access should go through an application layer, and the Redis port should be firewalled.

Is publish and subscribe reliable enough for job queues?

Publish and subscribe is at-most-once, so a message is lost if no subscriber is listening. For stronger guarantees, Redis points to streams, which persist messages and support at-least-once delivery.

Adding Redis to your product?

Tell us what you want it to speed up or hold. We will say whether Redis fits and what it should never be trusted with.

Related technologies

Technologies that appear alongside Redis in our case studies. Select one to see our work with it.

Three ways to work with us

Dedicated Hiring

Meet our team in an online meeting, interview the specialists and hire a dedicated team for your project.

Get a Quote

Fixed Scope

You share your requirements, we agree the scope and cost up front, and deliver against that scope.

Get a Quote

Time & Material

Best when the scope will change as you learn. You pay for the time and resources used, and you can adjust priorities as the work goes on.

Get a Quote

Tell us about your project