Multi Tenancy in Redis for node.js

Viewed 2773

We have a multi-tenant NodeJS application and we are now adding a cache layer for some of our data.

We are aiming to use Redis cache with redis package and we are trying to check our options for supporting multi-tenancy with two main points in mind:

  1. Securing data.
  2. Purging the old data in tenant level.

Our investigation results so far are that we can use separate Redis instances for each tenant - which is not a good solution for us.

Another option we found is to namespace our keys with the "tenant_id:" prefix. This option solves the first point - data is secured now, but we still have the second point to resolve.

Our use case for this point is that one tenant can put a major amount of data which will fill the cache and push out other tenants' data. We want to define our LRU in tenant level, that is - when new data is added to the cache it will evict only the last recently used data of the same tenant.

Any suggestions?

3 Answers

I just stumbled across the same question and found a good solution.. Look in KeyDB (https://keydb.dev/), it's a Redis fork and now supports multithreading. It's fully compatible with Redis, a drop-in replacement for Redis; so you don't have to change any code.

I use it as full text search provider in a multi-tenancy scenario. My data store is MongoDB (has less support for fts); Every tenant has a hash list in KeyDB storing all keywords. Then HSCAN is used to query KeyDB (it's really fast). The results can then be resolved by MongoDB. Since KeyDB is non-blocking and multi-threading there is no need for complex deployment solutions.

And yes, you can use the existing nodejs libs for Redis to access KeyDB.

Stay healthy, best!

Related