Anatomy of a chat backend
A real chat system is the sum of small, well-defined pieces: rooms (Track 4), message protocol with envelopes (Track 5), connection identity (Track 4), persistence to a database (here), typing indicators, read receipts, and history fetch on connect. None of them are individually hard; the discipline is keeping them composable.
Persistence is REST, real-time is push
The most common production pattern: chat messages POST to a REST endpoint that persists to a database AND fans out via WebSocket. The WebSocket is for liveness; the database is for history. Reconnecting clients fetch history via REST GET /messages?since=..., then receive new messages via WebSocket. Two paths, one source of truth.