Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Madisoft Labs:
Doctrine sharding
Jun 19, 2017 @ 11:17:06

On the Madisoft Labs site they've posted a tutorial looking at how to split out your application's data into shards, showing how to do it using Doctrine in a Symfony application.

In the previous article we explored why sharding by tenant is a very good solution for us. In this article we dig into how to divide our Symfony app by shard. [...] We chose Doctrine as our ORM so let’s see what it offers to us.

First of all you have to note that Doctrine is composed mainly by two different parts: DBAL and ORM. ORM leverages DBAL functionalities and it’s completely transparent for sharding. DBAL is the layer we’re interested in.

The author then walks you through the configuration required to make the sharding work including default and a global connections. Next they show the creation of a ShardChoser class that reads a configuration option provided and pulls in the configuration that matches (from YAML files). Finally the ShardManager class is created to handle the connection pool that also includes a "query all" method allowing for the execution of the same SQL on all shards.

tagged: doctrine sharding shard configuration manager chooser tutorial

Link: https://labs.madisoft.it/doctrine-sharding/