Perhaps, the simplest application needing this kind of scalability is a messaging (or chat) application; so, let's write one.
The initial single-server implementation has the following specifications:
There should be users and messages
Each user has a username, password, e-mail, list of friends, and a flag to indicate if the user wants to get messages from only their friends, or from everybody
For users, there are methods for:
Registering new users
Updating the list of friends
Logging in
Each message has a sender, receiver, message body, and timestamps for sending and reading the message
For messages, there are methods for:
Sending a message
Retrieving new messages
A minimalistic system implementing this, could look like the following:
Here, a web page opens a WebSocket (ws://
) to a HUB (a message concentrator) which in turn talks to a database. On each new connection, the HUB logs in and on successful login opens a WebSocket connection to the web page. It then sends...