Using gRPC service definitions as an interface for multiple instances

Viewed 829

Let's assume that we have a Search-Service

service Search {
  rpc Search (SearchRequest) returns (SearchReply) {}
}

message SearchRequest {
  string query = 1;
}

message SearchReply {
  repeated string message = 1;
}

Now, let's consider we multiple search engines that are all supposed to implement that interface to provide search.

The wall I am hitting is that gRPC only allow a singleton of the Search service behind a single IP:PORT pair. So, the only way to integrate multiple search engines in an environment is to put each behind a different IP:PORT, it's impossible to have them on the same port.

1 Answers

You can't have multiple instances of the same service on the same server. There are three main ways to solve the problem, depending on the flavor of your problem:

  1. Combine results
  2. Include a request parameter
  3. Use different service names

If the "multiple search engines" are semantically equivalent, then a separate method isn't necessary and instead respond with aggregated results.

If the "multiple search engines" are data-dependent, then include another parameter in SearchRequest, like string dataset = 2;.

Otherwise make separate services: ImageSearch and WebSearch.

Related