kefyusuf/laravel-shard
A Laravel package for database sharding, designed to distribute data across multiple database connections and simplify horizontal scaling. It offers shard-aware Eloquent models, query routing, and migration helpers, but has limited adoption and sparse documentation.
This is a Redis sharding package: it spreads keys across multiple Redis shards, keeps a locator mapping so the app knows which shard owns a key, and provides a rebalance operation to move keys between shards. v5.0.1 is a patch release — no breaking changes, no new public API — so existing usage keeps working.
Minimal steps:
composer require the package and publish its config (php artisan vendor:publish).RedisShardConfig, so read that class (and the docs section on configuration) before hand-rolling config() calls.redis driver.Where to look first: the new "known limitations" documentation section. It is the single most useful page in this release — it explains SQLite conditional deletion, unique constraints, retry risks, and queue fallback behavior, all of which are things you will otherwise discover the hard way.
First real use case: moving a hot key range off an overloaded shard. Do it during a write-quiet window, watch the counters, and reconcile anything the run reports as retained.
Route every access through the locator. Writes and reads that bypass the locator will land on the wrong shard and will not be moved by a rebalance. Treat the package's connection as the only sanctioned entry point.
Rebalance as a queued, batched job. Rebalance is a cross-shard, best-effort operation. Wrap it in a job that processes bounded batches, persists progress, and can be resumed. Do not run it inline in a web request.
Quiesce writes during a move. This is the core operational contract, and v5.0.1 reinforces it: source deletion is now fenced by atomic snapshot predicates. If the source row changed mid-move, the row is retained and counted as fenced rather than deleted. Build a reconcile step into your runbook that reads the retained count and re-processes those keys after writes resume.
Trust the locator mapping at execution time, not at dispatch time. v5.0.1 restores keyed queue context from the current locator mapping instead of overwriting it with the captured connection. The practical pattern: dispatch rebalance/migration jobs with a key, and let the worker re-resolve the shard on pickup. For keyless jobs the package still falls back to captured affinity — so give your jobs keys if you care about mapping changes taking effect mid-flight.
Centralize config reads. RedisShardConfig is now the single source for recurring configuration. If you have custom code reaching into config('redis-shards.*') directly, migrate it to the service or you will drift from package behavior on the next patch.
Flush-aware Pulse and Octane usage. Pulse shard counters are now flushed in HTTP, queue, CLI, and Octane contexts. Under Octane, register the flush in the worker lifecycle and do not cache counter state across requests in a singleton — the package flushes, so any copy you keep will go stale.
Integration tip: test against the same engine you deploy on. The SQLite conditional-deletion path is documented as a known limitation, so a green SQLite suite does not prove your MySQL/Postgres rebalance is correct.
utf8mb4_unicode_ci-style column, what looks like an unchanged row may compare as changed and be retained. Expected, but it inflates your retained count — don't read that as corruption.How can I help you explore Laravel packages today?