Scalable Order API
This project uses Laravel controllers, request validation, policies, an order action, events/listeners and CI. Use the four buttons below to see exactly how the same Laravel application can grow from one user to a very large system.
1 user — one Laravel server is enough
1 APP SERVERLaravel server job
Receives the HTTP request, authenticates the user, validates input, checks policies, runs CreateOrderAction and returns the response.
Why only one?
There is no traffic pressure. Adding three Laravel servers here creates operational complexity without solving a real problem.
Request flow
Client → Nginx/PHP-FPM → Laravel controller → validation/policy → order transaction → MySQL → response.
~100 users — optimize before multiplying servers
1–2 APP SERVERSWhy 1–2 Laravel servers?
One good server may still be enough. A second instance is useful for redundancy or when CPU/PHP-FPM workers become busy.
Redis job
Shares cache, sessions, rate limits and queue data so two Laravel instances do not depend on local memory.
Worker job
Email, invoices and webhooks move to Laravel queue workers so checkout remains fast.
~1 million users — horizontal application pool
4–12 APP SERVERS*Why many Laravel servers?
The load balancer can send each request to any healthy instance. Because app servers are stateless, more can be added horizontally during peak traffic.
Primary vs replica
Order placement and stock mutation stay on the primary database. Read-heavy history/catalog endpoints can use replicas where consistency rules allow.
Order safety
Idempotency keys, transactions, row locking and retry-safe jobs protect against duplicate requests and concurrent stock updates.
~10 million users — isolate workloads and failure domains
20–60+ APP SERVERS*What changed?
There are now multiple Laravel app groups across zones, a larger worker fleet, replicated caches and stronger data isolation. One server failure should not stop ordering.
Do we need microservices?
Not automatically. Split inventory, payment or notification only when traffic, ownership, deployment or failure isolation justifies independent services.
Observability
Track request rate, p95/p99 latency, error rate, PHP-FPM saturation, DB locks, replication lag, queue depth and cache hit ratio before changing capacity.
| Scale | Laravel app servers | Data | Async work |
|---|---|---|---|
| 1 user | 1 | 1 MySQL | Optional |
| ~100 users | 1–2 | Indexed primary + Redis if useful | 1+ workers |
| ~1M users | Example 4–12* | Primary + replicas + Redis cluster | Worker pool |
| ~10M users | Example 20–60+* | Replicas / partitioning where measured | Queue/event fleet |
*Why these server numbers are examples
A “million users” does not tell us requests per second. One million registered users with 2,000 concurrent users is very different from one million concurrent users. Actual Laravel instance count must be load-tested using the endpoint mix, PHP-FPM worker capacity, database latency and target response time.
Laravel deployment chain explained
Nginx receives HTTP traffic and forwards PHP requests to PHP-FPM. PHP-FPM workers execute the Laravel application. Laravel reads/writes MySQL, uses Redis for fast shared state, and publishes slow work to queue workers. A load balancer is added when more than one app server needs to share traffic. Docker can package each role, and GitHub Actions can test code before deployment.