MODRACXKENNETH D'SILVA

← Archive & Insights

Database Sharding & Read-Replica Architecture for E-Commerce

Database bottlenecks are the #1 cause of e-commerce checkout crashes. Splitting read traffic across RDS MySQL Read Replicas offloads high-volume catalog queries from the primary write master.

By Kenneth D'SilvaReading Time: 36 min readCategory: Architecture & Cloud

Magento 2 env.php Read-Replica Configuration

<?php
// Magento 2 Split Read/Write Database Connection Configuration (env.php)
return [
    'db' => [
        'connection' => [
            'default' => [
                'host' => 'db-master.internal', // Primary Write Connection
                'dbname' => 'magento',
                'active' => '1',
            ],
            'checkout' => [
                'host' => 'db-master.internal',
                'dbname' => 'magento',
                'active' => '1',
            ],
            'sales' => [
                'host' => 'db-replica-1.internal', // Offloaded Read Replica
                'dbname' => 'magento',
                'active' => '1',
            ]
        ]
    ]
];

Suggested & Related Reading

Explore related engineering guides from Kenneth D'Silva: