DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
VGSources
Blog

How to Horizontally Scale a Laravel App with PostgreSQL on VPS Servers

Scale Laravel across VPS servers by making app nodes stateless, centralizing Redis and uploads, pooling PostgreSQL connections, separating Horizon workers, and adding read replicas only when measured read traffic demands them.
Length11 min Posted Quest giverVGSources Team

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To scale a Laravel application across VPS servers, make every application node disposable: store sessions, cache, and queues in shared Redis; store uploads in shared object storage; place multiple app nodes behind a load balancer; run queue workers separately; and put PgBouncer in front of PostgreSQL before adding replicas. Add a streaming read replica only when read traffic requires it, then route reads deliberately and keep consistency-sensitive reads on the primary.

This order avoids the most common failure in a multi-server Laravel deployment: a request reaches a different VPS and cannot find state that was left on the previous node. It also prevents a database replica from being treated as a general performance cure. Replicas distribute read load, but they do not make one poorly performing query faster.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What horizontal scaling changes in a Laravel deployment

Vertical scaling gives one VPS more CPU, memory, storage, or network capacity. Horizontal scaling adds more VPS instances and distributes work among them. Laravel can scale horizontally only when an individual application node does not own information that another node must read.

A user may submit a form on one node and load the next page from another. A queue job may be claimed by a worker on a different server. A deployment may remove one node while traffic continues through the others. These events are routine in a load-balanced system, so the application tier must be stateless.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Stateless does not mean the whole system has no state. It means durable or shared state is kept in services designed for shared access rather than in a node’s local filesystem or process memory.

The target request and job flow

Client
  |
Load balancer
  |-- App node 1 (Laravel PHP workers)
  |-- App node 2 (Laravel PHP workers)
  |-- App node 3 (Laravel PHP workers)
  |
  |-- Shared Redis: sessions, cache, queue backend
  |-- Shared object storage: uploaded files
  |-- PgBouncer
        |-- PostgreSQL primary (writes and consistency-sensitive reads)
        |-- PostgreSQL streaming replica (eligible reads)

Separate queue-worker VPS nodes run Horizon against the same Redis backend.

The load balancer distributes HTTP requests. Redis gives every app node the same session, cache, and queue view. Object storage makes uploaded files available regardless of which node handled the upload. PgBouncer limits and reuses database connections. PostgreSQL replication can then distribute suitable read traffic without moving writes away from the primary.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make Laravel nodes stateless first

Put sessions, cache, and queues in shared Redis

Configure all app nodes to use one shared Redis service for Laravel sessions, cache, and queues. Every node must use the same Redis endpoint and compatible application configuration. A local Redis instance on each VPS creates separate islands: a session written on node 1 may be absent on node 2, and a queued job may be invisible to workers connected elsewhere.

Shared Redis also gives Horizon a single queue backend. Each server can run Horizon against that backend, while Redis coordinates job claims so that two workers do not process the same queued job simultaneously under normal operation.

  • Sessions: A request can move between app nodes without forcing a login again.
  • Cache: Cached values are visible to every node and are not lost merely because the load balancer selects a different VPS.
  • Queues: Web requests can enqueue work once, and dedicated workers on several servers can consume it from the same backend.

Plan Redis as a shared dependency rather than an incidental service on one app VPS. If it becomes unavailable, session access, cache operations, and queue dispatch or processing can all be affected, so monitor it separately and define a recovery plan before adding more app nodes.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Move uploads to shared object storage

Do not treat an app node’s local disk as the authoritative home for user uploads. A file uploaded through node 1 may be requested later through node 2, which has no copy. Node replacement, autoscaling, or a deployment can also delete files that were stored only on an instance disk.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use shared object storage for uploads and configure every Laravel node to use the same storage location. Keep only temporary processing files on local disk, and make the application persist the resulting object before returning success. This separates durable media from the lifecycle of disposable web servers.

Control PostgreSQL connections with PgBouncer

Add a connection pooler such as PgBouncer in front of PostgreSQL before introducing read replicas. A horizontally scaled Laravel fleet can create a large number of database connections because every app node has its own PHP workers and deployment processes. PostgreSQL must still manage those connections even when the application is not actively running queries.

PgBouncer accepts connections from the Laravel nodes and reuses a controlled pool of PostgreSQL connections. This reduces connection overhead and helps prevent a burst of app nodes or workers from exhausting PostgreSQL’s connection capacity.

Where the pooler belongs

