dosco / graphjin

GraphJin - Build NodeJS / GO APIs in 5 minutes not weeks
https://graphjin.com
Apache License 2.0
2.91k stars 177 forks source link

Subscription transports #403

Open gedw99 opened 1 year ago

gedw99 commented 1 year ago

What would you like to be added:

I am wondering if there is merit in adding an option to use SSE for subscription updates ?

Why is this needed:

Partly because I am having problems with web sockets and so reaching out to see if SSE would be better. It’s a far simpler protocol .

I am also curious how the backend manages what users are subscribed to what . Is this able to be inspected somehow or even better to have that data available as a change stream over SSE.

dosco commented 1 year ago

I'm not familiar with SEE can you share some links? The backend groups (with sharding) subscriptions to a single query together (each subscriber can have different variables) into a single query execution and then polls for changes using this. If any unified response has updates then the subscribers who those updates are for are sent the updated result.

For example if 10K folks subscribe to a query for new blog posts and each of them has a different list of followers then this will result to about 20 queries to the db for every polling instance. In short as efficient as can be and designed to be horizontally scaleable and use the most efficient DB interface SQL itself.

gedw99 commented 1 year ago

Ok so SSE is this: https://en.m.wikipedia.org/wiki/Server-sent_events

it’s built into browsers and there are golang ( and other libs ) for non browsers.

it’s quite a simple protocol.

This all came up for me because I was looking to decouple the subscription events transport from graphjin. For example I could stick the events into anything durable like a message queue and then push them out over SSE or a thing really. It’s basically a decoupling of the Transport for the Subscriptions. Sone people might even want to send a web hook to another server for example.

Thank you for the explanation of the Logic of how the system manages subscription. It’s an awesome design.

I am trying to come to grips with the client-side . A golang graphql package that works with graphjin subscription would be nice if you know of one. I could then experiment from the terminal with a minimal golang cli so I can experiment.

anyways looking forward to your thoughts.