Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the best practices in building multi-tenancy applications?

What are the best practices in building applications that support multiple tenants such as Software as a Service?

Links to white papers that expand on this topic are greatly appreciated.

like image 790
McGovernTheory Avatar asked Apr 04 '09 13:04

McGovernTheory


People also ask

What is an important concern for the customer in multi-tenant environments?

The primary concern is how to ensure that proper security and isolation protects consumers or tenants of these services from the risks they pose to one another.

What is the general setup of multi-tenant architecture?

In a multi-tenant architecture, multiple instances of an application operate in a shared environment. This architecture is able to work because each tenant is integrated physically, but logically separated; meaning that a single instance of the software will run on one server and then serve multiple tenants.


2 Answers

For the database:

A. Put everything on the same database, put a tenant_id column on your tables

Pros: Easy to do

Cons: Very prone to bugs: it's easy to leak data from one tenant to another.

B. Put everything on the same database, but put each tenant in its own namespace (postgresql calls them schemas)

Pros: Provides better data leak protection than option A

Cons: Not supported by all databases. AFAIK PostgreSQL and Oracle supports it.

C. Setup one database per tenant

Pros: Absolutely no chance of data leaking from one tenant to another

Cons: Setting up new tenants is more complicated. Database connections are expensive.

I only learned the above ideas from Guy Naor. Here's a link to his presentation: http://aac2009.confreaks.com/06-feb-2009-14-30-writing-multi-tenant-applications-in-rails-guy-naor.html

like image 61
Radamanthus Avatar answered Nov 07 '22 02:11

Radamanthus


You might find some valuable advise in a series of blog posts by Oren Eini.

This is one of the last posts in the series, with links to previous posts: http://ayende.com/Blog/archive/2008/08/16/Multi-Tenancy--Approaches-and-Applicability.aspx

like image 33
M4N Avatar answered Nov 07 '22 02:11

M4N