Infrastructure
Scaling Magento: Infrastructure for High-Traffic Stores
When to Think About Scaling
A single well-tuned Magento server can comfortably handle 200–500 concurrent users. Beyond that, you need horizontal scaling — multiple web nodes behind a load balancer.
The Magento Multi-Node Architecture
Internet → CDN (Cloudflare / Fastly)
↓
Load Balancer (HAProxy / AWS ALB)
/ \
Web Node 1 Web Node 2
\ /
Shared Storage (NFS / EFS)
↓
MySQL Primary ──→ MySQL Replica (reads)
↓
Elasticsearch Cluster (3 nodes)
↓
Redis Cluster (session + cache)
Shared Media and Static Files
All web nodes must access the same pub/media and pub/static directories. Use NFS or a cloud file system:
# Mount shared NFS on each web node
mount -t nfs nfs-server:/magento/media /var/www/html/pub/media
mount -t nfs nfs-server:/magento/static /var/www/html/pub/staticOr use AWS EFS and mount it automatically via /etc/fstab.
Database: Read/Write Splitting
Magento 2 has built-in support for a separate read replica:
// app/etc/env.php
'db' => [
'connection' => [
'default' => [
'host' => 'mysql-primary',
// write connection
],
'indexer' => [
'host' => 'mysql-replica',
// read-heavy indexer operations
],
],
],Session Consistency Across Nodes
With multiple web nodes, sessions must be stored centrally in Redis — not on the local filesystem. All nodes point to the same Redis instance (or Redis Sentinel for HA).
CDN Configuration for Static Assets
Offload static and media assets to a CDN to reduce load on web nodes:
bin/magento config:set web/unsecure/base_static_url https://cdn.yourdomain.com/static/
bin/magento config:set web/unsecure/base_media_url https://cdn.yourdomain.com/media/
bin/magento cache:flushDeploy Code Changes Across Nodes
Use a deployment tool like Deployer or Capistrano to push code changes atomically:
// deploy.php (Deployer)
task('magento:upgrade', function () {
run('cd {{release_path}} && bin/magento setup:upgrade --keep-generated');
run('cd {{release_path}} && bin/magento setup:di:compile');
run('cd {{release_path}} && bin/magento setup:static-content:deploy -f');
});Use MagentoEnv for Pre-Production Testing
Before rolling out infrastructure changes to production, test them in a MagentoEnv environment that mirrors your production topology — same Magento version, same PHP version, same extension set. Spin it up for a few hours, validate, then tear it down. You only pay for the hours used.