Search code examples
rethinkdb

RethinkDb: How to select the "single authoritative primary replica" on this side of the Ocean


I am building a multi-tennant solution. The customer are from all over the world, most in Europe or US, some are all over the place.

I want to have a single cluster of the database, with a number of servers in US, EU and Singapore.

I want the users to select their single authoritative primary replica for their data. How do I do that in RethinkDb?

The problem I am trying to solve is how to handle the latency over the Atlantic and Pacific. I do not want the users to have wait for 0.6 - 1.5s for writes all the time, which I would get if I use a "single master in US" approach.

I also want global reads to be done rather local, i.e. same continent, which I would get with RethinkDB using out-of-date reads, which is why I am looking at RethinkDB.


Solution

  • You can use server tags in combination with the ReQL reconfigure command to make sure that the primary nodes for a given table are assigned to a specific data center:

    http://rethinkdb.com/docs/sharding-and-replication/

    http://rethinkdb.com/api/javascript/reconfigure/

    Alternatively you can get even more fine-grained control and assign individual servers as primaries for a shard through the table_config system table:

    http://rethinkdb.com/docs/system-tables/

    Unfortunately you cannot currently control which documents in a given table will be handled by which server. If you have some documents that should have their primary in each of the data centers, I recommend creating individual tables for each and configuring them accordingly as described above.

    For querying all of the tables together you can use the union term: r.table("t_US").union(r.table("t_EU"), r.table("t_Singapore"))

    http://rethinkdb.com/api/javascript/union/

    I hope this helps, please let me know if you have additional questions.