-
Notifications
You must be signed in to change notification settings - Fork 45
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
Stateless Websocket Client #61
Comments
The overhead is smaller than you think (if you use http2). The connection is reused with http2 so you have only 1 connection to your server! But you are right if you have 1000 or more connections that is bad. Solution: Use only 1 db-user in your backend server! (And therefore 1 connection) Also why don't connect directly to surrealdb by your app / webpage / ...? |
Thanks for your promptly reply, really appreciated :) I've thought about using one connection only, but then I have to call the method Since I'm building a multi-tenant app some parts of the app are in common (eg. users, billing, etc..) while other are namespaced on the tenant side, hence the requirement of having the APIs to perform operations across namespaces/users on multiple incoming API requests without opening a lot of connections. I'm not connecting directly from the frontend mainly for 3 reasons:
|
If you change ns + db yes that will not be optimal.... Would something like surrealdb/surrealdb#247 help you? For your last point:
|
It seems an interesting feature. Great insights for point 1 and 2, of course the documentation doesn't help a lot but by looking at the code it's seems a very promising project. At the end I ended up creating my SDK ORM library: |
I think this is still an open issue. A stateless connection would be useful when deploying a Next.js app to Vercel. I'm working on a next-auth adapter for SurrealDB and it's not working on stateless cloud functions. I need just a few and very specific queries, so I'll do the fetches myself. This ORM provides stateless connection for SurrealDB: https://github.com/StarlaneStudios/cirql |
Hi @kearfy @tobiemh 👋 Could we reconsider this? In some scenarios its required a stateless connection to surreal from nodejs (like with next-auth on vercel nextauthjs/next-auth#6251). The current official nodejs driver only supports websockets. A good example is cirql (https://cirql.starlane.studio/docs/guide/stateless) |
Heya, I'm refactoring the whole socket bit of the library in #95 and also changing things up so we can have a sort-of interchangable class for WS and HTTP (the methods are different of course, so it will never be entirely the same, oh well) |
Right now each client created through this SDK is opening a stateful websocket connection to SurrealDb where you need to login or switch the namespace/db before performing any operation.
await db.signin({...})
await db.use('test', 'test');
This works well in a situation where the connection is created from multiple devices, or you need real-time data, but seems to add a bit of overhead in a backend server situation (eg. API) where you need to handle multiple concurrent connections across different users, namespaces or databases. Each combination will require a new client to be opened, cached and closed server side, resulting in a lot of overhead. Essentially a single server will have hundreds, if not thusands, of websocket connections opened to the same SurrealDb instance.
Maybe this could be solved by allowing to override the user/namespace/db on each specific SQL request.
Right now I'm working around this by creating a custom Typescript SDK based on the REST interface of Surrealdb, but wanted to be sure that I'm not missing something here or if it is already possible with the current websocket connection.
Thanks
The text was updated successfully, but these errors were encountered: