What is the difference between multiple data sources and multi tenancy? - mongodb

In context of mongodb and gorm, If we need to have different databases for different clients, then are multi-tenancy (With Database mode) and multiple data source approach are 2 solutions to achieve the same thing or is there any difference between them?
Multiple Data Source Solution:
http://gorm.grails.org/latest/mongodb/manual/#multipleDataSources
Multiple Tenant Solution:
http://gorm.grails.org/latest/mongodb/manual/#multiTenancy

Well they are not meant to achieve the same purpose
tldr;
Multiple Data Source is meant to have different databases (collections if you only plan to use mongodb) for different objects while Multi Tenant will store the same object but add a discriminator to identify client specific data.
If your question is about supporting different databases for different clients the answer will be to go with multi tenant
Multiple Data Sources
Grails supports (for long) to have multiple database for the same application (it can be different db vendor or different db from same vendor). The purpose is to have specific data stored in a different db/namespace.
For example, you can decide to have a db for all core entity of your business and to have a dedicated db for all audit/logging things. When using multiple data sources you will map an object to a dedicated datasource
Multi Tenancy (with database tenant as per OP context)
In mutli tenancy (database tenant) on the other hand, grails will have a single database schema for your client to store all the objects. so data from Client A will be in another db than Client B. Grails will have some default tenant resolver (that you can still override if needed) which will manage to determine which database needs to be queried depending the context.

Related

Spring Data Sources: Can I have 2 data sources that point to a read/write endpoint and a read only endpoint but both data sources use the same entitys

I have the need of creating 2 data sources in spring, one pointed to a read replica and one to a primary db. Both the db's are the same since the replica is just a copy of the primary. Therefore, they both use the same exact entities. Since I've created 2 data sources, I can no longer use the #EntityScan annotation. Before, when using the #EntityScan on my singular data source my connections to the database worked great. When I define two data sources and custom entity managers for each I can still connect to the databases just fine, but all my SQL queries will fail. It's as if the schemas are now incorrect and I'll get errors like columns don't exist when I know they do. Are there resources on how to achieve this design? I have been trying to follow this example:
https://www.baeldung.com/spring-boot-configure-multiple-datasources

Asp Net Boilerplate - Setup Schema-Per-Tenant Multitenancy (EntityFrameworkCore & PostgreSQL)

We are looking into using Asp Net Boilerplate. Looks very promising. We love the framework, but we would like to be able to use a per-schema Multitenancy configuration. Instead of sharing the data in the same db & tables, each tenant would "have" a schema, in which the whole database structure would be replicated.
One of our data tables will be quite big (sometimes +1 million entries / tenant), and we were advised that for performance reasons, it's better to keep the number of entries as low as possible. Also, this particular table will be queried & inserted a lot. It would be unrealistic that this table would hold data for 40+ tenants. For that reason, and others, we would prefer to have a distinct schema per tenant.
Our DB is a single PostgreSQL server (might scale up to more in the future). We use EntityFramework & Npgsql. We already noticed that it is possible to set up a different ConnectionString for specific tenants that would have bigger data requirements.
http://www.summa.com/blog/2013/09/17/approaches-to-multi-tenancy See separate schema per tenant
Any idea on how to acheive a schema-per-tenant multitenancy? There's a lot of moving parts in this, I'm not sure where to start.

Multiple database in EF6

We are involved in quite a new development in which we are remaking our current web shop platform.
In the current platform we do not use EF6 neither other ORM but store procedures to access to the db, but in the new building is what we do.
We have a doubt regarding database design of the new platform. In the current platform we use several different databases depending on the content of them.
For example, we have dedicated databases to store information for products catalogs other dedicated db for handling orders.
Currently all data access is done through stored procedures, so we have no problem with the links between different databases.
The problem appears to us now when we have started to use EF6. In this case each DB is associated with a context and it is not possible to know data from one context to another
unless we implement directly in the source code these relationships using various contexts. It looks like these means we will lose the power of EF6.
The questions we have are:
Is it a bad design maintaining different databases for the same application using EF6?
in case this is a poor design and choosing for a single database, is the performance going to be optimum even driving hundreds of tables (almost 1000) with several TBytes of information?
in the other hand, in the case of opting for the design in which several bbdd appear (it would be much better in our case), what is the best way to handle them EF6?
Thank you very much for your help!
First of all EF is not written to be cross database. You can't write cross database (cross context) queries, lazy load does not work and so on.
This is a big limitation in your case.
EF could work with several schema (actually I don't use it and I don't like it but is just my opinion).
You can use your stored procedures with EF but as I understand you are thinking to stop to use them.
In my experience I wrote several applications with more than one database but the use of the different databases was very limited. In this cases I use cross database views (i.e. one database per company and some common tables with views in company databases that selects data in common tables). In your case, if the tables are sharded everywhere I don't think this is a way you can choose.
So, in my opinion you could change the approach.
If you have backups problems you could shard the huge tables (I think facts tables and tables with pictures) and create cross database views. BTW, also, cross database referential integrity is not supported in SQL Server so you need to write triggers to check it.
If you need to split different application functions (i.e. WMS, CRM and so on) you can use namespaces without bothering about how tables are stored in the DB.

Database Crawler using JPA

We have a requirement for building a database crawler. The application parses the tnsnames, connects to each database and retrieves some information like version, accounts, etc. We are trying to use JPA across the other parts of the application and to persist this data into the application's database.
So far, I only see creating an EntityManagerFactory programmatically for every database. Is there any other options?
We are using Spring, are there any benefits that Spring brings to the table in this scenario?
Thanks
JPA is clearly not the right tool for this job. JPA allows creating functional entities mapping a well-know database schema. Your tool doesn't know anything about the schemas and tables it will find. There could be 0 tables or 5000, with completely unknow names.
You need a much lower-level API to do what you want, like JDBC.
You could use JPA to store the results of your crawlings in a single schema, though.

How to split tables among databases with JPA (Eclipselink)?

Is there a way to split a database using JPA (eclipselink)? I would like to separate the system data from the client data.
I would like to have relationship between them and if possible being one Persisence Unit.
Not sure what you mean. But you can have two persistence units, one for a client database, and one for a system databases.
If you want to use them as a single persistence unit from your application, or want to have relationships between the two, you can use Composite Persistence Units in EclipseLink.
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Composite_Persistence_Units