Multi-Tenancy in a story
Tags: multitenancy, spring, architecture, microservices
Published: 2019-10-16 19:06:11

Assume you have a small startup of refrigerators called CoolPool (Product). You provide the best cooling solutions out there.

![Coolpool](https://media.giphy.com/media/MAvILh6mD1XA26w6yH/giphy.gif)

You work on demand, so whenever someone asks for the fridge you just manufacture one and deliver it to their home and promise them 2 Years of free support.
Business was going great, you are now receiving more requests than ever, but as Uncle Ben said, With big power comes big responsibilities. You now have to cater more service requests per day. A lot of money was being spent on transportation costs and many times the problem was among all the refrigerators so you had to visit every single one of the customers once you identify the problem to fix it.
Well, your profit graph was going down significantly!



Then you took a decision, to have a central cooling station (Cloud Instance) and since almost all the customers are in the same city you convinced them to come to the cooling station and put their stuff in their respective boxes. You also provide the varied size of boxes to your customers for different prices. This also reduced your manufacturing and setup cost.

Though now each customer has their share of latency it wasn't affecting them much so they agreed, but they were really strict about the privacy, configuration of fridge and safety of the items they put in their boxes. You agreed to their terms and provided them a key to access their boxes (Authentication System)
Everything was nice now whenever something goes wrong you knew you just to fix at the central cooling station. You now had more satisfied customers(tenants) than ever. WoW!!

As the demand grew, you bought a new place (server instance) and started moving new customers over there. Though there were more places to visit but also more happy customers.

CoolPool is a brand name now, everyone wants to have it, people from neighbor cities (different regions) are also interested but they can't come to this city as toll taxes were really high it took some time to come over.
So, you took the most intelligent solution and bought another cooling station there to set up your machine.

Voila! That's what multi-tenancy is.

Here is what Wikipedia says, and try to relate it to the story
The term "software multitenancy" refers to a software architecture in which a single instance of software runs on a server and serves multiple tenants. A tenant is a group of users who share a common access with specific privileges to the software instance. With a multitenant architecture, a software application is designed to provide every tenant a dedicated share of the instance - including its data, configuration, user management, tenant individual functionality and non-functional properties.
Right!!


---

Yeah, but there were some serious problems as well in this architecture which I will like to point out:-
> Safety of goods (data) is always a concern as some mischievous always to steal food from others boxes and since all the boxes are in the same place it gets easier for them to break in.

> It get's very crowded if the number of customers (tenants) grow and unless you are ready to have another cooling station(server instance) you might be trying to fit all customers in a single room.

> If anything happens to cool station (say power cut) then all the customers in the cooling stations are affected.

> Customers with bigger boxes may consume more power (human resources attention and electricity (computational power)) which will lead smaller customers to starve.

But, there are different ways to address these issues.


---

Ola, I am **Devendra Tiwari**, a Software Developer at 3C Logic, a 12-Year-old, call center solution provider, we are popular just like CoolPool and yeah we are a multi-tenant system.
This blog is first in the blog chain of Implementing Multi-Tenancy with Spring Boot. Follow me to get the updates. :)