I have an e-commerce website (built upon Opencart), utilizing Master-Slave replication (1 Master and 2 Slave DB servers). For effective load balancing, people recommended us to use Maxscale. However, to avoid unnecessary increase in costs due to licensing and additional servers (for Maxscale), we implemented a weighted-random load balancing on our own. At the end, I am posting some relevant and interesting portions from my code, which many people may find helpful :-)

Immediately after a Write operation, any number of Read operations can also be routed to Write server. For eg: I allow 2 Read operation, because sometimes due to Replication lag, inserted/updated data in the Master server, does not immediately reflect in the Slave server(s).

Read load is randomly distributed, but in weighted manner across various Slave (Read) servers.

Now, I am inclined to switch to an ORM, and after a lot of Google searches, I am unable to find a straightforward ORM solution for my requirement(s). My question is: Are any ORM(s) which allow handling of Master-Slave load balancing with flexibility for weighted load distribution ?

PS: This question was considered too broad by StackOverflow community. So, I am hoping that this community may help in this!

Please find below the code snippet. I am also open to further improvement suggestions by the community: