Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use subdomains to designate tenants in a multi-tenant web application?

Questions

  1. Why do some multi-tenant web applications use subdomains to designate the tenant while others do not?
  2. Are there technical, privacy, or security reasons?
  3. Is it dependent on the language or framework used to develop the web application?
  4. Is it simply a matter of style or developer's choice?

Example Web Applications Using Subdomains to Designate Tenants

  • Basecamp
  • RepositoryHosting
  • Smugmug
  • Unfuddle

Example Web Applications Not Using Subdomains to Designate Tenants

  • Github
  • ThinMind
  • Bitbucket
like image 448
Matthew Rankin Avatar asked Feb 13 '11 22:02

Matthew Rankin


People also ask

What is the purpose of subdomains?

A subdomain name is a piece of additional information added to the beginning of a website's domain name. It allows websites to separate and organize content for a specific function — such as a blog or an online store — from the rest of your website.

Are subdomains necessary?

A subdomain is, as the name would suggest, an additional section of your main domain name. You create subdomains to help organize and navigate to different sections of your main website. Within your main domain, you can have as many subdomains as necessary to get to all of the different pages of your website.

Which should you choose single tenant vs multi-tenant?

Greater security risk - In a multi-tenant system, the risks are higher because resources are shared by multiple customers. If one customer's data is compromised, it is more likely that it will affect other customers, unlike in a single-tenant cloud where security incidents are isolated to a single client.

What is multi-tenant domain?

(Sub-)domain multi-tenancy is good if you want to give an user a perception of fully isolated tenancy. The customer may want custom welcome and login page, separate user-base etc. On the other hand the path based multi-tenancy is good for the users who are not fixed to single tenant namespace.


1 Answers

There are several ways to determine tenant on HTTP level:

  • domain - tenant is determined by whole Host header
  • sub-domain - sub-domain part of Host header,
  • path based - path segment, usually by prefix host.com/tenantId/...
  • cookie based - cookie value contains tenant id (good framework encrypts this!)
  • user based - user session or some data records on server

Here are an answers to your questions:

  1. (Sub-)domain multi-tenancy is good if you want to give an user a perception of fully isolated tenancy. The customer may want custom welcome and login page, separate user-base etc. On the other hand the path based multi-tenancy is good for the users who are not fixed to single tenant namespace. It is mostly used by social networks like Facebook, GitHub etc.

  2. (Sub-)domains can give you better isolation and security control for cookies, cross-origin resources sharing (CORS). It makes cross-tenant CSRF or XSS a bit harder. Moreover if you have control over DNS or Load-balancer you can assign tenants to different IPs (think geo-routing) or to various versions of application (e.g. beta tenants). You can assign a separate app instance or server for your most important tenants. This way you get a cheap tool to control risk of single point of failure and all eggs in one basket.

  3. Any web-framework which gives you an access to HTTP headers (Host) is sub-domains capable. Any serious MVC web-framework should give you sub-domain as action parameter directly or by plugin.

  4. It is definitely a design choice. If you want to know the best way think what level of isolation you want for your tenants. If you decide but you will find that the way is not right then you can migrate to another level with help of HTTP 301 redirection.

like image 166
gertas Avatar answered Oct 16 '22 04:10

gertas