The claim goes: “Redis handles hundreds of thousands of operations a second, so let us use it as the main database for orders.” The first half is true. The second does not follow from it, and the gap between them is where data gets lost.

Redis is an excellent piece of software. This is not an argument against it. It is an argument about what a primary database is for, and about asking the right questions before choosing.

Myth one: fast means good for everything

Redis is quick mainly because it keeps its working data in memory and uses simple data structures with a single-threaded command execution model. That design gives it very low latency. It also means the cost per gigabyte is much higher than disk, and the whole dataset must fit in RAM (spread across nodes in a cluster). An order history that grows by several gigabytes every month will become an expensive memory bill long before it becomes a performance problem.

A primary database is judged on correctness and recoverability first. Speed is third or fourth on the list. An order system that answers in a millisecond but forgets last Tuesday’s orders after a crash has failed at its one job.

Myth two: “it persists to disk, so it is durable”

Redis does offer persistence. There are two main mechanisms, and understanding them matters.

  • Snapshots (RDB). Redis writes a point-in-time copy of the dataset at intervals. Anything written after the last snapshot is lost in a crash. If snapshots happen every few minutes, you may lose minutes of orders.
  • Append-only file (AOF). Redis logs every write command. How safely depends on the sync setting. The usual default is to sync to disk about once per second, so a crash can lose roughly the last second of writes. A stricter setting syncs after every write, which is much safer but reduces throughput, removing some of the speed that attracted you in the first place.

So Redis can be configured to be quite durable, but a default or lightly tuned setup is not equivalent to a database that has acknowledged a commit only after the write is safely on disk. For payments or orders, “we might lose the last second” has to be a conscious business decision, and finance usually disagrees when asked.

Replication adds another subtlety. Redis replicas are normally updated asynchronously, so if the primary dies and a replica is promoted, writes the primary had acknowledged but not yet sent can vanish. Redis has a command that waits for a given number of replicas to acknowledge a write, which narrows the window, though the documentation itself describes it as not providing strong consistency in every failure scenario. Compare this with databases like PostgreSQL, where synchronous replication and write-ahead logging are designed around not losing committed transactions.

Myth three: it is a drop-in replacement for a relational database

Orders are relational by nature: a customer, items, addresses, payments, refunds, and reports that cut across all of them. Redis stores values by key. Looking up an order by its ID is trivial. Finding “all orders from Chennai last week that are still unpaid” is not, unless you have built and maintained your own indexes using sets and sorted sets, and kept them consistent by hand. There are modules and extensions that add search capabilities, but you are then relying on more moving parts.

Transactions work differently too. Redis offers command batching with atomic execution and optimistic watching of keys, and server-side scripting for atomic logic. These are useful tools. But they do not give you the rollback behaviour, constraints, foreign keys and flexible isolation levels that a relational engine provides. Business rules that a database would enforce for free, such as “an order must reference a real customer”, move into application code, where each bug is a possible data corruption.

Operational concerns follow: backups and point-in-time recovery, schema evolution, auditing, and the familiarity of your team and of your tooling, from analytics to compliance reports. Any of them can be solved. Each is a cost that a conventional database simply has built in.

Questions worth asking in a design review

  1. If the server crashes right now, how much data is acceptable to lose, and who signed that off?
  2. What is the dataset size in a year and in three years, and what will that cost in memory?
  3. Which queries must we answer beyond lookup by key, and how will they be served?
  4. Where is the authoritative record if Redis and another system disagree?
  5. How do we restore to a point in time after a bad deployment or a deleted key?
  6. What does failover do to in-flight writes?

Where Redis genuinely shines

The recommendation is not to avoid it. Redis is very good as a cache in front of a durable database, for session storage, rate limiting, leaderboards, short-lived locks, queues where occasional loss is tolerable, and counters. In these cases data is either rebuildable or low-value if briefly lost. A common healthy design is to keep orders in a relational database, which is the source of truth, and use Redis to hold copies for fast reads, such as the order-status page that gets hit by customers every few seconds.

If a team still wants Redis as a primary store for some data, the realistic path is to constrain the use: data that fits in memory comfortably, access almost entirely by key, strict durability settings tested by deliberately killing the server, and a documented recovery plan. Many teams that do this find, after the testing, that a database like PostgreSQL would have been fast enough all along. A well-indexed relational database can serve many thousands of simple queries per second on modest hardware, which covers most Indian mid-sized businesses by a wide margin.

Leave a Reply

Trending