TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: WebSocket server transforming channel subscriptions to gRPC streams

1 pointsby FZambiaalmost 2 years ago
Hello! I&#x27;d like to ask your opinion about the idea of a WebSocket server which can handle WebSocket connections, can manage channel subscriptions and transform them to GRPC streams to a custom backend server.<p>Let&#x27;s say we have a system with 3 participants like this:<p>Client (browser, mobile device, etc.) —&gt; WebSocket server (the subject to implement here) —&gt; Backend server (any custom server in any language with good GRPC support).<p>Then the mechanics is as follows:<p>* Client establishes WebSocket connection with WebSocket server<p>* Client can optionally subscribe to channels. Subscriptions to channels are multiplexed over a single WebSocket connection.<p>* Upon receiving WebSocket connection (or subscription to channel) server can open unidirectional or bidirectional stream with the configured backend which implements GRPC service.<p>* Backend may stream data to connections or to channel subscriptions over established GRPC streams. Data from GRPC streams will be transformed to WebSocket messages and delivered to clients with minimal latency.<p>* Additionally, client can stream data to the backend server (if bidirectional GRPC streams are used). I.e. client sends WebSocket messages, those will be transformed to GRPC messages by WebSocket server and delivered to the application backend.<p>As a result we have a system which allows to quickly create individual streams by using strict GRPC contract but terminating connections over WebSocket transport. So it works well in web browsers. After that no need to write WebSocket protocol, client implementation, handle WebSocket connection. This all will be solved by a suggested WebSocket server and its client SDKs.<p>The mechanics is similar to Websocketd (https:&#x2F;&#x2F;github.com&#x2F;joewalnes&#x2F;websocketd), but instead of creating OS processes we create GRPC streams. The difference from grpc-web (https:&#x2F;&#x2F;github.com&#x2F;grpc&#x2F;grpc-web) is that we provide streaming capabilities but not exposing GRPC contract to the client - just allowing to stream any data as payload (both binary and text) with some wrappers from our client SDKs side for managing subscriptions. I.e. it&#x27;s not native GRPC streams on the client side - we expose just Connection&#x2F;Subscription object to stream in both directions. GRPC streams used only for communication between WebSocket server and backend. To mention - grpc-web does not support all kinds of streaming now (https:&#x2F;&#x2F;github.com&#x2F;grpc&#x2F;grpc-web#streaming-support) while proposed solution can. This all should provide a cross-platform way to quickly write streaming apps due to client SDKs and language-agnostic nature of GRPC.<p>I personally see both pros and cons in this scheme (without concentrating on both too much here to keep the question short). I spent some time thinking about this myself, already have some working prototypes – but turned out need more opinions before moving forward with the idea and releasing this, kinda lost in doubts.<p>My main question - whether this seems interesting for someone here? Do you find this useful and see practical value?

no comments

no comments