A chat backend is the classic WebSocket demo: open a socket, broadcast whatever comes in, done in fifty lines. Then you start asking what happens at the edges. Someone leaves a room but still has a tab open on it. A message gets broadcast, and the process restarts before it's saved. An access token expires while the socket it opened stays connected for three days. One client sends a thousand messages a second.
Those edges are what this article is about. We'll build a chat backend in Node.js with NestJS 12, Socket.IO and PostgreSQL: rooms with members, messages that arrive live and are stored before anyone sees them, a history clients page through over REST, presence and typing indicators, and a rate limit per user. Every file is here, along with the commands, the migration, the end-to-end tests and a production checklist.…