← All Articles

Multi-Tenancy: Serving multiple apps from the same stack

Kasia HoffmanKasia Hoffman
Jun 21st 16Updated Jul 26th 17
Features

multi-tenancy-serving-multiple-apps-from-the-same-stack

What is Multi-tenancy?

A multi-tenancy architecture allows for multiple independent instances of one or more applications to share the same environment, which can include the data model, servers and database layers.

Why choose a multi-tenant environment for your application?

There are times when you'll need to run multiple applications on the same stack. This might be because:

  • the applications you're running share common resources, or
  • your applications don't have enough traffic to run on separate stacks

The primary benefit of a multi-tenant environment is the ongoing cost-savings of shared infrastructure. Additionally, it can help you maximize the performance of the different components in the stack. As it's easier to monitor and administer one server (i.e. a single, centralized place), as opposed to applications hosted in different environments, you can save time spent on configuration and managing software updates.

Multi-tenancy for your Docker Stack with Cloud 66

To achieve your multi-tenancy requirements, you'll first need to modify your service.yml file. To start, place each of your applications into its own service in order to host multiple applications on the same stack.

For example:

services:
  first_app:
    git_url: git@github.com:kasia/my_first_app.git
    git_branch: master
    ports: ["3000:80:443"]
  second_app:
    git_url: git@github.com:kasia/my_second_app.git
    git_branch: master
    ports: ["3000:80:443"]
  third_app:
    git_url: git@github.com:kasia/my_third_app.git
    git_branch: master
    ports: ["3000:80:443"]

In the example above, you'll notice that all the specified applications share the same public ports (80 and 443). This means that any inbound traffic to the stack on port 80 or port 443, will be randomly served by any application each time.

This problem can be solved by using the Domain Matching feature in Cloud 66. This feature allows you to still share ports and have the ability to split traffic by the URL domain name that client has requested:

For example:

services:
  first_app:
    git_url: git@github.com:kasia/my_first_app.git
    git_branch: master
    ports: ["3000:80:443"]
    traffic_matches: ["firstpplication.com"]
  second_app:
    git_url: git@github.com:kasia/my_second_app.git
    git_branch: master
    ports: ["3000:80:443"]
    traffic_matches: ["secondapp.com", "www.secondapp.com", "second-app.com", "www.second-app.com"]
  third_app:
    git_url: git@github.com:kasia/my_third_app.git
    git_branch: master
    ports: ["3000:80:443"]
    traffic_matches: ["thirdapplication.com", "*.thirdapplication.com"]

The example above shows how traffic has been split based on the requested domain. However, you can match the traffic based on multiple domains, as well as wildcard (*) subdomains.

Configuring your docker service allows you to provide more explicit control settings to cater for custom setup scenarios (like multi-tenant stacks). To find out more about configuring your service.yml, visit our help page on Docker Service Configuration -->.


Try Cloud 66 for Free, No credit card required