I am in the process of developing cloud services in which synchronises local databases (an order taking POS system) to a central remote database. Our remote database is running the latest version of mysql 5.6 with innoDB table engine for each of the tables. Basically it acts as a transactional database that experiences a lot of transactions mainly writing to (ie. INSERT and UPDATE) and some times experiences reading when viewing reports etc. Inevitably we experienced our first database deadlock (please note this occurred prior to upgrading mysql 5.6), and my understanding of the cause of deadlock may of been where there are 2 connections trying to either READ or WRITE to a row at the same time. I also understand deadlocks are common and require correct code to try/catch deadlocks in which I believe I have managed to accomplish. In order to mitigate deadlocks I was thinking of setting up 2 databases which are a mirror of each other A) Database that is written to b) Database that is read
Basically the syncing from local to remote will be writing to database A, and using rsync in the background would mirror database A to B, which database B would be used to read and query the reports, since rsync doesn't use database connections to read the data for syncing.
My question is, would this structure work in terms of mitigating deadlocks and have any significant performance issues on the server?
I hope my question makes sense in what I am trying to achieve.
Thanks in advance.
Database replication can help in improving performance and availability. But, there can be various aspects you might want to review before starting to replicate databases.
I am assuming that you have turned on knobs to log slow queries. I would recommend to analyze and see if there are opportunities to optimize your problem causing queries. Another thing is, although it is not always easy to re-model your data, but it can help at times. Verify that your reporting queries are using the indexes as desired. You can look into data partitioning as well.
At some point, depending on your data volume and reporting requirements, you can very well think about using NoSQL databases for analytical data.