Developing Multi Tenant functionally for Nopcommerce... brain storming

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
Hi Guys!

I was wondering if anyone could give me their thoughts on what the best way to develop a multi tenant functionality for nopcommerce 3 from a development standpoint.  

Basically, I would like to be able, from the nopcommerce admin, to create stores on sub domains that could be run completely dependent of each other.  but would run off the same main code.  I am looking to build something like what orchard has here or the multisite for wordpress here.

What are the development steps that would have to be taken to create something like this in nopcommerce?  Also, from a development standpoint, how complicated would this be and what would be the basic things that would have to be done?

I would mainly like to have the ability to add stores as sub-domains.  For example, if my main site is mysite.com then I would like to be able to add store1.mysite.com from the admin.  Using C# and MVC is there an easy way to create sub domains without having to creating them from your hosting control panel?  

Also, if I decided to change a store from a sub domain to a different domain could I use the same approach as the nopcommerce multi site?  Is there some type of mapping that could make that work?

Could the multi store functionality be used as a base to develop the multi tenant functionality?

I am just brain storming at this point and would love to hear your thoughts.
10 years ago
Tim2376 wrote:
Hi Guys!

I was wondering if anyone could give me their thoughts on what the best way to develop a multi tenant functionality for nopcommerce 3 from a development standpoint.  

Basically, I would like to be able, from the nopcommerce admin, to create stores on sub domains that could be run completely dependent of each other.  but would run off the same main code.  I am looking to build something like what orchard has here or the multisite for wordpress here.

What are the development steps that would have to be taken to create something like this in nopcommerce?  Also, from a development standpoint, how complicated would this be and what would be the basic things that would have to be done?

I would mainly like to have the ability to add stores as sub-domains.  For example, if my main site is mysite.com then I would like to be able to add store1.mysite.com from the admin.  Using C# and MVC is there an easy way to create sub domains without having to creating them from your hosting control panel?  

Also, if I decided to change a store from a sub domain to a different domain could I use the same approach as the nopcommerce multi site?  Is there some type of mapping that could make that work?

Could the multi store functionality be used as a base to develop the multi tenant functionality?

I am just brain storming at this point and would love to hear your thoughts.


It seems it is quite a task
https://www.nopcommerce.com/boards/t/21211/nopcommerce-300-roadmap-lets-discuss.aspx?p=20#93767
10 years ago
It is a big task, but what would you recommend?  Would it be better to have all the tenants use one database or have a separate database for each one?  

Does anyone know how others have implemented the tenant ability in applications?  How could something like this be done and what would be the best approach?  I have the basic idea of what I would like to implement and develop, but I am having a hard time knowing where to start and how to do it.

For example, I know there has got to be some way to develop the ability to create a sub domain through code... has anyone here done something like that before?  

What is the basic best approach for developing this tenant capability?  I am still in the brain storming stage. Thanks!  :-)
10 years ago
Hi,I think that links may help

http://msdn.microsoft.com/en-us/library/aa479069.aspx

http://msdn.microsoft.com/en-us/library/aa479086.aspx

http://msdn.microsoft.com/en-us/library/ff966499.aspx
10 years ago
Hi Keem,

Thanks for the links!  I have started to look at them... its a lot of great information.  I appreciate you sharing them with me.
10 years ago
hi
did you get anywhere on this
Can we use Seperate DB for tenancy. eg:
http://tenant1.someSite.Com
http://tenant2.someSite.Com

then somewhere convenient maybe a action filter we do a
read from config for the connection string named by tenant ?

hmmm - so to programatiically add new tenant we have to 1- create new db + tables + add config entry with the tenant name..
seems messy but I think that would work.
10 years ago
deltaoo wrote:
hi
did you get anywhere on this
Can we use Seperate DB for tenancy. eg:
http://tenant1.someSite.Com
http://tenant2.someSite.Com

then somewhere convenient maybe a action filter we do a
read from config for the connection string named by tenant ?

hmmm - so to programatiically add new tenant we have to 1- create new db + tables + add config entry with the tenant name..
seems messy but I think that would work.


Hi Deltaoo,

