title: Application sharding communication best practice?
body: <p>Good morning everyone,</p>
  
  <p>I am working on a client-server game application with this connection architecture in mind:
  <a href="https://i.stack.imgur.com/pFv4s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pFv4s.png" alt="enter image description here"></a></p>
  
  <p>I just finished the login section: The client auth on google play, send a token+userid to one login server, the login server auth the data with google play and create a session on the database for that user.</p>
  
  <p>My Idea is on a successfully login, the login server talks with one of the Main Servers to register an expected client, close the connection to the login server, then the client connect to that server. I want to have multiple Main Servers for scaling and localization, but then the question is how to manage client-client interaction when clients are on different Main servers? Whats the best practice? </p>
  
  <p>Lets think about a simple "friend connected" notification system. So Imagine all the clients on the schema are friends, Client 2 and 3 are already connected, Client 1 connects, Main Server build a client model on Client 1 connection that will have a list of friends (that contains an online status and Connected ServerID if online). It will group online friends by server, and send a bulk friend_connected packet to these Main Servers and these notify the users (if is the same server just send the friend_connected to each user). </p>
  
  <p>So should I create a TCP Socket connection between all Main servers? Is my first time building a multiserver structure so not sure if there is a better/easier way to manage it. I thought about a middle servers to manage messaging between Main Servers but probably is only worth when your system have hundreds of servers so each Main server only have 1 socket to the closest message manager.</p>
  
  <p>Login servers dont need to be interconnected since there is no client-client communication, it just manage an incomming connex, auth the client and setup the session.</p>