Make Servers Discoverable

Distributed Services with Go — by Travis Jeffery (64 / 84)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Load Balance on the Client in gRPC | TOC | Resolve the Servers 👉

Our resolver will need a way to discover the cluster’s servers. It needs to know each server’s address and whether or not it is the leader. In Implement Raft in Our Service, we built Raft into our service, which knows the cluster’s server and what server is the leader. We can expose this information to the resolver with an endpoint on our gRPC service.

Using an RPC for discovery will be easy because we built Serf and Raft into our service already. Kafka clients discover the cluster’s brokers by requesting a metadata endpoint. Kafka’s metadata endpoint responds with data that’s stored and coordinated with ZooKeeper, though the Kafka developers plan to remove the dependency on ZooKeeper and build Raft into Kafka to coordinate this data, similar to our service. This will be a big change in how this data works in Kafka, specifically with how it manages what servers are in the cluster and how it elects leaders; however, little to nothing will have to change with how the clients discover the servers, thus showing the benefit of using a service endpoint for client-side discovery.

Open the api/v1/log.proto file and update the Log service to include the GetServers endpoint like so:

ClientSideServiceDiscovery/api/v1/log.proto

​ ​service​ Log {
​ ​rpc​ Produce(ProduceRequest)…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.