Short answer: For a Node.js realtime chat room, backfill history from your database before subscribing, then deduplicate the overlap by message ID. Persist each message before publishing it; this makes presence and message freshness observable while keeping the transport replaceable.
The safest design for showing who is online in a shared workspace is to backfill the last messages from your database, then subscribe to the room for newer events. Put a stable message ID on every event. That ordering makes the join boundary auditable and keeps the realtime provider replaceable.
This is an architecture decision record for a B2B SaaS team chat. The important metric is presence accuracy: a user should not see an apparently current room that silently missed a message while the join request was in flight.…