You're starting a new project and you're thinking about using Laravel framework. But... is it scalable enough? What happens if the application grows? Will it support the demand? The answer to these questions has more to do with design, architecture, and infrastructure decisions than with the language/framework of choice. This post aims to discuss two effective scaling techniques and how you can apply them to your Laravel project.

What is Scalability?

Scalability refers to the ability of an application or a system to handle a growing amount of work by adding computational resources with minimum impact.

Why it matters

As an agency focused on developing software for startups, we never know how many users will use the products we build; but what we know is that successful startups achieve hockey stick growth at a certain point, so we need to be prepared.

The goal is not to support an excessive number of users from the beginning; if we do that, we will be spending extra money on servers for something we won't yet use. The goal is to support more and more users gradually as needed with the minimum impact.

Scope of this article

There are many different strategies and techniques you could use to favor the scalability of your application. In this post, we are going to focus on decisions based on the deployment architecture. We will discuss how we can use a serverless or Kubernetes based architecture to make our Laravel application more scalable.

Scaling: Horizontal vs. Vertical

You can scale your system by upgrading the current server configuration (more RAM or better CPU) or adding more servers and distributing the work between them. The first approach is known as Vertical Scaling, and the second one - yes, you've guessed it - Horizontal Scaling.

Both approaches have their pros and cons, but horizontal scaling is typically the way to go. It's more complicated from an architectural perspective, but it's cheaper in terms of server fees, and it offers infinite scaling - there is no limit to the number of nodes you can add. On the other hand, vertical scaling has a limit, the maximum amount of RAM and the best CPU available on the market at the time.

Scaling Approaches: Serverless and Kubernetes

Serverless and Kubernetes are powerful contemporary platforms that help improve system scalability and performance in many ways. Although they will both help you bring scalability to your application, you should choose the one that better suits your project needs. Serverless is easier to implement and needs less maintenance, and Kubernetes gives you more control and makes it easier to estimate server costs. I will explain each one in more detail below.

Serverless - with Laravel Vapor

Laravel Vapor is an official Laravel service built by Taylor Otwell - Laravel's founder - to facilitate Laravel applications' deployment in a Serverless AWS infrastructure. It minimizes the amount of configuration you need, and since it's a Serverless platform, it scales automatically. Automatic scaling means that the platform will automatically allocate more resources to your app when required to meet the demand and deallocate resources when necessary.

Kubernetes

Different from Laravel Vapor, Kubernetes is not specific to the Laravel Framework. It's harder to configure than Vapor, but it provides full control of your containers' administration. Having your application containerized in Docker is a requirement to be able to use this approach.

Conclusion

Both of these approaches will help your application scale better, saving you server costs and hours of maintenance.

Which approach to use depends on your project's nature and requirements; in our case, we typically choose Laravel Vapor since it saves our clients expensive DevOps hours. At the same time, paying Vapor's subscription lets us contribute to the Laravel Ecosystem and help it grow.


We're Laravel Experts!

Do you have a Laravel project and need development services or an extra hand? Let's partner up! At Light-it, we offer Laravel Development & Staff Augmentation Services. Psst...We're the best at what we do... we've been recognized by Clutch as part of the TOP 30 Laravel Developers Worldwide.

Contact us