• LightSwitch Multi-tenancy – Introduction

    Posted Nov 7th, 2013 By in Cloud Computing, LightSwitch With | No Comments LightSwitch Multi-tenancy – Introduction

    It would appear that the top suggested topic on the PaulSPatterson.UserVoice.com site is the Automated Multi-tenant Applications topic. I kinda figured it would be a popular suggestion because it is one that I have been wanting to try for some time now.

    So, with that being said, I am going to create a proof-of-concept multi-tenancy solution using LightSwitch, and blog about it in the hopes that you can learn from what I do (and do not). Keep in mind that I just said I am going to create something. I have only just started investigating how to do this, and haven’t actually started anything yet.

    Proof-Of-Concept

    Before I hunker down with the low level stuff, it would help op define some scope for my proof-of-concept. I thought I’d brainstorm a bit and jot down a bit of a usage scenario to help me set some boundaries about what I am going to be doing.

    I am thinking of this as a usage scenario…

    • A person will navigate to a New Tenant registration System (web site).
    • The person will enter information about their organization, as well as information about their default tenant administrator user.
    • The System will save the new Tenant information, as well as create the default Tenant Administrator User.
    • The System will send an Email with a hyperlink containing unique new user registration confirmation code.
    • The User will open the email and navigate to the registration confirmation website using the URL in the email.
    • The System will inspect the confirmation code and activate the new User.
    • The System will then present the User with the login screen (for the LightSwitch application)
    • The user will enter their credentials and press the login button.
    • The System will evaluate the login credentials to authenticate the user.
    • The System will present the User with the home screen.
    • The System will perform data actions that are in the context of the Tenant that the User is for. No other Tenant data will be accessible to the user.

    Albeit there is some work to do for the registration system, but that is something that needs to happen anyway. But before I even start on that, I want to take a look at some high-level concepts that talk to multi-tenant architectures.

    Data Isolation

    One of the first articles I found, and arguably the most relevant to what I am trying to achieve, is this 2006 MSDN article titled  Multi-Tenant Data Architecture. The article talks about three approaches to managing multi-tenant data, which is essentially what I want to do.

    What I need to first determine is what degree of isolation I want to use for the data in my application. Do I need to have tenant data completely isolated from other tenant data, such as in separate databases, or can the data for each tenant reside within a shared environment?

    multi-tenant-approach-001(image source: Microsoft - http://msdn.microsoft.com/en-us/library/aa479086.aspx)

    Let’s have a bit of a discussion on this degree of isolation stuff.

    Separate Databases

    The first approach would be isolate the data by creating separate databases for each tenant. This would certainly provide for an easy way to logically separate the data for each tenant. To implement this approach, I would have to create functionality that provisions a new database for each new tenant registration. I would then have to engineer the LightSwitch client to dynamically connect to the appropriate database with each user log in. To me, this would require more maintenance work than I am willing and able to perform.

    Separate Schemas

    I suppose I could try and stick with one database and then create separate database schemas for each tenant, but how much different, really, is that to using separate databases? Yeah, I can take advantage of the fact that I am using just one database, however I still have the same scale application connectivity functionality and maintenance , for the most part anyway, as that of having the separate databases. So where am I better off on this one?

    Same Database

    How sharing all tenant data in one database, with one schema? Having a shared repository for all tenant data would certainly mitigate most of my concerns regarding database maintenance. The single database and schema would eliminate the need to have any requirement for dynamic data connections.

    LightSwitch has the flexibility to be able to apply row level filtering to data sources. This is a great feature that presents an excellent opportunity to abstract and contextualize  tenant data in the application. By applying filtering to the data, I should be able to serve up only the data the logged in user has access to.

    multi-tenant-approach-002(image source: Microsoft - http://msdn.microsoft.com/en-us/library/aa479086.aspx)

    My Approach

    Well, you can probably already tell which approach I am going to take with the creating of this prof-of-concept. I am going to use a single database, with a single schema. I am going to leverage row-level filtering to only allow users to work with the data for the tenant that the user is attached to.

    Having said that, here is what I intend to do:

    • Create a Tenant Registration system – an ASP.Net MVC web application
      • Create a user registration confirmation messaging system
      • Use an Azure SQL database as the data store
      • Use SendGrid for messaging
    • Build a LightSwitch application
      • Leverage row level filtering,
        • possibly use some kind of pattern so that the filtering is applied globally, rather than manually creating filters for each data entity.

    Well? How does all that sound? Let the journey begin!

    • delicious
    • digg
    • reddit

    Paul
    My name is Paul Patterson and I am a software developer who has a keen interest in technology, including; open source, .Net, and anything Interweb. When not crafting some code, I can be found learning something new about photography. As well, I occasionally escape to the "music room" with my guitars to practice a few scales and then jam with my favourite FM radio stations.

Leave a Reply


No comments yet. Be the first!

© Copyright Paul S Patterson - Please, no touchie. :)