This project is a prototype of a scaling architecture for a collaborative Kanban web app with live updates via websockets.
I did this to gain more experience with technologies I was curious about:
- Docker compose
- Rust backend
- Websockets
- Pub/Sub
- Distributing load between multiple backends
I did not create unit tests as this is just a small prototype
- Install docker.
- Clone the repository.
- Run the
run-demo.sh
bash file. This starts all services including 2 backend instances, edit the file to use a higher number of backend instances (changebackend=2
tobackend=6
for example). - Open http://localhost:3500 and select a board.
- Open the board in multiple tabs and make changes to the board. The changes should be synchronized between all tabs.
- The backend logs (
docker compose logs backend -f
) should indicate that multiple backends are serving clients.
I wanted to create a solution that would support editing of the same kanban boards by multiple users across multiple backend instances.
Was really easy to set up: The configuration is completely inside the docker compose file. Traefik also reacts to up and down scaling without restarts and the configuration can be inspected via a frontend on http://localhost:8080.
Seemed like a good alternative to Actix (it is developed by the Tokio team).
I created this frontend 2 years ago and reused it for this prototype (it still uses react-beautiful-dnd
).
Nats claims to be easy to set up (it was) and I just wanted to try it out.
I decided to use MongoDB as it is easy to set up and to adjust the data layout.
- Load balancer distributes incoming requests for the backend to the available backend instances
- Frontend establishes Websocket connection to a backend instance for the current board. The frontend will then receive updates to the board made by other users via this connection.
- User changes to the board are sent from frontend to a backend instance via
PUT
calls - Backend instance modifies the boards document in the MongoDB collection, increments a
version
field and sends updated board inJSON
response to frontend. - Backend instance then publishes a message to Pub/Sub containing the new
JSON
representation of the board - Pub/Sub distributes the updated kanban board
JSON
representation to all subscribed backend instances - Subscribed backend instances notify connected frontends about change to the kanban board via the Websocket connections of step 2
- All notified frontends update their board state if the
version
of the received board is newer