I want to know which is the best architecture to adopt for this case :
- I have many shops that connect to a web application developed using Ruby on Rails.
- internet is not reachable all the time
- The solution was to develop an offline system which requires installing a local copy of the distant database.
All this wad already developed.
Now what I want to do :
- Work always on the local copy of the database.
- Any change on the local database should be synchronized with distant database.
- All the local copies should have the same data in other local copies.
To resolve this problem I thought about using a JMS like software eventually Rabbit MQ.
This consists on pushing any sql request into a JMS queue that will be executed on the distant instance of the application which will insert into the distant DB and push the insert or SQL statement into another queue that will be read by all the local instances. This seems complicated and should slow down the application.
Is there a design or recommendation that I must apply to resolve this kind of problem ?
I would recommend taking a look at CouchDB. It’s a non-SQL database that does exactly what you are describing automatically. It’s used especially in phone applications that often don’t have internet or data connectivity. The idea is that you have a local copy of a CouchDB database and one or more remote CouchDB databases. The CouchDB server then takes care of teh replication of the distributed systems and you always work off your local database. This approach is nice because you don’t have to build your own distributed replication engine. For more details I would take a look at the ‘Distributed Updates and Replication’ section of their documentation.