Skip to content

A tutorial to scale Websockets both via Docker Swarm and Kubernetes

License

Notifications You must be signed in to change notification settings

sw360cab/websockets-scaling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scaling websockets

Intro

Purpose of this is achieving a scalable environment when WebSocket are involved. The pattern to reproduce is a Multi-Server to Multi-client communication via websocket.

The result should be a client connected to a specific server host and keeping its connection bound to it (sticky connection). Whereas the server hosts will broadcast messages in turn and all the connected clients should receive them. The latter will be achieved leveraging the pub/sub paradigm of Redis.

The application is made of server and client part. Both are based socket.io library.

Server

  • it employs a dedicated adapter implementing native Redis support.
  • an instance will advertise periodically its private ip. NOTE that this message should be received by ALL the clients connected.

Client

  • it is configured to employ native websockets, without attempting to use naïfes solutions as http polling.

    { transports: ['websocket'] }
    
  • it will send a message to a single server instance at connection time. NOTE that this message should be received only by a single server instance.

Stack of Microservices Scenario

See Stack configuration.

Kubernates Scenario

See Kubernates configuration.

References