3

I have been trying to understand how one would scale an application utilizing tcp/ip sockets for client server communication. For example in the simple diagram below:

        +------------+
        | Server     |
        +------------+
           |      |
           |      |
           |tcp/ip|
           |socket|
          connections 
           |      |
           |      |
+------------+  +------------+
| Client_001 |  | Client_002 |
+------------+  +------------+

Two clients are connecting to one server. An action can be performed, and the result can be sent to all clients connected to the server. This is all fine and dandy. However if one were to introduce some additional applications servers behind a load balancer like such:

+------------+  +------------+
| server_001 |  | server_002 |
+------------+  +------------+
          |       |
          |       |
        +------------+
        | HAProxy    |
        +------------+
           |      |
           |      |
           |tcp/ip|
           |socket|
          connections 
           |      |
           |      |
+------------+  +------------+
| Client_001 |  | Client_002 |
+------------+  +------------+

The clients would be making connections to the load balancer, the load balancer would then be delegating the connections to one of the two servers.

Lets pretend that client_001 executes the program and the load balancer connects them to server_001, then client_002 executes the program and the load balancer connects them to server_002.

server_001 performs an action on behalf of client_001 and sends in response a byte stream to all connected clients. However, since client_002 is connected to server_002, it does not receive this byte stream.

Which leads me to my question: How can you send a response to all connected clients independent of which server they were connected to via the load balancer?

3

I would recommend looking at distributed pub/sub frameworks. Even if you decide to implement it yourself with TCP/IP instead of using the framework, their architecture should still provide inspiration. ZeroMQ handles this use case, and so does Redis.

You can read about how ZeroMQ handles pub/sub here.

Redis does distribution by sharding the dataset into chunks. Each Redis server is responsible for a shard. You would try to design your shards in such a way that clients will be fairly evenly distributed among shards.

You can have server_001 connect to server_002 as a client and when it receives a message, it can relay the message to all clients connected to it.

  • Sharing messages between servers is a good approach. – user251748 Sep 26 '17 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.