I was sharing my thoughts on the impact of Covid-19 and the new opportunity in supply chain domain.
Saturday, April 10, 2021
Wednesday, April 8, 2020
DB Multi-Tenancy Modelling for Microservice
Multi-Tenancy with the SaaS based model does not bring any change on the application layer as multiple services deployment of application would be able to accommodate the
load on application but it would matter how do we decide the modelling of the database w.r.t. Multi-Tenancy.
Following are the factors to be considered for decision making for multi-tenancy:
Cost Cost per tenants if separate DB/SCHEMA is selected per tenants.
Performance Application performance & scalability would impact based on the number of tenants, data size per tenants and the workload.
Time Development & Release migration efforts when multiple databases/schemas are in production. Complexity for managing the operations for maintaining multiple DBs.
Tenancy Modelling
Database per Tenant Single Tenant Architecture where each tenant has its own database and is isolated from other tenants.
Shared Database Multi Tenant Architecture with separate schema where all tenants share a database, but have their own database schemas and tables.
Shared Database and Shared Schema Multi Tenant Architecture with all tenants share a database and tables. Every table has a Column with the Tenant Identifier, that shows the tenant of the row.
Various multitenancy strategy supported by Hibernate are
Flyway integration would be creating necessary tables in database dbA
Sample request for catalog retrieval
Following are the factors to be considered for decision making for multi-tenancy:
Cost Cost per tenants if separate DB/SCHEMA is selected per tenants.
Performance Application performance & scalability would impact based on the number of tenants, data size per tenants and the workload.
Time Development & Release migration efforts when multiple databases/schemas are in production. Complexity for managing the operations for maintaining multiple DBs.
Tenancy Modelling
Database per Tenant Single Tenant Architecture where each tenant has its own database and is isolated from other tenants.
Shared Database Multi Tenant Architecture with separate schema where all tenants share a database, but have their own database schemas and tables.
Shared Database and Shared Schema Multi Tenant Architecture with all tenants share a database and tables. Every table has a Column with the Tenant Identifier, that shows the tenant of the row.
Various multitenancy strategy supported by Hibernate are
public enum MultiTenancyStrategy {
DISCRIMINATOR,
SCHEMA,
DATABASE,
NONE;
}
DISCRIMINATOR strategy work is in progress and from the documentation of hibernate
DISCRIMINATOR strategy Correlates to the partitioned (discriminator) approach. It is an error to attempt to open a session without a tenant identifier using this strategy.
This strategy is not yet implemented and you can follow its progress via the HHH-6054 Jira issue.
JIRA HHH-6054 is currently in OPEN Status.
Here in the example following modules/projects shows the example to achieve the tenancy modelling using
SCHEMA (shared db, separate schema) strategy per tenant based approach and SCHEMA (shared db, shared schema) strategy for different tenants.
multitenancy-op2 project shows the example with the multiple tenants share the same database but different schemas.
multitenancy-op3 project shows the example of the hybrid approach of with the tenants are grouped against the specific database and schema.
This would give an ability to map a specific tenant with single database as well when the high load is expected for a tenant in comparison to others.
Project multitenancy-op2
UseCase is where database is same (dbA) and every TENANT is using specific Schema i.e.
Tenant wise DB and Schema mapping.
TENANTID | DB | SCHEMA |
TENANT1 | dbA | SCHEMA1 |
TENANT2 | dbA | SCHEMA2 |
Build and run multitenancy-op2 project
cd multitenancy-op2
mvn clean package
mvn spring-boot:run
Catalog creation request for TENANT1 which would insert data into table SCHEMA1.CATALOGTABLE
curl -X POST \
http://localhost:8080/catalog \
-H 'content-type: application/json' \
-H 'tenantid: TENANT1' \
-d '{"tenantId":"TENANT1","catalogName":"Catalog1","supplierId":"supplier1","source":"X-Systems"}'
Catalog creation request for TENANT2 which would insert data into table SCHEMA2.CATALOGTABLE
curl -X POST \
http://localhost:8080/catalog \
-H 'content-type: application/json' \
-H 'tenantid: TENANT2' \
-d '{"tenantId":"TENANT2","catalogName":"Catalog2","supplierId":"supplier2","source":"Y-Systems"}'
Catalog retrieval request for TENANT1
curl -X GET \
'http://localhost:8080/catalog?catalogId=1' \
-H 'content-type: application/json' \
-H 'tenantid: TENANT1'
Catalog retrieval request for TENANT2
curl -X GET \
'http://localhost:8080/catalog?catalogId=2' \
-H 'content-type: application/json' \
-H 'tenantid: TENANT2'
Project multitenancy-op3
UseCase is as the hybrid approach to accommodate following cases:
- Tenant(s) with higher load using the dedicated database and single schema (TENANT1).
- Tenant(s) with moderate load can use same database but different schema (approach in multenancy-op2 project).
- Tenant(s) with lower loads can share the DB SCHEMA (TENANT2 and TENANT3). Tenant wise DB and Schema mapping.
TENANTID
| DB | SCHEMA |
TENANT1 | dbA | SCHEMA1 |
TENANT2 | dbB | SHARED |
TENANT3 | dbB | SHARED |
Build and run multitenancy-op3 project
Sample request for catalog creation
Catalog creation request for TENANT1 which would insert data into table SCHEMA1.CATALOGTABLE in database dbA
cd multitenancy-op3
mvn clean package
mvn spring-boot:run
Create the following schema manually
create schema if not exists SHARED;
create table SHARED.catalogtable(id bigint, tenantid varchar(10), catalogname varchar(30), supplierid varchar(30), source varchar(10));
CREATE SEQUENCE SHARED.hibernate_sequence START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
Catalog creation request for TENANT1 which would insert data into table SCHEMA1.CATALOGTABLE in database dbA
curl -X POST \
http://localhost:8080/catalog \
-H 'content-type: application/json' \
-H 'tenantid: TENANT1' \
-d '{"tenantId":"TENANT1","catalogName":"Catalog1","supplierId":"supplier1","source":"X-Systems"}'
Catalog creation request for TENANT2 which would insert data into table SHARED.CATALOGTABLE in database dbBcurl -X POST \
http://localhost:8080/catalog \
-H 'content-type: application/json' \
-H 'tenantid: TENANT2' \
-d '{"tenantId":"TENANT2","catalogName":"Catalog2","supplierId":"supplier2","source":"X-Systems"}'
Catalog creation request for TENANT3 which would insert data into table SHARED.CATALOGTABLE in database dbBcurl -X POST \
http://localhost:8080/catalog \
-H 'content-type: application/json' \
-H 'tenantid: TENANT3' \
-d '{"tenantId":"TENANT3","catalogName":"Catalog3","supplierId":"supplier3","source":"Y-Systems"}'
Inserted records can be verified at http://localhost:8080/h2-console/ by logging into
use database dbB (jdbc:h2:mem:dbB) for TENANT2 and TENANT3 in schema SHARED
Sample request for catalog retrieval
curl -X GET \
'http://localhost:8080/catalog?catalogId=1' \
-H 'content-type: application/json' \
-H 'tenantid: TENANT1'
Catalog retrieval request for TENANT2
curl -X GET \
'http://localhost:8080/catalog?catalogId=1' \
-H 'content-type: application/json' \
-H 'tenantid: TENANT2'
Catalog retrieval request for TENANT3
curl -X GET \
'http://localhost:8080/catalog?catalogId=2' \
-H 'content-type: application/json' \
-H 'tenantid: TENANT3'
Download/Refer code from github repository.Sunday, May 13, 2018
Smart Light using Arduino
While working on the regular projects in office, I have joined SAP Ariba IOT Group where we try out few things which can solve some problem which could be really helpful.
I am also trying to use Raspberry Pi, Arduino and other platforms.
Recently i have tried to build a smart light, which I want to fix it to my study table now. :-)
Circuit:
I have picked the circuit from internet which explains about the connectivity of different components.
Circuit Diagram |
Demo Video:
Here is a short video about it.
Hardware Components:
Arduino Uno | 1 |
Relay Module | 1 |
PIR Motion Detector Sensor Module | 1 |
Connectors/Jumper Wires | 6 |
Power Cable | 1 |
Power adaptor for Arduino Uno | 1 |
Light | 1 |
Software Components:
Arduino IDE | 1 |
Smart Light Code |
Code:
Troubleshoot:
While uploading the code there was an issue with PORT( /dev/ttyACM on ubuntu) read/write permission
Following commands helped:
deepak@deepak-B570:$ ls -l /dev/ttyACM*
crw-rw---- 1 root dialout 166, 0 May 12 19:21 /dev/ttyACM0
deepak@deepak-B570:$ ls -l /dev/ttyACM*
crw-rw---- 1 root dialout 166, 0 May 12 19:21 /dev/ttyACM0
deepak@deepak-B570:$ sudo chmod a+rw /dev/ttyACM0
[sudo] password for deepak: ********
Subscribe to:
Posts (Atom)
Heroku Custom Trust Store for SSL Handshake
Working with Heroku for deploying apps (java, nodejs, etc..) is made very easy but while integrating one of the service ho...
-
Multi-Tenancy with the SaaS based model does not bring any change on the application layer as multiple services deployment of application w...
-
Raspberry Pi is an awesome and interesting . I was totally astonished after knowing about it from one of my friend and colleague "Ale...
-
I have a class which is not serializable. If i will try to serialize the object of it than i am going to get exception "java.io.NotSer...