Brett
Brett

Reputation: 6020

Replicating data between 2 Mongo replica sets

I'm currently have a mongo replicaset consisting of 1 primary and 2 slaves, that is used by a read-only application. I'm adding a 2nd read-only application that requires access to the same data. I have / am considering using the same RS for both applications, but was wondering if there's a way to create a specific type of configuration with Mongo, that works something like this:

1 x primary, that handles all writes, but is not seen as part of a replicaset by the application, and then 2 sets of read-only secondaries that replicate from primary. Each set of secondary replicates writes from the master. Conceptually, something like:

          /----> RS1: |Secondary1|Secondary2|..|SecondaryN|   <--- App1
PRIMARY|=> 
          \----> RS2: |Secondary1|Secondary2|..|SecondaryN|   <--- App2

Is this sort of configuration possible at all? What similar architectures could I consider for this use-case?

Thanks in advance.

Brett

Upvotes: 1

Views: 1451

Answers (1)

Brett
Brett

Reputation: 6020

I came across a way to implement this using mongo tooling:

  1. Create a replica set to use as a master. Data updates are written to this RS (represented by "PRIMARY" in the diagram). Do not enable authentication on this host
  2. Create 2 replica sets with the same data (completely independent of each other)
  3. Schedule regular "mongooplog" runs, using #1 as from and each of the RS's for host see the manual

Authentication can be set up in the RSs from #2, that only give applications read access to the data.

I haven't tested this yet, but from what I can tell, this approach should work for my objectives - is there anything I've overlooked in this approach?

edit

While trying to use this approach, I ran into issues when trying to use mongooplog with authentication on the destination. over and above that, mongooplog doesn't cater for authentication on the source / --from rs, and so I wrote a tool to cater for this:

https://github.com/brettcave/mongo-oplogreplay

It supports authentication on both source and destination, as well as replicaset targets.

Upvotes: 1

Related Questions