GrabVasu KrishnamoorthyProblem & solution
How We Built Our In-house Chat Platform for the Web
Summary
Grab extended its in-house chat platform to the web to support its internal Customer Support portal. Because the existing TCP gateway only supports unicast connections with one active connection per user, opening multiple browser tabs would repeatedly disconnect previous tabs. Rather than undertaking a complex migration to multicast connections on the server, the team adopted a hybrid client-side strategy using SharedWorker and BroadcastChannel APIs. The implementation uses a SharedWorker to maintain a single WebSocket connection per domain while a BroadcastChannel syncs events across all open tabs. A custom wrapper over the worker manages version transitions during deployments to avoid race conditions across tabs.
Context
Grab's TCP gateway enforced unicast connections that allowed only one active connection per user, which broke in web browsers when Customer Support agents opened multiple tabs simultaneously.
Approach / What changed
Grab used the SharedWorker API to maintain a single socket connection to the server across all tabs within a domain, combined with BroadcastChannel to synchronize outgoing and incoming chat messages across browser contexts.
Takeaways
Using a SharedWorker allows a browser application to maintain a singleton socket connection across multiple tabs within the same origin.
The BroadcastChannel API acts as an intra-origin message bus to keep chat state synchronized across active tabs when users send or receive messages.
Because SharedWorker uniqueness relies on script names and origin, separate tabs opened across a deployment can run conflicting script versions unless handled by a wrapper that yields control to the newest version.
Source and freshness
- Source
- engineering.grab.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.