-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat: make schema controller and schema cache stateless #7951
base: alpha
Are you sure you want to change the base?
feat: make schema controller and schema cache stateless #7951
Conversation
Thanks for opening this pull request!
|
Thanks for this PR, it seems to be quite a significant one at the internals of Parse Server, so could you provide more details about what the PR changes and whether there are any breaking changes? |
So @mtrezza answering Your question.
So to sum up:
|
Sounds great, let's wait for some more review feedback just to be sure. In the meantime, could you rebase this onto alpha and take a look at the failing tests? (Ignore the flaky, unrelated tests failing). You can run each of the tests also locally (see package.json for npm commands). |
Hi @pzawadzki-pronos , thanks for your PR ! 👍 After some reading on the issue, a quick look at the changes. I've some questions and maybe some doubts if this PR could be merged into the parse-server code base. Parse Server is not currently designed in many aspects to handle multi-tenant requests directly. As I understand in your use case, you send all queries to a single Parse Server deployment type (could be many parse-server with a single configuration behind a load balancer). Then on the fly, you may use a request header or a Parse.Object field to detect the target database. Based on this field you manipulate the Mongo connection string and maybe some other properties to send the query to the right database and handle the response correctly. From my point of view. Without the complete code to correctly handle multi-tenant requests, your suggested changes will be not usable by the community. These changes are specifically designed for a multi-tenant use case. In this case, the complete multi-tenant implementation should be supported/documented. From my knowledge of parse-server it means (this is a partial list, it needs a deeper investigation):
It seems that you succeed in using parse-server in a multi-tenant use case 👏 . Could you provide additional details about which changes you needed to make it work properly and the limitations encountered? I think multi-tenant compatibility will help the community and show how parse-server is versatile, but we need to do this with the complete experience of working out of the box. 🚀 |
Multitenant is not the only use-case. Other are: Back to questions about multitenant:
|
ed338bb
to
c603bb2
Compare
59215e6
to
e6d7d8f
Compare
I can see your point of view. A stateless parse-server will play better for many uses case, but the Schema cache is technically already stateless. Parse Server stores the whole schema architecture into the _Schema table/collection, and parse pull this schema from the database when it's needed. Developers have also the control to clear the schema when they want. I think stateless is not the correct word here maybe. It seems that you try to achieve "multi-schema" support that will be relevant mainly in a multi-tenant config.
You are right, singleton is terrible and does not play well in many use cases, it can break the code isolation. And your use case shows the limitation of Parse. Cloud and Parse JS SDK singleton. This is not hard to fix I think but it needs a deeper look inside the parse-server and a separate PR.
Also a multi-tenant use case. In a "traditional" parse-server config, a parse-server works commonly with one database. Then nothing will be faster than storing the Schema in the memory (like the alpha current implementation).
I'm scared for you about maybe a concurrency issue. Did you check with high concurrency parallel usage that the cloud function works correctly? Parse Server is currently not designed for this type of usage, you can land with deep side effects.
On my side, I can say that the parse-server is not designed to handle this kind of use case, you could have a hard to making it work properly on a specific use case, or you could be completely blocked on the issue/bug related to the internal architecture of parse-server. And I think it will never be supported since it needs a tremendous internal refactor to support correctly a "multi-tenant" out of the box. We have many features that will not work like DefinedSchema, LiveQuery, and maybe GraphQL. I'm personally not in favor of this PR. In another hand, I can suggest you take a look at managing the multi-tenant at a higher level (network/gateway). Many companies have switched to GraphQL to handle correctly at scale the multi-tenant use case, and to only expose one documented API. This is GraphQL/Apollo federation Gateway https://www.apollographql.com/docs/federation/ it allows you to stitch/merge/manage/connect many (Remote or in memory) GraphQL Schema into one big GraphQL schema. In your use case, you could deploy 1 parse-server with its specific config for each tenant. Then you have another GraphQL Federation serve (a simple express lightweight app) that manages all queries. In the GraphQL federation server, you can easily introduce some custom business logic to handle correctly relations and more. Note: your Cloud code on a tenant will also be able to query your public GraphQL gateway federation server with a master key. I hope it could help 🚀 |
c603bb2
to
1f71dc8
Compare
"I can see your point of view. A stateless parse-server will play better for many uses case, but the Schema cache is technically already stateless. Parse Server stores the whole schema architecture into the _Schema table/collection, and parse pull this schema from the database when it's needed. Developers have also the control to clear the schema when they want. I think stateless is not the correct word here maybe. It seems that you try to achieve "multi-schema" support that will be relevant mainly in a multi-tenant config." In the code of parse-server there is support to create multiple parse-server instances (with different app id) on the same process of node. You can provide there different databases. The only limitation is that You cannot use cloud code on the server (that's why I cannot use this approach - in our application there is a lot of cloud code). And there, this singleton schema cache, can lead to some problems. So the question is -> if Parse is still supporting this option? |
New Pull Request Checklist
Issue Description
Currently Schema-controller, database-controller and schema cache is a singleton and it makes whole parse-server statefull
Related issue: #7950
Approach
The concept is to make schema logic stateless and make possible to override in parse-configuration schema cache, so that it is possible to e.g cache it in Redis or another custom solution
TODOs before merging
NA