C
C#13mo ago
coado

Databases load balancing

Hey everyone, I have to create a load balancer between databases. I am using EF core to build queries and manage database connections. I wonder if changing the database connection in interceptors is possible. For example, I have a DBContext instance connected to database1, and in the interceptor, I want to run a round-robin algorithm that will change the connection between database1, database2, etc. The second approach that came to my mind is to create a proxy that will act as a "database" (it will listen for queries). It would redirect the requests between multiple real databases. I will connect DBContext to my proxy in my server that uses EF Core. I am unsure if it's possible and how to go about this. I am new to C# and this is my assignment for university, so any help is appreciated. Thanks! Hey everyone, I have to create a load balancer between databases. I am using EF core to build queries and manage database connections. I wonder if changing the database connection in interceptors is possible. For example, I have a DBContext instance connected to database1, and in the interceptor, I want to run a round-robin algorithm that will change the connection between database1, database2, etc. The second approach that came to my mind is to create a proxy that will act as a "database" (it will listen for queries). It would redirect the requests between multiple real databases. I will connect DBContext to my proxy in my server that uses EF Core. I am unsure if it's possible and how to go about this. I am new to C# and this is my assignment for university, so any help is appreciated. Thanks!
4 Replies
Angius
Angius13mo ago
Database load balancing is not something that should be handled at the application level It should be a reverse proxy between the application and the databases Directing the queries from the application to the appropriate db Something like HAProxy for example
coado
coadoOP13mo ago
Yes, that make sense. Is it possible to make very simple one from scratch and connects to it using EFCore or some other ORM?
Angius
Angius13mo ago
Sure All a reverse proxy, ultimately, does, is takes the incoming traffic and redirects it So you should be able to just run the proxy at the address and port of the database, capture the incoming traffic, and redirect it to the actual database
coado
coadoOP13mo ago
Okay, but what about migrations? Is it possible to run migration on all databases at once?
Want results from more Discord servers?
Add your server