doctrine-shard-manager-bundle — Doctrine sharding for Symfony
An archived Symfony bundle for routing Doctrine ORM and DBAL operations across shards with hash, range, or composite strategies and a shard-aware execution context.
An archived Symfony bundle for routing Doctrine ORM and DBAL operations across shards with hash, range, or composite strategies and a shard-aware execution context.
Doctrine Shard Manager is a Symfony bundle for distributing Doctrine ORM and DBAL operations across multiple databases or schemas according to an application-defined sharding key.
userId or clientId.hash, range, and composite sharding strategies.#[Sharding] attribute.ShardContext.composer require elrise/doctrine-shard-manager
Register the bundle when Symfony Flex is not available:
return [
Elrise\Bundle\DoctrineShardManager\ElriseDoctrineShardBundle::class => ['all' => true],
];
A sharded entity declares its strategy, key, and shard count in configuration or through an attribute:
use Elrise\Bundle\DoctrineShardManager\Attribute\Sharding;
#[Sharding(
strategy: 'hash',
key: 'userId',
shardCount: 4
)]
class User
{
}
Connections and entity managers are registered per shard. Range strategies additionally receive an ordered list of key ranges and target shard identifiers.
ShardContext selects the target shard for a unit of work and exposes the matching entity manager:
$this->shardContext->withKey(
$userId,
function (EntityManagerInterface $entityManager, string $shardId) use ($userId): void {
$user = $entityManager->getRepository(User::class)->find($userId);
}
);
This portfolio entry is archived. The source remains available as a reference implementation of application-level sharding for Symfony and Doctrine.