Laravel should connect to the pooler’s endpoint, while the pooler connects to the PostgreSQL primary and, where configured, replica endpoints. Keep write traffic on the primary. If a separate endpoint is used for replicas, route only reads that can tolerate replication delay.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Pooling is not a substitute for query tuning, indexes, or adequate PostgreSQL resources. It addresses connection management; it does not accelerate a single slow SQL statement. Test transaction behavior and session-level database features with the selected PgBouncer mode before production rollout.

Add app nodes behind a load balancer

Once shared state and database access are ready, run two or more identical Laravel app nodes behind a load balancer. Each node should contain the same application release, environment configuration, PHP runtime, web server configuration, and scheduled deployment state.

What the load balancer should do

  • Send HTTP requests only to healthy app nodes.
  • Stop sending traffic to a node during deployment or when its health check fails.
  • Distribute requests without relying on a particular node’s local session or upload directory.
  • Preserve the client information your application and logs require, using the proxy settings appropriate to your chosen load balancer.

HAProxy and Nginx are common choices for this role. The exact VPS configuration depends on the network layout, TLS termination point, health-check endpoint, and operating system, so treat those as deployment-specific decisions rather than copying a generic configuration unchanged.

Health checks should test useful dependencies

A process-level check proves only that the web server is listening. A useful readiness check should reflect whether the node can serve traffic with its required configuration. Decide explicitly how Redis and database failures should affect readiness: taking every node out of rotation during a shared dependency outage can make recovery harder, while keeping unhealthy nodes in rotation increases user-facing errors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run queues separately with Laravel Horizon

Web requests and background jobs compete for CPU, memory, and database connections if they run on the same VPS. Create separate queue-worker nodes and run Horizon against the shared Redis backend. The app nodes dispatch jobs; the worker nodes execute them.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Why Horizon fits a multi-server queue

Horizon can run on each worker server while all instances use the same Redis connection. Redis coordinates queue access, preventing ordinary double processing when multiple workers claim jobs. You can therefore add worker VPS nodes without creating a separate queue for each machine.

Horizon also adjusts worker counts per queue between configured minimum and maximum values according to queue wait times, instead of relying only on fixed queue:work processes. Configure those limits per workload: a CPU-heavy video job, a short notification job, and a database-intensive import should not necessarily share identical concurrency.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Separate queues by workload

  • Place latency-sensitive jobs on a queue that has reserved worker capacity.
  • Put long-running or memory-heavy jobs on a separate queue so they cannot block short jobs.
  • Set maximum worker counts with PostgreSQL and Redis capacity in mind; adding workers can increase database contention rather than throughput.
  • Watch queue wait time, job runtime, failure count, and worker memory usage after every concurrency change.

Deploy worker code and app code as a compatible release. A worker that continues running old code while new requests enqueue a changed payload can fail even though both servers are individually healthy.

Use PostgreSQL replicas for reads, not as a second primary

PostgreSQL uses streaming replication to copy changes from a primary to one or more replicas. The primary remains the write authority. Replicas can serve eligible read traffic, spreading read load across servers, but they do not speed up one slow query and they cannot safely receive writes.

Choose the read path deliberately

A proxy such as HAProxy or Pgpool-II can route writes to the primary and reads to replicas. The proxy needs a clear policy for what happens when a replica is lagging or unavailable. Reads that must reflect the latest committed write should go to the primary.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Replication lag is normal enough that application code must account for it. A user who creates an order and immediately loads its detail page can be sent to a replica that has not replayed the insert yet. For those read-after-write paths, use the primary or Laravel’s sticky read/write behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Laravel read and write configuration

Laravel supports separate read and write host arrays in config/database.php, plus an optional sticky flag. A minimal structure is:

'pgsql' => [
    'driver' => 'pgsql',
    'read' => [
        'host' => [env('DB_READ_HOST')],
    ],
    'write' => [
        'host' => [env('DB_WRITE_HOST')],
    ],
    'sticky' => true,
    // keep the remaining PostgreSQL settings shared by your deployment
],

With sticky enabled, a request that performs a write uses the write connection for subsequent reads in that same request. This protects common read-after-write flows, but it does not make a later request automatically current. If the next request can land on a replica, route that particular operation to the primary when freshness matters.

