Video in progress

Can you use Redis as the main database instead of PostgreSQL?

In some cases yes, but usually no. Redis has no SQL queries, JOINs, secondary indexes or full ACID transactions, all the data has to fit in RAM, and persistence may lose the last seconds.

📖 Answer

There are cases where making Redis the only store makes sense: sessions, real-time leaderboards, temporary state, the latest values coming from IoT devices. In those cases the data is simple, fetched by key, and losing a little isn't a disaster.

For orders, payments and user accounts, there are plenty of problems:

  • you can't write a query like "users who ordered more than 100 thousand soums in the last month"; you'd have to build the index yourself;
  • even with appendfsync everysec, a crash can lose about 1 second of writes;
  • 200 GB of data means more than 200 GB of RAM, which costs far more than disk;
  • there's no schema, foreign key or constraint, so data integrity is left to your code.

That's why the usual architecture is: the source of truth is the relational DB, and Redis is a fast layer in front of it.