I am considering two alternatives for a chat application back-end architecture:
- Server per room: where users connect to the same server, which forwards messages and other events directly. A database is used for persistence.
- Pros: messages delivered faster, more efficient, less servers involved
- Server per user: where each user connects to a server, which forwards messages and other events via a message broker (i.e. Redis) to other servers, which forward those events to users. Again, a database is used for persistence.
- Pros: simple architecture, users connect to a single server, more reliable
Note: the term "server" refers to not a physical machine, but a specific address/port.
What other pros and cons exist for each model? Which model would I use in what situations? Are there any other possible back-end architectures?
In case this is relevant: the application focuses on 2-user rooms (i.e. direct messaging) with less emphasis on groups, or very large rooms.
If this isn't the right Stack Exchange network to ask on, please let me know and I can move the question. Thank you!