Thanks for posting!  I am still in the brainstorming stage. :-)  

From the articles that Keem posted, it looks like the best idea it to have separate databases instead of one database for multi tenants functionality.  The only concern I have is upgrading, for example if you have 2000 tenants you would have to upgrade each database.

From the sounds of it though, separate databases make it easier to get started, and keep the tenant's data separate, however in the long run it will cost a little more then the shared database approach.  I know that wordpress uses the shared database approach and orchard uses the separate database approach.

Since the separate database approach is easier I think it would be best to start with.  Also, since Nopcommerce and Orchard are both ASP.NET MVC we might be able to draw from some of the ideas they used.

Do you think this approach would work?

I was wondering if it could work as a plugin.  I am thinking we would need the following parts:

1) The ability to create a new database for each tenant

2) Have a table for this plugin that would, like you said, contain all the info for the tenant. Like name, etc.

3) The ability to have a wild card " * " sub domains that would allow nopcommerce to know what tenant to display.  For example:  If you typed in site1.yoursite.com, it would do a search for a tenant who's site name was site1 and then somehow use that to connect to the correct database to show site1.  

4)  The ability to suspend/delete a tenant.  

5) Someway to allow all tenants to "connect" to one code base.  We don't want multiple copies of the nopcommerce code.  I am really confused about this part.  I am not sure how the controllers, modal and views can all work with multiple different databases.  To do all this, would we have to have different config files for each tenant or could we use the wildcard sub domain to allow the main site decide what tenant to show?

Do you think all this is possible as a plugin so we did not have to change the main nopcommerce code that much?  As for item 3, I think this is the approach that wordpress uses.  When you enable the multisite on wordpress, you have to create a wild card sub domain like *.yoursite.com.  This allows wordpress to create the sub domain look without you having to manually create the sub domains from your hosting admin.

The only trouble it is seems kind of hard to grasp how it all works. :-)  Can anyone explain item 5?

I would really appreciate everyone brainstorming this out with me.  I am sure we will be able to figure it all out if we work together.  What do you think of the list that I have?

Let me know what you think.   Thanks!

Regards,

Tim
10 years ago
Hi Tim
thanks
the described approach is what I am planning.

Not sure about the plugin . I've not used that at all- I think the single code base will be ok as long as you can switch dbs and you want all the tenants to have the  same functionality -
Once you start adding custom functionality to each tenant - it might get tricky - Not impossible -

May I should download the code first ;) to see it ..

Have you done anything in the way of coding this already ?

thanks
10 years ago
deltaoo wrote:
Hi Tim
thanks
the described approach is what I am planning.

Not sure about the plugin . I've not used that at all- I think the single code base will be ok


Hi deltaoo,

Sorry it took me so long to reply.  I think I understand how to do the single code base better.  If it could be implemented as a plugin I think that would be the best option for future nopcommerce upgrades but it might be easier to just hard code it first.

deltaoo wrote:

May I should download the code first ;) to see it ..

Have you done anything in the way of coding this already ?

thanks


I am still in the brain storming stage. :-)

I think I have found a way to code the initial ability to detect the wild card sub domain to allow you to connect to a different database but I still need to know the following

1)  How to create a blank database using c# through a plugin and automatically installing nopcommerce on this blank database using predefined information from the tenant.  You would already know the SQL credentials but you would need to use the tenant defined admin email, password, and store name.

2) Once I use routing code to be able to detect the sub domains and pass this information, I need to know the best way to use a controller or something to use this information to look up and connect to the tenants database.

Do you have any ideas for these parts?

The other thing we would have to look into is how to restrict the plugins the be based off of roles.  You don't want the tenant to have access to the multi tenant plugin, but they do need to see the other plugins.  

Even if in the end a plugin is not the best approach, we need some way to restrict the tenants so they would not be able to access the the site admin multi tenant capability.  Right now I am thinking the best appraoch for this part would be to use a new customer defined role that could be used to add restrictions.
10 years ago
Hi,for querying multi-tenant databases, I found this library http://enzosqlshard.codeplex.com/ from the links I previously mentioned,I haven't try it yet!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.