We have an application that does lot of data heavy work on the server for a multi-tenant workspace.
Here are the things that it do :
- It loads data from files from different file format.
- Execute idempotence rules based on the logic defined.
- Execute processing logic like adding discount based on country for users / calculating tax amount etc.. These are specific to each tenant.
- Generate refreshed data for bulk edit.
Now after these processing is done, the Tenant will go the the Interface, do some bulk edit overrides to users, and finally download them as some format.
We have tried a lot of solutions before like :
- Doing it in one SQL database where each tenant is separated with tenant id
- Doing it in Azure blobs.
- Loading it from file system files.
But none has given performance. So what is presently designed is :
- We have a Central database which keeps track of all the databases of Customers.
- We have a number of Database Elastic Pools in Azure.
- When a new tenant comes in, we create a Database, Do all the processing for the users and notify the user to do manual job.
- When they have downloaded all the data we keep the Database for future.
Now, as you know, Elastic Pools has a limit of number of databases, which led us to create multiple Elastic pools, and eventually keeping on increasing the Azure Cost immensely, while 90% of the databases are not in use at a given point of time. We already have more than 10 elastic pools each consisting of 500 databases.
Proposed Changes:
As gradually we are incurring more and more cost to our Azure account, we are thinking how to reduce this.
What I was proposing is :
- We create one Elastic Pool, which has 500 database limit with enough DTU.
- In this pool, we will create blank databases.
- When a customer comes in, the data is loaded on any of the blank databases.
- It does all the calculations, and notify the tenant for manual job.
- When manual job is done, we keep the database for next 7 days.
- After 7 days, we backup the database in Azure Blob, and do the cleanup job on the database.
- Finally, if the same customer comes in again, we restore the backup on a blank database and continue. (This step might take 15 – 20 mins to setup, but it is fine for us.. but if we can reduce it would be even better)
What do you think best suited for this kind of problem ?
Our objective is how to reduce Azure cost, and also providing best solution to our customers. Please help on any architecture that you think would be best suited in this scenario.
Each customer can have millions of Record … we see customers having 50 -100 GB of databases even… and also with different workloads for each tenant.
3
Answers
Pick a provider, and host the workloads. Under demand: provide fan-out among the cloud providers when needed.
This solution requires minimal transfer.
Here is where the problem starts:
"[…] When they have downloaded all the data we keep the Database for future."
This is very wrong because it leads to:
"[…] keeping on increasing the Azure Cost immensely, while 90% of the databases are not in use at a given point of time. We already have more than 10 elastic pools each consisting of 500 databases."
This is not only a problem of costs but also a problem with security compliance.
Here is my 2 solution:
Azure SQL Database gets expensive only when you use them.
If they are unused they will cost nothing. But "unused" means no connections to it. If you have some internal tool that wakes them up ever hours they will never fall in serverless state so you will pay a lot.
HOW TO TEST SERVERLESS:
Take a database that you you know it’s unused and put it in serverless state for 1 week; you will see how the cost of that database drop on the Cost Management. And of course, take it off from the Elastc Pool.
You can run this query on the
master
database:The query will return you statistics for all the databases on the server.
AVG_Connections_per_Hour
: collects data of the last 30 daysAVG
andMAX
statistics: collects data of the last 14 daysYou could perhaps denormalise your needed data and store it in ClickHouse? It’s a fast noSQL database for online analytical processing meaning that you can run queries which compute discount on the fly and it’s very fast millions to billions rows per second. You will query using their custom SQL which is intuitive, powerful and can be extended with Python/C++.
You can try doing it like you did it before but with ClickHouse but opt in for a distributed deployment.
"Doing it in one SQL database where each tenant is separated with tenant id"
The deployment of Clickhouse cluster can be done on Kubernetes using the Altinity operator, it’s free and you only have to pay for the resources, paid or managed options are also available.
ClickHouse also supports lots of integrations which means that you can perhaps stream data into it from Kafka or RabbitMQ or from local files/S3 Files
I’ve been running a test ClickHouse cluster with 150M rows and 70 columns mostly int64 fields. A DB query with 140 filters on all the columns took about 7-8 seconds on light load and 30-50s on heavy load. The cluster had 5 members (2 shards, 3 replicas).
Note: I’m not affiliated with ClickHouse, I just like the database. You could try to find another OLAP alternative on Azure.