title: Should I share gRPC Stubs or Channels?
body: <p>The gRPC C++ API for creating channels returns a shared_ptr. The generated function NewStub returns a unique_ptr. However I've seen <a href="https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11244" rel="noreferrer">reports of people having issues</a> trying to create multiple instances of a stub type, sharing a channel. Their solution was to share the stub.</p>
  
  <p>It is not clear from the documentation or API if a client is meant to create multiple stub instances sharing the channel or share a single stub. Please clarify the conceptual relationship between stubs, channels, and unique client connections.</p>
  
  <p>Diving a little deeper:
  A server can serve more than one service and a client endpoint can use a single channel to connect corresponding stub types to each of those services. For that purpose, it is clear the different stub types share the single channel to talk to the server endpoint. Does gRPC expect only one client per channel for a given service or can I have multiple clients on the client endpoint talking to a single service? If allowed, how do I achieve multiple clients for a given service on a client endpoint? How does the server distinguish these as independent clients? </p>
  
  <p>As an aside, <a href="https://stackoverflow.com/questions/33197669/are-channel-stubs-in-grpc-thread-safe">This SO post</a> indicates both Channels and Stubs are thread-safe. (The post is specifically for Java, but I'm assuming it carries over to C++).</p>