PHPackages                             furan/magento-read-write-split - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. furan/magento-read-write-split

ActiveMagento2-module[Database &amp; ORM](/categories/database)

furan/magento-read-write-split
==============================

Magento 2 module to split read &amp; write operations

v1.0.1(1mo ago)912MITPHPPHP ^8.0

Since Oct 30Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/furan917/Magento2-ReadWriteSplit)[ Packagist](https://packagist.org/packages/furan/magento-read-write-split)[ RSS](/packages/furan-magento-read-write-split/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (3)Used By (0)

Magento 2 Read/Write Database Split Module
==========================================

[](#magento-2-readwrite-database-split-module)

A Magento 2 module that implements automatic read/write database splitting. Read queries are distributed across multiple read replicas using round-robin selection, while write operations always go to the master database. CLI operations (indexing, cron, console commands) always use the master to avoid temporary table conflicts. We ensure a 'writer first' approach and include a writer fallback for defensive posturing. It is built to support multiple readers, but 1 will work just as well.

Configuration
-------------

[](#configuration)

Add reader connection configurations to `app/etc/env.php`:

```
'db' => [
    'connection' => [
        'default' => [
            'host' => 'master-db-host',
            'dbname' => 'magento',
            'username' => 'dbuser',
            'password' => 'dbpass',
            'model' => 'mysql4',
            'engine' => 'innodb',
            'initStatements' => 'SET NAMES utf8;',
            'active' => '1',
            'driver_options' => [
                1014 => false
            ]
        ],
        'indexer' => [
            'host' => 'master-db-host',
            'dbname' => 'magento',
            'username' => 'dbuser',
            'password' => 'dbpass',
            'model' => 'mysql4',
            'engine' => 'innodb',
            'initStatements' => 'SET NAMES utf8;',
            'active' => '1'
        ]
    ],
    'reader_connections' => [
        'default' => [
            // Note this is an array, even if only using 1 you must keep this structure
            [
                'host' => 'reader-1-host',
                'dbname' => 'magento',
                'username' => 'dbuser',
                'password' => 'dbpass',
                'model' => 'mysql4',
                'engine' => 'innodb',
                'initStatements' => 'SET NAMES utf8;',
                'active' => '1',
                'driver_options' => [
                    1014 => false
                ]
            ],
            [
                'host' => 'reader-2-host',
                'dbname' => 'magento',
                'username' => 'dbuser',
                'password' => 'dbpass',
                'model' => 'mysql4',
                'engine' => 'innodb',
                'initStatements' => 'SET NAMES utf8;',
                'active' => '1',
                'driver_options' => [
                    1014 => false
                ]
            ]
        ]
    ]
],
```

How It Works
------------

[](#how-it-works)

- SELECT, SHOW, DESCRIBE, EXPLAIN queries are routed to reader connections
- INSERT, UPDATE, DELETE, DDL, and transaction queries go to master
- Queries within transactions always use master for consistency
- CLI operations (bin/magento commands) always use master
- Failed reader connections automatically fall back to master
- Round-robin load balancing across active readers

Sticky Writer (intentional)
---------------------------

[](#sticky-writer-intentional)

Once any write occurs in a request, all subsequent reads in that same request are pinned to the master. This is deliberate, not a bug. Magento commonly writes an entity and immediately reads it back in the same request (e.g. saving a product then loading it to build the redirect URL in admin). A read replica that has not yet caught up via replication would return stale data or no row at all, causing redirects to 404s, missing form data, or broken admin flows. Pinning to master after the first write trades a small amount of read offload for correctness.

Disabling Readers
-----------------

[](#disabling-readers)

Set `'active' => '0'` for any reader connection to temporarily disable it without removing the configuration.

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Magento 2.4+
- MySQL master-slave replication configured
- Read replicas must be in sync with master

Notes
-----

[](#notes)

The indexer connection is never split and always uses the master database to avoid issues with temporary tables during reindexing operations.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance89

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~191 days

Total

2

Last Release

55d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15950274?v=4)[Francis](/maintainers/furan917)[@furan917](https://github.com/furan917)

---

Top Contributors

[![furan917](https://avatars.githubusercontent.com/u/15950274?v=4)](https://github.com/furan917 "furan917 (7 commits)")

---

Tags

databaseperformancesplitmagento2read-writereplica

### Embed Badge

![Health badge](/badges/furan-magento-read-write-split/health.svg)

```
[![Health](https://phpackages.com/badges/furan-magento-read-write-split/health.svg)](https://phpackages.com/packages/furan-magento-read-write-split)
```

###  Alternatives

[bvanhoekelen/performance

PHP performance tool analyser your script on time, memory usage and db query. Support Laravel and Composer for web, web console and command line interfaces.

522846.1k5](/packages/bvanhoekelen-performance)[satur.io/duckdb

DuckDB API for PHP

86104.5k5](/packages/saturio-duckdb)[sarfraznawaz2005/meter

laravel package to find performance bottlenecks in your laravel application.

2498.2k](/packages/sarfraznawaz2005-meter)[msafadi/laravel-eloquent-join-with

Laravel Eloquent Join With Relationships

1656.0k](/packages/msafadi-laravel-eloquent-join-with)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

846.1k](/packages/tommyknocker-pdo-database-class)[olliejones/index-wp-mysql-for-speed

Speed up your WordPress site by adding high-performance keys (database indexes) to your MySQL database tables.

1491.9k](/packages/olliejones-index-wp-mysql-for-speed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
