views:

317

answers:

2

I have a rails app that uses two of the same models as another rails app I have. What's the best way to keep data synced between two models?

MySQL replication probably won't be possible due to hosting restrictions and since stuff that references the replicated data is dependent => :destroy meaning mysql replication will cause stuff that points to replicated data that is deleted to remain.

In short, what's the best way to do replication between two rails apps, on a per-model basis, at the application level? Am I going to have to hack my own replication using REST, or is there a better way?

I should add that data changes infrequently, at most a few times a day, and the set will always be less than 50k rows.

Edit: In response to Toby's comment below, the data is all going one way.

A: 

This isn't a specific answer but consider some sort of queuing mechanism. App A makes a change and writes to both a queue and the database. The "queue" could be a table in the database that says "App A changed Model M with id I". Both apps could then have a process that polls this table and applies the changes.

Where you will run into trouble is when both sides modify the same object.

Dave
A: 

So, it turns out there are two plugins that do this:

Acts as Replica and Acts as Syncable

Acts as Replica seems to have better documentation.

Looking at the complexity of it however, I think for my own needs I'm going to roll my own that, while not perfect will be far simpler for my own use case.

All the data in my replicated tables is simply culled from an XML file. The XML cannot be sent in full to the server to be replicated to for privacy reasons (I only use a subset in both apps, but the extra data is sensitive), so I'm going to just expose a REST interface with the data I need and replicate that.

Andrew Cholakian