hebel. today · 8 November 202673 / 73
Technology · Software Architecture Patterns
Scoped message routing replaces broadcast bottlenecks
Engineers at a ride-sharing platform replaced broadcast-style messaging with a scoped subscription registry to prevent egress bandwidth from scaling linearly with total connections. In the naive implementation, the server transmits every driver location update…
From 1 newsletter · 1 min read · one thing to try
Engineers at a ride-sharing platform replaced broadcast-style messaging with a scoped subscription registry to prevent egress bandwidth from scaling linearly with total connections (Hands On Kafka). In the naive implementation, the server transmits every driver location update to all 3,000+ connected riders, regardless of their location. This approach ties egress costs to the product of total connections and the total update rate, which creates a performance bottleneck that fails at city-scale concurrency.
Developers now implement a STOMP-based broker where riders subscribe only to specific H3 cells within their current K-ring, typically one to seven cells rather than the entire coverage area. The broker parses WebSocket text frames to route messages through a registry keyed by destination, ensuring updates publish only to the subscriber set interested in a specific cell. This mechanism shifts the scaling factor to the number of interested subscribers multiplied by the update rate for those specific cells, protecting the network link from saturation.
Try today · 45 min
Implement a destination-keyed subscription registry for your WebSocket message broker.
Identify your current broadcast loop and replace it with a map of client sets keyed by topic or cell ID.
You need
- WebSocket connection list
- Destination-to-subscriber map
- STOMP frame parser
Steps
- Identify the loop that iterates over all connected clients to send updates.
- Create a Map> structure to track subscriptions.
- Update the client connection logic to register the client to specific topics upon request.
- Refactor the message broadcast logic to look up the subscriber set for the target destination.
- Send the update frame only to the clients found in the destination's subscriber set.