Giter VIP home page Giter VIP logo

Comments (7)

mathe42 avatar mathe42 commented on May 18, 2024

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 / ...?

from surrealdb.js.

adileo avatar adileo commented on May 18, 2024

Thanks for your promptly reply, really appreciated :)

I've thought about using one connection only, but then I have to call the method await db.use('namespace123', 'db123') each time before handling an API request to switch between different dbs or namespaces, as far as I've seen there is a message submission through websocket to SurrealDb to switch the Namespace and DB each time, so it doesn't seem 100% efficient.

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:

  • Server side rendering for authenticated users
  • Public facing REST API (therefore the requirement to have a middleware between the client, 3rd party code, and the DB)
  • I prefer to have a middleware between the client and the DB also for flexibility purposes (monitoring, extensibility, complex authorization checks, etc...)

from surrealdb.js.

mathe42 avatar mathe42 commented on May 18, 2024

If you change ns + db yes that will not be optimal....

Would something like surrealdb/surrealdb#247 help you?

For your last point:

  1. monitoring -> just add a reverseproxy infront of surrealdb that can log / monitor stuff
  2. complex authorization checks -> I could not think of a use case that surrealdb can not handle... The permissons syntax is not well documented but powerfull!

from surrealdb.js.

adileo avatar adileo commented on May 18, 2024

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:
https://github.com/adileo/surrealdb-ts-client

from surrealdb.js.

martinschaer avatar martinschaer commented on May 18, 2024

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

from surrealdb.js.

martinschaer avatar martinschaer commented on May 18, 2024

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)

from surrealdb.js.

kearfy avatar kearfy commented on May 18, 2024

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)
Anyways, will also be adding an HTTP class in there to allow this kind of stuff

from surrealdb.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.