Keep the read and write host definitions consistent across all app nodes. A node with a different environment variable or stale cached configuration can silently send traffic to the wrong database.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A deployment sequence that limits risk

  1. Inventory node-local state. Find session files, cache files, queue backends, uploaded media, generated exports, and any other data written outside PostgreSQL.
  2. Move sessions, cache, and queues to one shared Redis backend. Confirm that a value written through one app node can be read through another.
  3. Move uploads to shared object storage. Upload through one node and retrieve the object through another before exposing the load-balanced service.
  4. Introduce PgBouncer. Point Laravel at the pooler, verify connection limits and transaction behavior, and observe PostgreSQL connection counts under a representative worker load.
  5. Clone the app node. Build a second node from the same release and environment configuration. Check that both nodes use identical Redis, storage, and database endpoints.
  6. Put the nodes behind the load balancer. Test health checks, node removal, deployment draining, and a request sequence that crosses nodes.
  7. Move Horizon to worker VPS nodes. Connect every worker to the same Redis backend, then test dispatch, completion, retries, and failure handling.
  8. Measure before adding a replica. Establish whether the bottleneck is database reads, writes, connections, CPU, memory, storage latency, or a slow query. A replica is useful only when read demand is the limiting factor.
  9. Add a PostgreSQL streaming replica. Keep writes on the primary, expose the replica through a deliberate routing layer, and monitor replay delay.
  10. Route selected reads. Send only replica-safe reads to the read path. Keep read-after-write and freshness-critical queries on the primary, using Laravel’s sticky behavior where it fits the request lifecycle.

Failure modes to plan for

Symptom Likely design problem Corrective action
Users lose sessions when requests switch VPS nodes Sessions remain on node-local storage Use one shared Redis session backend on every app node
Uploaded files appear on one node but return 404 on another Files are stored on local disk Persist uploads in shared object storage
PostgreSQL rejects connections during traffic or worker bursts Every process opens an unmanaged database connection Place PgBouncer before PostgreSQL and size the pool deliberately
Jobs are invisible to some workers Workers use different Redis backends or queue settings Point all Horizon instances at the same Redis queue backend
A newly created record is missing immediately afterward The read went to a lagging replica Use the primary for freshness-sensitive reads and enable Laravel sticky routing where appropriate
Adding workers increases database latency Concurrency exceeded database capacity Reduce worker limits, separate queues, and measure query and connection pressure
Reads remain slow after adding replicas The workload is dominated by one slow query Investigate the query and database plan; replicas distribute load but do not accelerate one query

Operational checks after each scaling change

Application checks

  • Log the app node identifier so a request can be traced across load-balancer hops.
  • Verify session continuity by authenticating through one node and making subsequent requests through another.
  • Upload and retrieve a file through different nodes.
  • Confirm that cache invalidation is visible from every node.

Queue checks

  • Dispatch a known test job and confirm that any worker can claim it.
  • Measure queue wait time separately from job runtime.
  • Check retries and failed-job handling after stopping one worker node.
  • Watch Redis memory and worker memory as Horizon changes process counts.

Database checks

  • Track active PostgreSQL connections before and after PgBouncer.
  • Measure replica replay delay and define the maximum lag acceptable for each read class.
  • Verify that writes never reach a read replica.
  • Test a read-after-write request and confirm that it remains consistent.

When horizontal scaling is the wrong next step

Adding VPS nodes increases operational overhead. The team must maintain shared Redis, object storage credentials, a load balancer, worker processes, database pooling, deployment coordination, monitoring, and failure procedures. For a small or lightly loaded application, that complexity can cost more in maintenance than it returns in capacity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

First identify the limiting resource. If one slow query, an undersized primary, inefficient application code, or an unbounded queue is responsible, adding app nodes may simply multiply the pressure. PgBouncer is the earlier database scaling step because connection exhaustion can occur before PostgreSQL needs replicas. Add replicas when measured read demand justifies them, not because a multi-server diagram looks complete.

Designing for failover

A read replica is not automatically a failover system. Decide how the application behaves when the primary, pooler, Redis service, or load balancer fails. Database promotion, DNS or proxy changes, Laravel configuration, and queue recovery all need an explicit runbook.

Patroni is sometimes proposed for PostgreSQL failover, but its suitability depends on the surrounding topology and operational expertise; validate its behavior in a staging failure test rather than assuming it provides a complete solution by itself. Likewise, a proxy can route traffic, but it does not replace backup, restore, replication monitoring, or a tested promotion procedure.

Final implementation checklist

  • All app nodes use shared Redis for sessions, cache, and queues.
  • Uploads live in shared object storage, not node-local disk.
  • App nodes are identical and sit behind health-checked load balancing.
  • Horizon runs on separate worker nodes against the same Redis backend.
  • Laravel connects through PgBouncer with a tested connection policy.
  • PostgreSQL writes stay on the primary.
  • Read replicas are added only for measured read-load needs.
  • Replica lag is monitored, and freshness-critical reads use the primary.
  • Laravel’s sticky read/write setting is enabled where same-request read-after-write consistency is required.
  • Failure, node removal, deployment draining, and recovery have been tested rather than assumed.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.