All posts
  • Socket.io
  • Node.js
  • MongoDB

Building real-time chat for a multi-vendor marketplace

How I wired Socket.io into a MERN marketplace so vendors and customers could talk instantly — rooms, presence and message persistence.

Talha Sajid7 min read

When I started the marketplace project, chat felt like a nice-to-have. A week into testing it was clearly the feature customers used most — questions about sizing, delivery and stock all happened in conversation.

This post walks through the architecture I landed on, and the mistakes I made on the way.

One room per conversation

Every vendor–customer pair gets a deterministic room id built from both user ids. Joining is idempotent, so reconnects never create duplicate rooms.

Messages are written to MongoDB first and emitted second. If the write fails, nothing is broadcast — the client simply retries.

Presence without the pain

Online status is tracked in memory per socket and reconciled on disconnect. For a single server that's enough; with more instances it would move to Redis pub/sub.

What I'd do differently

I'd add delivery receipts from day one and paginate history with cursors instead of offsets. Both were painful to retrofit.