DeveloperJoy Logo DeveloperJoy

How to Scale a Laravel App to handle +9M requests per month in a small EC2 instance

April 7, 2024
How to Scale a Laravel App to handle +9M requests per month in a small EC2 instance

Creating a Laravel application that can efficiently manage over 9 million requests monthly requires a robust scaling strategy.

In this article, we will explore key techniques and best practices to scale your Laravel app effectively, ensuring optimal performance and reliability.

1. Utilising Jobs and Queues

To handle the increased load on your Laravel application, leveraging jobs and queues with Laravel Horizon and Redis is crucial.

By efficiently managing tasks asynchronously, you can improve application responsiveness and scalability. Instead of waiting for all the process to be done, you can reply with a 201 HTTP Status and do everything in the background.

In MetricsWave, for example, every time that we receive a new event or visits we are storing it in redis, and, in the background, making all the process to store that visit in a proper way. The user doesn’t need to wait for it.

Additionally, scaling workers based on the workload it’s easier than scaling the whole application. You can have all the workers you need in the background doing all the job.

2. Optimising Code for Performance

This sounds obvious but is not. You have to take care of your code, you can use tools like Sentry or Laravel Debugbar to see what are the slowest points and with the most options for improvement.

One of the most common bottlenecks in Laravel are the N+1 query issue.

Most of the time, solving this problem is just loading your entity with the children’s you need in that particular use case.

Author::with('books')->get()

This will reduce the number of queries needed significantly.

3. Identifying and Resolving Slow Queries

Monitoring and addressing slow queries is essential for maintaining optimal database performance.

Techniques such as adding indexes, partitioning tables, and optimizing query execution can help in improving overall database efficiency.

Try to analyze your most common queries with MySQL EXPLAIN and EXPLAIN ANALYZE. This will give you super useful information about how the query is being executed and in how many steps. With the proper indexes, and sometimes, choosing just the fields you need, you can x10 uno query performance.

4. Cache Implementation Strategies

While caching can enhance application speed, it's crucial to use it judiciously.

Sometimes, using cache is more a problem than a solution. We have to avoid using cache if we can, but there are some use cases where a few seconds of cache, or depending in the use case more, can improve our app performance by a lot.

Implement caching only where necessary to reduce database load and improve response times.

Proper caching strategies can significantly benefit the performance of your Laravel app.

5. Exploring Laravel Octane for Performance Boost

Consider integrating Laravel Octane into your application to handle concurrent tasks efficiently.

By utilizing Swoole under the hood, Octane can improve application performance, especially in scenarios requiring high levels of concurrency.

It requires some extra work, there are something that doesn’t work in the same way, but it is something worth analyzing and thinking about if we need to scale our application in a big way.


Scaling a Laravel application to manage over 9 million requests per month requires a comprehensive approach encompassing efficient job handling, code optimization, query tuning, caching strategies, and innovative solutions like Laravel Octane.

By implementing these strategies diligently, you can ensure your Laravel app scales seamlessly and delivers a smooth user experience even under high traffic volumes.

← Go back to the blog

Work with me

Do you own a company or need help with your Laravel project? I can help you with that. Check the plans and let me know if you have any questions.

Get 1 month free with yearly plan during checkout.

Technical Advisor

$ 3 ,995

/m

What's included:

  • Lead your team to a better code architecture, testing mentality, clean code, and more.
  • Lead knowledge-sharing sessions depending on current company status and requirements.
  • Help with product and technical decisions.
  • Pause or cancel anytime.

Integrated Senior Developer

$ 5 ,995

/m

What's included:

  • Includes all Technical Advisor services.
  • Engages as a team member in daily tasks.
  • Participates actively in day-to-day development.
  • Direct communication:
    Slack, and meetings included.
  • Pause or cancel anytime.

Want to talk first?

Ok, just book a call now.

FAQ