Skip to content

2. Primary & Replica Databases

John James Jacoby edited this page Jun 27, 2024 · 5 revisions

Reads & Writes

When defining a database, it needs to include both read and write parameters. They allow or disallow the use of that database for reading or writing. On or off. Yes or no. 1 or 0.

A primary database would typically be configured to allow both reading and writing:

'write' => 1,
'read'  => 1,

while a replica would typically be allowed only to read:

'write' => 0,
'read'  => 1,

In some situations, it might be advantageous to disallow reading from the primary (such as when there are many replicas available and the primary is frequently busy with writes).

'write' => 1,
'read'  => 0,

In-memory Read/Write Tracking

Internally, LudicrousDB tracks the database tables it has written to (in the current PHP process) and will intelligently prefer to send subsequent read queries to the same server that previously & recently performed a successful write query.

This means that a primary database that is configured to disallow reads may still receive read queries, but only after it was just written to.

Clone this wiki locally