Using Redis as a main database

109 Views Asked by At

I am implementing a leaderboard for my game and since it needs to be fast and run-time I am planning to use Redis. I haven't use Redis before so I am confused about one thing. As far as I know Redis is maninly used as a cache, but in my scenario I am planning it like a database. Can I do this or should I store the leaderboard data in a database as well. What would be the best practice in this situation?

3

There are 3 best solutions below

0
SerhiiH On

Simple answer would be have leaderboard data in a reliable database and load it into Redis as a secondary database.

However, it is possible to configure Redis persistence RDB + AOF and with that option you can use only Redis, but be aware that having RDB + AOF will be impacting Redis performance for write operations and there might be another issues mapping you in-memory data to disk.

Redis is in-memory storage and, as you already know, there are some hurdles making it primary database. Also you can try ready-to-go solutions like AWS MemoryDB, which is reliable database and Redis at the same time. If you can't use solutions like that, I don't recommend focusing effort try store data only on Redis and have data backed up by regular, well understood database.

0
Andrii On

As far as I know Redis is mainly used as a cache, but in my scenario I am planning it like a database. Indeed, Redis is primarily used for temporal data such as caching, sessions, or, in your case, for maintaining intermediate scores.

There are better choices for persistent storage: relational databases (PostgreSQL, MySQL etc) or NoSQL (MongoDB, Firebase etc). In addition to persistence, they offer a lot of query-related functionality as well as concurrent user access and transactions.

Redis is an excellent choice for leaderboards due to its Sorted Sets data structure, which allows for maintaining the leaderboard in a sorted state. Additionally, Redis provides commands to retrieve the top or bottom ranges easily. For more details read the article

0
Lior Kogan On

It is perfectly valid to use Redis as an operational NoSQL database, as well as a data structure server (e.g., counter, stack, queue, priority queue, set, leaderboard, …) with enterprise capabilities (distribution, scalability, concurrency, and controllable transaction guarantees).

Redis is much more than just a cache (see here, here). I'm from Redis. Many of our paying Redis Enterprise Software and Redis Cloud customers use Redis as a primary database and data structure server. Specifically, many of the world's gaming industry leaders use Redis, among other things, as the primary store for leaderboards (See here, here, and here).