Short introduction to multi-tenancy database architecture
Ever thinking of using multiple databases into our application? Well, it is a good practice as our application is getting bigger we need to keep our application scalable. Here is an illustration of multi-tenancy database :
So, what is multi-tenancy database?
Multi-tenancy database is an architecture which isolate and separate each database for each instance (such as per user/company). Generally each user will have one database. The opposite of multi-tenancy database is single-tenancy database. It collect all data into one single database, and it’s not recommended for big and scalable application
Then, what are the pros of implementing multi-tenancy database?
Data isolation
Just imagine, we are having an online store app that enables each user to sell products. Facing technical problem, our database is corrupted. How about all of our user data if we store each of them in a single database?
With multi-tenancy database, for example we are making each database for each user. We have 5 users — 5 databases. If one database is corrupted, we still have 4 databases. Most of our user’s data are safe.
Performance
How if we have 5 users on our application, and each of them has 10 products? And we need to display product number 45. It’s not quite heavy task as there are only a few data. But how about having millions of products? And we need to display specific product for user with ID 675. With multi-tenancy architecture, our query will not be as heavy as we store all of our products into one single database.
Security
Let’s say we are storing all of our payment data on single database (not separated per user). And then, someone having access to our database without permission. It will be extra dangerous as our data are easily accessed within one single query.
But with multi-tenancy architecture, as long as our super admin or root access are not accessible nobody can access our data as each database holds different credential.
That’s a simple and short introduction to multi-tenancy database architecture.
Thank you for reading :)