Andrii Skaliuk
Andrii Skaliuk

Reputation: 438

Redis as a cache and a queue using same instance

My application requires two use-cases for a cache:

  1. Redis as a cache. I plan to cache items (JSON blobs) by id using allkeys-lru memory policy. Average JSON item will take <1 Mb.
  2. Redis as a queue. I decided to build content social feed (similar to Instagram or Facebook) using Redis queue API. It will use same memory policy. Capacity of a queue will be ~1000 elements. Average queue (which represents a feed per user) will take ~10 Mb.

Can i use a single instance of Redis for both purposes without performance impact? Is it better to split them for better performance? Thank you.

Upvotes: 4

Views: 3425

Answers (2)

zenbeni
zenbeni

Reputation: 7213

Redis is single-threaded, so you get more CPU power with 2 redis instead of one. Still you will need to manage 2 databases (can be great for scaling, but it will need more actions for backups etc).

If you don't need a lot of CPU power in redis (with functions that requires a lot of computations, like in LUA scripts) I don't think you will see a big difference by using 2 redis instead of one. Most of the time, it is I/O that is the slowest part that drives the performance and as Redis is an in-memory database, it won't have a big impact.

Upvotes: 3

E.J. Brennan
E.J. Brennan

Reputation: 46879

There is no reason not to try; I would recommend using two databases within the same redis instances however, so that if you ever want to up size to two separate instances, you can dump and relocate on db separate from the other.

Two instances would be faster than one, but no sense doubling the cost until you have some idea what your needs are - but keeping the db's separate will make that process a bit less painful if it comes to that.

Upvotes: 4

Related Questions