sw360cab / websockets-scaling

A tutorial to scale Websockets both via Docker Swarm and Kubernetes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A tutorial to scale Websockets both via Docker Swarm and Kubernetes

License:MIT License


Languages

Language:JavaScript 85.5%Language:Dockerfile 14.5%