superfly/litefs

Websocket connection on a replica node

Opened this issue · 3 comments

Working on a pet project, exploring distributed systems & LiteFS. I'm hoping that someone may be able to weigh in on this with a potential solution.

If I wanted to build a chat application whereby clientA & clientB may be connected to a replica node sending messages between each other this data will need to be persisted to the database (on the primary). I'm wondering how this would work.

The http-proxy wouldn't be useful here as a websocket connection is neither a POST/PUT/DELETE request. And I've thought about using halting or forwarding the request but the former solution isn't recommended for high-frequent queries, and the latter would just mean the primary will ever be used (maybe causing it to be overwhelmed).

I'm also using NATS (with Jetstream) as my messaging bus for this application so I'm not sure if utilising their KV API somehow and then propagating the KV store data to the primary litefs node?

As this is an experiential project I'm very open for suggestions, or elaborating if you require more info. Thanks

Browsing GitHub I was able to come across a similar issue in a different repo so will look into what they did to resolve this for themselves

@adoublef There's some docs on determining the primary node and you could also track the primary via the event stream. Your replica will need to do some kind of RPC to the primary node in order to perform the write.

@adoublef There's some docs on determining the primary node and you could also track the primary via the event stream. Your replica will need to do some kind of RPC to the primary node in order to perform the write.

I see, as I'm using Go, I've had a brief look into their 'net/rpc' package (I'm sure anything will work including grpc or an extra API point) so will determine which option seems to work best.

Since posting I've also learned that Jetstream clusters could be an opportunity for me to persist real-time data there, forgoing a trip to the primary sqlite node. If I'm successful with getting the embedded NATS server working for this solution then I'll use both Jetstream and SQLite in combination.