Question

Best way to handle a Laravel multitenant application for best and affordable scaling

Hi there, I am working on a multi-tenant Laravel application and we create a new tenant for each user on the platform.

I’m finding it difficult to get the best approach that will not incur too much cost and is also flexible for scaling.

I have a few questions to ask that can shed more light on my problem and could also assist with providing a solution

  1. Do I create one droplet and create a new database for each user in that droplet
  2. Do I create a new droplet for a new user that has its own db and resources ?

PS: I’m building a multi db multitenant application, looking to start small and scale with time.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
October 26, 2023

Hey Louis,

Scaling a multi-tenant application, especially with Laravel, can be both fun and a bit tricky. It would essentially be up to some personal preferences and use-cases.

Here are some of my thoughts on this:

On the topic of single Droplet vs multiple Droplets:

  • Single Droplet:

    • Advantages:
      • Save costs.
      • Easy management.
    • Drawbacks:
      • Potential performance issues.
      • Single point of failure for all customers.
  • Multiple Droplets:

    • Advantages:
      • Better isolation and potential performance.
      • Scale per tenant. This is probably the most important one!
    • Drawbacks:
      • Costs add up.

You can always start with one Droplet. When things get tight, consider scaling later on.

On the database side:

Option: Single Droplet, Multiple Databases.

  • Advantages:
    • Unified database management.
    • Saves money.
  • Drawbacks:
    • Shared resources.
    • Trickier backup procedures.

Option: Managed DigitalOcean Databases (e.g., MySQL, PostgreSQL, Redis).

  • Advantages:
    • Seamless scaling.
    • High reliability.
  • Drawbacks:
    • A bit more pricey but compensated by the operational ease.
    • Some customizability might be lost.

I would personally do the following:

  1. Start with one Droplet, multiple databases. Perfect for when you’re bootstrapping.
  2. Use caching. Redis with Laravel is a solid combo.
  3. Make sure to use the DigitalOcean’s monitoring.
  4. Docker might be up your alley. Then scaling after that you can dive into managed databases.
  5. Always enable Backups

Here is an article that we wrote a while back on how to scale your Laravel app using a Managed database and DigitalOcean Spaces:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-scalable-laravel-6-application-using-managed-databases-and-object-storage

Let me know if you have any questions!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel