quarks
quarks

Reputation: 35326

Redis namespaces for multi-tenant apps

How can a single instance of Redis be used in a multi-tenant environment. Meaning multiple and different applications using the same Redis instance.

Suppose I have two apps, one is Baking App and the other one is Delivery App. Both apps will be using the same Redis instance and both apps will be saving similar keys with similar key patterns (e.g. userid:uuid -> johnsmith) etc. Obviously, using the same Redis will have collisions, is there a way to "Namespace" the database as such even the same key will be isolated from each other allowing multiple apps to use the same Redis instance concurrently?

And also work with Redis search, and in the same way, search and indexing would be isolated from each app. So if the search is on the Delivery App namespace it would not fetch anything from the Baking App namespace.

How can this be achieved?

Upvotes: 5

Views: 2915

Answers (1)

Gautam Rajotya
Gautam Rajotya

Reputation: 176

So there are multiple things that you can do:

  1. You can prefix the keys with app name like app1:userid:uuid etc
  2. You can use different in memory db provided by redis. Redis supports upto 16 DBs. You can store keys for different apps in different db. To fetch them connect with respective DB.
  3. You can use both of the above methods.

To improve security so that the Apps cannot access other App's data:

  1. Implement Redis ACL - If you are using Redis version 6+, you can leverage the feature of using ACL(Access Control Lists). You can create users with passwords for each app and pass these credentials while making Redis connection. You can even add permissions/commands etc. to the users.
  2. Data in different DB cannot be accessed i.e. if you make connection to DB 0, you cannot fetch data from DB 1.

Upvotes: 6

Related Questions