0

I'm developing a web application that has two main user roles : say role X and role Y. React will be used as the front-end interface, while Django will be used as the API endpoint. Say that it will be hosted under a domain name called myapp.com. Once the user logged in, it will be redirected to its respective subdomain according to the role--if the user has a role X, it will go to x.myapp.com, and if it's Y then to y.myapp.com.

But, the said application will have multiple 'customers' (different from users). Each customer wants to have their own database for privacy concerns, despite the app has exactly the same functionality. I have read resources regarding having copies of applications deployed to different servers, but that means maintaining each application on different servers separately.

Since React is an SPA and is detached to the backend, why not just host one React Site and one Django API connecting to different databases from different servers?

My plan is to host the React and Django in the main domain (myapp.com), and do some routing and establish some config files on React to display the proper page according to the roles (for x.myapp.com and y.myapp.com). Perhaps using nginx for this? For the database, there will be an intermediary database that contains a table containing copies of user data from each company's database. This is because user will sign in from the main domain and we need to know from what company that user came from.

Case Example:

  • userQ1 is X from company Q
  • userQ2 is Y from company Q
  • userW1 is X from company W
  • userW2 is Y from company W

When signing in, the backend will access the intermediary database first to check the user's credentials and to what company that user belongs to. I've heard implementing SSO here.

userQ1 will be redirected to x.myapp.com, while userQ2 will be redirected to y.myapp.com with the same API endpoint of e.g. api.myapp.com/q/. The backend will access the company Q's database. While userW1 will see the app through x.myapp.com, with a different endpoint of api.myapp.com/w/ connected to company W's database. Or maybe this can be done with the same endpoint address, but pointing to different database with some logic written inside the Django app. I've also heard of implementing message broker here?

I don't know whether this setup is feasible nor would it be a good idea to implement.

I have provided a rough sketch to illustrate the case.

Rough illustration

I am very new to deploying apps, and have a very limited knowledge and skillset regarding the topic. Any suggestions and insights are welcome. I am very sorry if this sounds very specific but I really don't know where else to ask.

Thank you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.