Ask A Question


You’re not receiving notifications from this thread.

Multitenancy with different account types

Robert Farese asked in Rails

I'm just getting started on a multitenant application for the lending / finance space. I've looked into Apartment, Milia, Act_as_tenant, etc. but none seemed to really fit what I'm trying to do.

I'll need different types of accounts. The interface / view templates will be different for a lender, for example, than for a borrower. I'm anticipating needed a lot of different classes, functionality, and different API's across the different types of accounts. This starts to sound like something that would be a good basis to start thinking about a services oriented architecture and a distributed system, however, for efficiency and time, I don't want to jump into that at the outset. I'd prefer to keep it as a monolith to start and break it out should the need arise in the future.

Here is what I was thinking as a general structure:

  • The Account class would be the tenant
  • Account has a subdomain and a category
  • Account#category would be set as an enum with category: [:lender, :borrower, :insurer, :admin]
  • The :admin under Account#category is a master level account for us internally to gain access to any account and to see our own dashboards for viewing customer analytics
  • Account has_many companies
  • Company belongs_to an account
  • Comany has_many users
  • User belongs_to a company
  • Company has_many admins
  • Admin belongs_to a company
  • Account has_many users through company
  • Account has_many admins through company

The issue I ran into with Apartment, for example, is the inability to add models that are unique to a specific type of tenant. For example, Lenders will have the ability to submit a Bid (loan offer with terms) to a borrower (so that the borrower can recieve multiple offerst from multiple lenders). I don't want to have a Bid added for a Borrower account in the DB as well, nor would I like the Bid excluded from the tenant and placed in a global space.

I was thinking that I could have Account type isolated into its own gem / engine so it would be similar to Dan Manges article about building a modular Rails monolity app with gems. The only difference is that in the /app folder I'd have the shared functionality between the tenants.

I have so many questions I'm not sure where to start! General feedback on this structure, how to go about accomplishing this, any potential resources you might know of, etc. is all welcome! So glad to be a part of GoRails! I hesitated too long to join!

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,969+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.