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.2(3w ago)9233MITPHPPHP ^8.0

Since Oct 30Pushed 3w 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 1w ago

READMEChangelogDependencies (3)Versions (4)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

43

—

FairBetter than 89% of packages

Maintenance94

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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 ~133 days

Total

3

Last Release

25d 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 (8 commits)")[![pknap](https://avatars.githubusercontent.com/u/1770746?v=4)](https://github.com/pknap "pknap (1 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.

521883.9k5](/packages/bvanhoekelen-performance)[mollie/magento2

Mollie Payment Module for Magento 2

1142.0M17](/packages/mollie-magento2)[satur.io/duckdb

DuckDB API for PHP

87127.1k6](/packages/saturio-duckdb)[sarfraznawaz2005/meter

laravel package to find performance bottlenecks in your laravel application.

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

Laravel Eloquent Join With Relationships

1656.0k](/packages/msafadi-laravel-eloquent-join-with)[myparcelnl/magento

A Magento 2 module that creates MyParcel labels

1861.2k](/packages/myparcelnl-magento)

PHPackages © 2026

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