I’m getting ready to use Dgraph in production, but have run into the following issue:
I currently have a geographically distributed Dgraph cluster over several continents. At any point in time, one or more servers in this cluster may become unavailable (due to upgrade, maintenance, or other considerations). It would be prudent to have a Dgraph client implementation that:
- Will automatically attempt to send query/mutations to other servers if one server is deemed unavailable, and will only fail if all servers are unreachable.
- Will take a given domain name (e.g. “consul-dgraph-us-west”) and continuously resolve the name to follow any changes in IP addresses/service availability. This is useful for service discovery and health checking systems such as Consul.
- Prioritizes certain servers for queries/mutations, and only attempts to contact other servers if the prioritized servers are unavailable. This will reduce round-trip time lag when dealing with various geographically disparate regions.
From what I gather the following code can be used to add multiple endpoints to the Dgraph js client:
const dgraph = require("dgraph-js")
const grpc = require("grpc")
const stub1 = new dgraph.DgraphClientStub(
"dgraph-alpha1:9080",
grpc.credentials.createInsecure(),
)
const stub2 = new dgraph.DgraphClientStub(
"dgraph-alpha2:9080",
grpc.credentials.createInsecure(),
)
const client = new dgraph.DgraphClient(stub1, stub2)
But from a quick reading of the source code, it seems that the client then uses a round-robin approach to choose which stub to use. If a stub endpoint is unreachable, the given query/mutation fails, and the client does not automatically failover to another stub. Please let me know if this understanding is incorrect.
Thank you!