✅ Storing JSON and User data in a multi-tenant application
Hello!
I'm developing a multi-tenant (multiple concurrent users) application.
I require a database for storing JSON configurations and user data (users, roles, permissions).
Not sure, whether to use a single relational database, or a relational for user data and non-relational for JSON.
I believe that Redis is out of the question, as it is an in-memory database; whereas, I need a more permanent storage for JSON configurations.
I'd prefer to use EF Core to simplify development efforts; however, I've found that it doesn't have that much support for NoSQL. E.g., there is no official EF Core driver for MongoDB.
My personal wish is to allow the resulting application to use any database provider - that is why I want EF Core, as doing this manually would be quite complicated.
Is my goal realistic?
Do you have any experience with such solutions?
If it is not realistic, how should I go about this?
13 Replies
What about Marten? It's a document database built on top Postgres.
https://martendb.io/
Marten
.NET Transactional Document DB and Event Store on PostgreSQL
You could also store the configuration in a json column in the "tenant" table.
The JSON configs will be accessed and written more often than user data. Is this an optimal approach?
Given that I use EF Core, define an entity with a JSON column, and EF is connected to any of the following databases:
- SQLite
- MySQL
- MS SQL Server
- PostgreSQL
Dont see how that would be different from using a nosql database?
you're still looking up a document
you'd likely want to add a cache for it, ofc
since you'll be wanting to access this data on every request
Just asking, if there is a, e.g., performance issue
So maybe a REDIS cache would be a viable choice
for accessing a redis cache on every request? not at all
thats extremely standard
and what redis is made for
makes sense
for the product I work with at work, we use redis to store session information
so its accessed for literally every request
given that is standard, here's a nooby question... how do I ensure cached data is synced with the stored data
technically you dont
the idea is that every time you write to the database, you also update the redis cache record
so if the user config is ever updated, its updated in both DB and redis
so simple
wonderful
thanks a lot!
this supports multiple application instances as well, ie horizontal scaling
Thanks for the tip! However, this is a specific database. Which should be abstracted away by EF Core. But, I will check it out