Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket connection on a replica node #418

Open
adoublef opened this issue Nov 10, 2023 · 3 comments
Open

Websocket connection on a replica node #418

adoublef opened this issue Nov 10, 2023 · 3 comments

Comments

@adoublef
Copy link

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

@adoublef
Copy link
Author

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

@benbjohnson
Copy link
Collaborator

@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
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants