Scaling Shopify on DigitalOcean to Handle 50,000+ Concurrent Requests
Architectural Overview: Decoupling Shopify’s Core Components
Scaling a Shopify instance to handle 50,000+ concurrent requests necessitates a fundamental shift from a monolithic architecture to a highly distributed, microservices-oriented approach. This isn’t about simply adding more Droplets; it’s about intelligently segmenting and scaling individual components that form the backbone of an e-commerce platform. For a self-hosted or hybrid Shopify setup on DigitalOcean, this typically involves isolating the web front-end, API gateway, background job processing, and database layers.
Frontend Scaling with Nginx and PHP-FPM
The primary entry point for customer traffic is the web frontend. We’ll leverage Nginx as a high-performance reverse proxy and load balancer, serving static assets directly and forwarding dynamic requests to a pool of PHP-FPM workers. This separation ensures that Nginx handles TLS termination, request routing, and caching efficiently, offloading CPU-intensive PHP processing.
Consider a fleet of DigitalOcean Droplets dedicated to the frontend. Each Droplet would run Nginx and PHP-FPM. The key is to configure Nginx to manage the worker processes and distribute load effectively.
Nginx Configuration for Frontend Load Balancing
The Nginx configuration will define upstream server groups for PHP-FPM and potentially other backend services. For high concurrency, tuning `worker_processes` and `worker_connections` is crucial. We’ll also implement aggressive caching for static assets and leverage HTTP/2 for improved client-side performance.
# /etc/nginx/nginx.conf
user www-data;
worker_processes auto; # Let Nginx determine based on CPU cores
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 10240; # Significantly increase connections per worker
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# SSL configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m; # Adjust size as needed
ssl_session_timeout 10m;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
# Gzip compression
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
# Define upstream PHP-FPM pools
upstream php_fpm_pool {
# Use least_conn for better distribution if some requests are longer
least_conn;
server 10.10.0.1:9000 weight=10 max_fails=3 fail_timeout=30s; # Internal IP for PHP-FPM server 1
server 10.10.0.2:9000 weight=10 max_fails=3 fail_timeout=30s; # Internal IP for PHP-FPM server 2
# ... add more PHP-FPM servers as needed
}
# Serve static assets directly
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
access_log off;
try_files $uri $uri/ =404;
}
# Proxy dynamic requests to PHP-FPM
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# Use the upstream pool defined above
fastcgi_pass php_fpm_pool;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Include virtual host configurations
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
PHP-FPM Tuning for High Concurrency
Each PHP-FPM server needs to be tuned to handle a high volume of requests. The `pm` (process manager) setting is critical. For high concurrency, `pm = dynamic` with carefully chosen `pm.max_children`, `pm.start_servers`, `pm.min_spare_servers`, and `pm.max_spare_servers` is generally recommended. `pm.process_idle_timeout` can also help reclaim resources from idle workers.
; /etc/php/8.1/fpm/pool.d/www.conf (example path) [www] user = www-data group = www-data listen = 10.10.0.1:9000 ; Listen on a specific internal IP and port ; Process manager settings pm = dynamic pm.max_children = 250 ; Adjust based on server RAM and typical request processing time pm.start_servers = 50 pm.min_spare_servers = 20 pm.max_spare_servers = 100 pm.process_idle_timeout = 10s ; Release idle processes after 10 seconds ; Request handling request_terminate_timeout = 60 ; Max execution time for a script (seconds) ; request_slowlog_timeout = 10 ; Enable slow log for debugging (optional) ; slowlog = /var/log/php-fpm/slow.log ; Other settings catch_workers_output = yes ; env[PATH_INFO] = / ; env[PATH_TRANSLATED] = / ; env[SCRIPT_NAME] = / ; env[SCRIPT_FILENAME] = / ; env[REMOTE_ADDR] = 127.0.0.1 ; env[REMOTE_PORT] = 12345 ; env[SERVER_ADDR] = 127.0.0.1 ; env[SERVER_PORT] = 80 ; env[SERVER_SOFTWARE] = nginx ; env[REMOTE_USER] = www-data ; env[REDIRECT_STATUS] = 200 ; env[APP_ENV] = production ; env[APP_DEBUG] = 0 ; env[APP_KEY] = base64:................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*
Database Layer: PostgreSQL and Redis Optimization
The database is often the ultimate bottleneck. For a high-traffic e-commerce site, a robust, scalable relational database like PostgreSQL is essential. Beyond basic tuning, we need to focus on query optimization, indexing, and potentially read replicas. Redis will be crucial for caching frequently accessed data, session management, and potentially as a message broker for background jobs.
PostgreSQL Performance Tuning
The `postgresql.conf` file is the primary configuration point. Key parameters to adjust include `shared_buffers`, `work_mem`, `maintenance_work_mem`, and `effective_cache_size`. For high concurrency, `max_connections` must be set appropriately, and connection pooling (e.g., PgBouncer) is highly recommended to avoid the overhead of establishing new connections for every request.
# /etc/postgresql/14/main/postgresql.conf (example path) # Memory settings (adjust based on server RAM, e.g., 25% of RAM for shared_buffers) shared_buffers = 8GB work_mem = 64MB ; For complex queries, sorting, hashing maintenance_work_mem = 2GB ; For VACUUM, CREATE INDEX, etc. effective_cache_size = 24GB ; Estimate of total available cache (OS + shared_buffers) # Connections max_connections = 500 ; Adjust based on expected concurrent connections and available RAM ; listen_addresses = '*' ; Or specific IPs for security # WAL settings (for durability and replication) wal_level = replica wal_buffers = 16MB min_wal_size = 4GB max_wal_size = 16GB checkpoint_completion_target = 0.9 random_page_cost = 1.1 ; For SSDs, lower this value # Autovacuum tuning autovacuum = on autovacuum_max_workers = 4 autovacuum_naptime = 10s autovacuum_vacuum_threshold = 50 autovacuum_analyze_threshold = 50 autovacuum_vacuum_scale_factor = 0.1 autovacuum_analyze_scale_factor = 0.05 # Query planner enable_seqscan = on enable_indexscan = on enable_bitmapscan = on random_page_cost = 1.1 ; For SSDs seq_page_cost = 1.0 # Logging (adjust for performance vs. debuggability) log_min_duration_statement = 250ms ; Log queries slower than 250ms log_checkpoints = on log_connections = off log_disconnections = off log_lock_waits = on log_temp_files = 0 ; Log temp files larger than 0 bytes log_autovacuum_min_duration = 0 ; Log all autovacuum actions
Implementing a connection pooler like PgBouncer is non-negotiable for high-traffic applications. It significantly reduces the overhead of establishing and tearing down PostgreSQL connections.
; /etc/pgbouncer/pgbouncer.ini [databases] ; Format: dbname = connection_string ; Example: mydb = host=10.10.0.5 port=5432 dbname=your_db user=bouncer_user password=your_password [pgbouncer] ; Listen on a specific IP and port for application connections listen_addr = 10.10.0.6:6432 auth_file = /etc/pgbouncer/userlist.txt pool_mode = session ; Or transaction, depending on application needs max_client_conn = 2000 ; Max concurrent clients connecting to pgbouncer default_pool_size = 100 ; Pool size per database min_pool_size = 5 reserve_pool_size = 20 ; pause_mode = off ; logfile = /var/log/postgresql/pgbouncer.log ; pidfile = /var/run/postgresql/pgbouncer.pid
Redis for Caching and Session Management
Redis acts as a high-speed in-memory data store. For scaling, we’ll configure it for persistence (RDB snapshots and AOF logging) and potentially use Redis Sentinel for high availability. Key configuration parameters include `maxmemory` (to prevent Redis from consuming all system RAM) and `maxmemory-policy` (e.g., `allkeys-lru` for evicting least recently used keys). Tuning `tcp-backlog` and `tcp-keepalive` can also be beneficial under heavy load.
# /etc/redis/redis.conf daemonize yes pidfile /var/run/redis/redis-server.pid port 6379 # bind 127.0.0.1 ::1 10.10.0.7 ; Bind to specific IPs for security # Memory management maxmemory 16gb ; Set based on available RAM, leaving room for OS and other services maxmemory-policy allkeys-lru ; Evict least recently used keys when maxmemory is reached # Persistence save 900 1 ; RDB snapshot every 15 minutes if at least 1 key changed save 300 10 ; RDB snapshot every 5 minutes if at least 10 keys changed save 60 10000 ; RDB snapshot every 1 minute if at least 10000