# How to connect a golang client to multiple alpha servers

**URL:** <https://discuss.dgraph.io/t/how-to-connect-a-golang-client-to-multiple-alpha-servers/3925>\
**Category:** Dgraph\
**Created:** [January 24, 2019, 4:28pm UTC](https://discuss.dgraph.io/t/how-to-connect-a-golang-client-to-multiple-alpha-servers/3925 "2019-01-24T16:28:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgoodall](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jgoodall/32/1347_2.png) [@jgoodall](https://discuss.dgraph.io/u/jgoodall)\
**Post date:** [January 24, 2019, 4:28pm UTC](https://discuss.dgraph.io/t/how-to-connect-a-golang-client-to-multiple-alpha-servers/3925/1 "2019-01-24T16:28:03Z")

</div>

What is the correct way to connect a single go client to multiple alpha instances? In [the go documentation](https://docs.dgraph.io/clients/#create-the-client), it says: “You can connect to multiple Dgraph alphas to distribute the workload evenly.”, but there is no example of how to properly do that. There are a couple of other threads that raise this issue, but no actual code snippets. I assume you need to create a separate grpc connection and [api client](https://godoc.org/github.com/dgraph-io/dgo/protos/api#NewDgraphClient), and then pass those to the [dgo client](https://godoc.org/github.com/dgraph-io/dgo#NewDgraphClient), but I can’t seem to get it working as expected. Can someone post a snippet of how they are doing this?}

---

<div class="post-metadata">

**Author:** ![dmai](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/dmai/32/1254_2.png) [@dmai](https://discuss.dgraph.io/u/dmai)\
**Post date:** [January 24, 2019, 4:51pm UTC](https://discuss.dgraph.io/t/how-to-connect-a-golang-client-to-multiple-alpha-servers/3925/2 "2019-01-24T16:51:55Z")

</div>

The Dgraph Live Loader can connect to multiple Alpha instances using dgo. You can take a look at how it does that:

> <https://github.com/dgraph-io/dgraph/blob/a4756c206adc19b5ba640373407b30ef3a01f030/dgraph/cmd/live/run.go#L315-L325>

---

<div class="post-metadata">

**Author:** ![jgoodall](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jgoodall/32/1347_2.png) [@jgoodall](https://discuss.dgraph.io/u/jgoodall)\
**Post date:** [January 24, 2019, 5:53pm UTC](https://discuss.dgraph.io/t/how-to-connect-a-golang-client-to-multiple-alpha-servers/3925/3 "2019-01-24T17:53:26Z")

</div>

That is a big help, thanks!

For anyone looking in the future, note that `x.SetupConnection` uses `grpc.WithTimeout(10*time.Second))`, which looks to be [deprecated](https://godoc.org/google.golang.org/grpc#WithTimeout), so instead use [DialContext](https://godoc.org/google.golang.org/grpc#DialContext).

---

<div class="post-metadata">

**Author:** ![jgoodall](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jgoodall/32/1347_2.png) [@jgoodall](https://discuss.dgraph.io/u/jgoodall)\
**Post date:** [March 7, 2019, 11:24pm UTC](https://discuss.dgraph.io/t/how-to-connect-a-golang-client-to-multiple-alpha-servers/3925/4 "2019-03-07T23:24:46Z")

</div>

Will that approach, using multiple grpc connections for one client, round robin the mutations? We are seeing one node in a three node alpha cluster with way higher utilization.  
Thanks

---

<div class="post-metadata">

**Author:** ![dmai](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/dmai/32/1254_2.png) [@dmai](https://discuss.dgraph.io/u/dmai)\
**Post date:** [March 8, 2019, 11:45pm UTC](https://discuss.dgraph.io/t/how-to-connect-a-golang-client-to-multiple-alpha-servers/3925/5 "2019-03-08T23:45:39Z")

</div>

If you provide multiple Alpha addresses to dgo, then one will be picked randomly per transaction.
