Skip to content

3. Network Topology

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

Preferred Connections

When your databases are located in separate physical locations there is typically an advantage to connecting to a nearby server instead of a more distant one. The read and write parameters can be used to place servers into logical groups of more or less preferred connections.

Lower numbers indicate greater preference.

Example

This configuration instructs LudicrousDB to try reading from one of the local replicas at random. If that replica is unreachable or refuses the connection, the other replica will be tried, followed by the primary, and finally the remote replicas again in random order.

Local replica 1:   'write' => 0, 'read' => 1,
Local replica 2:   'write' => 0, 'read' => 1,
Local primary:     'write' => 1, 'read' => 2,
Remote replica 1:  'write' => 0, 'read' => 3,
Remote replica 2:  'write' => 0, 'read' => 3,

In the other datacenter, the primary would be remote. We would take that into account while deciding where to send reads. Writes would always be sent to the primary, regardless of proximity.

Local replica 1:   'write' => 0, 'read' => 1,
Local replica 2:   'write' => 0, 'read' => 1,
Remote replica 1:  'write' => 0, 'read' => 2,
Remote replica 2:  'write' => 0, 'read' => 2,
Remote primary:    'write' => 1, 'read' => 3,

Concepts

There are many ways to achieve different configurations in different locations. You can deploy different config files. You can write code to discover the web server's location, such as by inspecting $_SERVER or php_uname(), and compute the read/write parameters accordingly.

Clone this wiki locally