Can Laravel 5 handle 1000 concurrent users without lagging badly? Can Laravel 5 handle 1000 concurrent users without lagging badly? laravel laravel

Can Laravel 5 handle 1000 concurrent users without lagging badly?


In short, yes. At least newer versions of Laravel are capable (Laravel 7.*).
That being said, this is really a three part conundrum.


1. Laravel (Php)


Honestly, I wouldn't be able to provide half the details as this amazing article provides. He's got everything in there from the definition of concurrency all the way to pre-optimization times vs. after-optimization times.



2. Reading, Writing, & Partitioning Persisted Data (Databases)


I'd be curious if the real concern is Php's Laravel, or more of a database read/write speed timing bottleneck. Non relational databases are an incredible technology, that benefit big data much more than traditional relational databases.

  • Non-relational Databases (Mongo) have a much faster read speed than MySql (Something like 60% faster if I'm remembering correctly)
  • Non-relational Databases (Mongo) do have a slower write speed, but this usually is not an inhibitor to the user experience
  • Unlike Relational Databases (MySQL), Mongo DB can truly be partitioned, spread out across multiple servers.
  • Mongo DB has collections of documents, collections are pretty synonymous to tables and documents are pretty synonymous to rows.
  • The difference being, MongoDB has a very JSON like feel to it. (Collections of documents, where each document looks like a JSON object).
  • The huge difference, and benefit, is that each document - AKA row - does not have have the same keys. When using mongo DB on a fortune 500 project, my mentor and lead at the time, Logan, had a phenomenal quote.

"Mongo Don't Care"

This means that you can shape the data how you're wanting to retrieve it, so not only is your read speed faster, you're usually not being slowed by having to retrieve data from multiple tables.

Here's a package, personally tested and loved, to set up MongoDB within Laravel

If you are concerned about immense amounts of users and transferring data, MongoDB may be what you're looking for. With that, let's move on to the 3rd, and most important point.


3. Serverless Architecture (Aka Horizontal scaling)


Aws, Google Cloud, Microsoft Azure, etc... I'm sure you've hear of The Cloud.

This, ultimately, is what you're looking for if you're having concurrency issues and want to stay within the realm of Laravel.

It's a whole new world of incredible tools one can hammer away at -- they'er awesome. It's also a whole new, quite large, world of tools and thought to learn.

First, let's dive into a few serverless concepts.

  • Infrastructure as Code Terraform

    "Use Infrastructure as Code to provision and manage any cloud, infrastructure, or service"

  • Horizontal Scaling Example via The Cloud

    "Create a Laravel application. It's a single application, monolithic. Then you dive Cloud. You discover Terraform. Ahaha, first you use terraform to define how many instances of your app will run at once. You decide you want 8 instances of your application. Next, you of course define a Load Balancer. The Load Balancer simply balances the traffic load between your 8 application instances. Each application is connected to the same database, ultimately sharing the same data source. You're simply spreading out the traffic across multiples instances of the same application."

  • We can of course top that, very simplified answer of cloud, and dive into lambdas, the what Not to do's of serverless, setting up your internal virtual cloud network...

Or...we can thank the Laravel team in advance for simplifying Serverless Architecture

Laravel Vapor Opening Paragraph

"Laravel Vapor is an auto-scaling, serverless deployment platform for Laravel, powered by AWS Lambda. Manage your Laravel infrastructure on Vapor and fall in love with the scalability and simplicity of serverless."


Coming to a close, let's summarize.

Oringal Concern

Ability to handle a certain amount of traffic in a set amount of time

Potential Bottlenecks with potential solutions

Laravel & Php

Database & Persisting/Retrieving Data Efficiently

Serverless Architecture For Horizontal Scaling


I'll try to answer this based on my experience as a software developer. To be honest I definitely will ask for an upgrade whenever it hits 1000 concurrent users at the same time because I won't take a risk with server failure nor data failure.

But let's break it how to engineer this.

  1. It could handle those users if the data fetched is not complex and there are not many operations from Laravel code. If it's just passing through from the database and almost no modification from the data, it'll be fast.
  2. The data fetched by the users are not unique. Let's say you have a news site without user personalization. the news that the users fetched mostly will be the same. You cached the data from memory (Redis, which I recommend) or from the web server(Nginx, should be avoided), your Laravel program will run fast enough.
  3. Querying directly from the database is faster than using Laravel ORM. you might consider it if needed, but I myself will always try to use ORM because it will help code to be more readable and secure.
  4. Splitting database, web server, CDN, and cache server is obviously making it easier to monitor server usage.
  5. Try to upgrade it to the latest version. I used to work with a company that using version 5, and it's not really good at performance.
  6. opcode caching. cache the PHP file code. I myself never use this.
  7. split app to backend and frontend. use state management for front end app to reduce requests data to the server.

Now let's answer your question

Are there any tools for checking performance? You can check Laravel debug bar, these tools provide for simple performance reports. I myself encourage you to make a test for each of the features you create. You can create a report from that unit test to find which feature taking time to finish.

Are lume faster than laravel? Yeah, Lumen is faster because they disabled some features from Laravel. But please be aware that Taylor seems gonna stop Lumen for development. You should consider this for the future.

If you're aware of performance, you might not choose Laravel for development.

  1. Because there is a delay between each server while opening a connection. Whenever a user creating a request, they open a connection to the server. server open connections to the cache server, database server, SMTP server, or probably other 3rd parties as well. It's the real bottleneck that happened on Laravel. You can make keep-alive connections with the database and cache server to reduce connection delay, but you wouldn't find it in Laravel because it will dispose the connection whenever the request finish.
  2. It's a typed language, mostly compiled language are faster

In the end, you might not be able to use Laravel with that server resources unless you're creating a really simple application.


A question like this need an answer with real numbers:

luckily this guy already have done it in similar conditions as you want to try and with laravel forge.

with this php config:

opcache.enable=1opcache.memory_consumption=512opcache.interned_strings_buffer=64opcache.max_accelerated_files=20000opcache.validate_timestamps=0opcache.save_comments=1opcache.fast_shutdown=1

the results:

Without Sessions:Laravel: 609.03 requests per secondWith Sessions:Laravel: 521.64 requests per second

so answering your question:

With that memory you would be in trouble to get 1000 users making requests, use 4gb memory and you will be in better shape.