Search code examples
mysqlhibernatedropwizardmaster-slave

master-slave in dropwizard and hibernate


I have an application written in Dropwizard and using hibernate to connect to DB(mysql). Due to new features being released, I am expecting high load for read apis and thinking of providing the reads from slave DB. What are the different ways in which i can configure master-slave and tradeoffs.


Solution

  • The way I have solved:

    1. I have 2 session factories in my case: one is default which talks to master and other one with a name say "slaveDb" which talk to slave database.

    2. I have created different dao for same entity one for slave interactions and one for master. in slave dao i am binding it with the slaveSessionFactory

    3. Now unit of work annotation has one attribute "value" if you don't use it , which we do not in many cases then the annotation processor will talk on top of the default session factory. If you define a name over here then annotation processor will use the session factory with that particular name.

    P.S. In my case I have a single slave as the application is not that high load and I wanted slave just for report generation purpose. In case of many slaves this solution doesn't scale well. Also As I was giving the slave machine details in my config.yaml file , I need not set the underlying connection as read only.