RepoDB icon indicating copy to clipboard operation
RepoDB copied to clipboard

Enhancement: Could you please consider round robin connection

Open kchinburarat opened this issue 5 years ago • 8 comments

In case of we have database replica so that we can round robin connection over many database instance

kchinburarat avatar May 05 '20 03:05 kchinburarat

For me to understand further, can you provide more context on what you would like to attain?

mikependon avatar May 05 '20 04:05 mikependon

Do you use the embedded repositories (ie: BaseRepository or DbRepository) and would like the library manage that, or do you use your own repository and manage your own connection? The latter part will definitely not a responsibility of the library.

The library is connection driven and it must be the client's responsibility to manage the connection. Any logic on top is not ideal for a framework like this (maybe?), due to the fact that it will abstract some functionalities that will work in your case (but not on the others).

Or, Please add more context to this request.

mikependon avatar May 05 '20 08:05 mikependon

Let say if i have 1 master database for write and 3 read only databases. How can i use DbRepository to connect to all read only database by round robin. Example: Query 1 go to MsSQL001(Read Only) Query 2 go to MsSQL002(Read Only) Query 3 go to MsSQL003(Read Only) Query 4 go to MsSQL001(Read Only) Query 5 go to MsSQL002(Read Only) Query 6 go to MsSQL003(Read Only)

kchinburarat avatar May 06 '20 07:05 kchinburarat

A very specialized scenario :). No, this is not a part of the framework. We will not make DB Connection buffering to manage this (or maybe it is something that we can improve moving forward).

One more comment, do you have a diversion layer that manage this automatically for you in between your application and your databases? Something like a request router based on the availability of the databases?

mikependon avatar May 06 '20 07:05 mikependon

A very specialized scenario :). No, this is not a part of the framework. We will not make DB Connection buffering to manage this (or maybe it is something that we can improve moving forward).

One more comment, do you have a diversion layer that manage this automatically for you in between your application and your databases? Something like a request router based on the availability of the databases?

No. I don't. Last time i was talked to devops team about new technology like service mesh but the issue is we will lose the benefit from database connection pool .

My idea is instead of passing connection string we should passing new class like IDatabaseResourceManager that will manage the list of connection string

What do you think?

kchinburarat avatar May 06 '20 16:05 kchinburarat

BTW Let me play around with your very nice lib maybe i will create new PR

kchinburarat avatar May 06 '20 16:05 kchinburarat

Just remember that this library needs to isolate itself from specific use cases like this. I would humbly say that your use case is an additional layer of abstraction to manage such scenario.

IMHO, imagine you have a list of ConnectionStrings and you call the Query method, but suddenly you would like the Query method to query the DB2 instead of DB1. Such call must be abstracted by 2 open-pooled connection as the feature of identifying which DB to connect to is not an ORM specific use-case :)

mikependon avatar May 06 '20 16:05 mikependon

BTW Let me play around with your very nice lib maybe i will create new PR

Try to see if you can optimize both DbRepository and BaseRepository. There is a possible change. Make sure to run the Regression Tests from time-to-time to slowly guide you while doing the passing changes. Looking forward on it :)

mikependon avatar May 06 '20 16:05 mikependon