Report this

What is the reason for this report?

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

Posted on October 26, 2023

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.



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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.