I am looking into the revamping my organization's application by moving from a monolithic into a microservice-architecture. My database is a multi-schema shared in one database. Each of these schemas is currently being distinguished by a different username, while the rest of the settings (url, password, dialect, etc..) remains the same. The CRUD process has been established by calling the stored procedures (since it involves parent-child tables and composite keys).
So far, after looking into various techniques, design patterns and sample code shows two possible approaches:
- Declare the schemas as multiple datasources in the config file (a .properties or .cfg file) and change it at run time or;
- Treat the DB username as the Tenant-ID and use it in the style of TenantContextHolder, resolving tenant mechanism.
Much of the code that I've seen on GitHub treats the multi-tenancy done on a single microservice basis.
This the current situation we are at:
- The legacy authorization and authentication service is in Python, with persistent token value storing in DB that will be carried across the application, including the vertical (schema) that this token represents. We are not planning to change anything or reinventing it in Java since it is quite well matured and compatible.
- There are about six to seven microservices to be developed in future but ideally in the form of a Spring Java microservice (e.g Kafka message stream, Spark csv, Recommendation (DML), Mall Tenancy, Item Management, User Management, etc..)
- Dev team size is still small about five persons. We have limited time and financial resources.
- We have a very complete those in five months.
Given of the scenario we are facing: A. Should we opt for approach A (declare multiple datasources) or B (use the tenant id and context holder) ? B. From A, should mulitenancy capability be done on each microservice or done in a library jar? C. If the recommendation is to use the library jar, any sample codes that I can have a look to see if it matches what we would look for?
Can anyone shed light on the ideal approach and the pros / cons?