Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Cached Database Stickiness Laravel Package

mpyw/laravel-cached-database-stickiness

Keeps Laravel's read/write database stickiness alive across requests by caching it. After a write, later requests are routed to the primary connection for a set period, preventing stale reads from replicas when using read/write connection splitting.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • The package targets a specific, well-understood gap: read/write splitting with replica lag. Laravel's native sticky flag only guarantees read-your-writes within a single request; this package caches the sticky state so subsequent requests (HTTP or queued jobs) also route to the primary until a TTL expires.
  • It sits at the connection/manager layer, so it is transparent to application code — no repository or model changes required. That is a low-intrusion fit for teams that already have read/write connections configured.
  • Value is conditional: teams on a single database, or already reading exclusively from the primary, gain nothing. The package is only relevant if replica lag has caused observable stale-read bugs.
  • It introduces a hard runtime dependency on a shared cache store. That is an architectural coupling worth accepting consciously, not incidentally.

Integration feasibility

  • Composer install plus published config; service provider auto-discovery. No schema changes, no data migration, no backfill. Integration effort is measured in hours, not sprints.
  • v2.2.1 is a compatibility-only release: PHP 8.5 added to the CI matrix, Laravel 14 added to composer constraints, Laravel 13 documented. No new features, no API changes, no deprecations.
  • Net effect on feasibility is positive but narrow: it removes the package as a blocker for a framework or runtime upgrade. It does not change the integration shape.
  • Pin to ^2.2.1 rather than a floating constraint, and confirm the target environment's exact Laravel/PHP pair is in the package's test matrix, not just its constraint expression.

Technical risk

  • Constraint widening without matching test coverage. The release notes explicitly state PHP 8.5 was added to the CI matrix but say nothing about adding Laravel 14 to it. A widened composer constraint that is not exercised in CI is a declaration, not a guarantee. This is the single most important item to verify before relying on Laravel 14 support.
  • Internals coupling. Cache-backed stickiness requires hooking the database manager and observing write events. Packages in this position are structurally exposed to framework refactors in the connection layer — precisely the area Laravel 14 touches.
  • Long-lived process state. Under Octane or queue workers, sticky state must be correctly scoped and reset. A missed reset turns "sticky for a TTL" into "permanently pinned to primary," which degrades silently under load rather than erroring.
  • Primary load amplification. Every sticky window redirects all reads for that session to the primary. Under write-heavy traffic this can shift a meaningful share of read volume onto the primary — the opposite of the intended effect.
  • AI-assisted contributions. Both PRs are tagged [Claude]. Not disqualifying, but it raises the bar on maintainer review rigor for a package that patches framework internals.

Key questions

  1. Is Laravel 14 actually present in the CI test matrix, or only in the composer constraint? What is the highest Laravel version with real integration test coverage?
  2. What is the PHP floor and ceiling after this release, and is PHP 8.5 tested against the oldest supported Laravel, or only the newest?
  3. How is sticky state scoped and reset under Octane and Horizon workers — per request, per job, or per process?
  4. What is the configured TTL semantics, and does it account for measured replica lag in our environment?
  5. On cache-store outage, does the package fail open (stale reads, silent correctness bug) or fail closed (all traffic to primary, availability risk)? Is that behavior configurable?
  6. Which cache drivers are supported and tested for the cross-request path — Redis only, or Memcached/database too?

Integration Approach

Stack fit

  • Requires a Laravel application using read/write connection splitting, plus a shared cache backend reachable by every app node (Redis is the realistic choice).
  • Fits cleanly alongside standard Laravel data access. Higher friction with packages that themselves wrap or replace the DB connection: multi-tenancy packages that swap connections per tenant, query loggers, debug bars, and any tooling that resolves connections before the service provider boots.
  • If the cache store is already Redis-backed and highly available, incremental infrastructure cost is effectively zero.

Migration path

  • Drop-in adoption. Install, publish config, set the TTL, enable for the target connections, deploy. No schema migration, no dual-write period, no rollback script needed.
  • Rollback is a config toggle plus a cache flush — cheap and fast, which materially lowers the cost of a failed pilot.
  • Recommended sequence: enable in a non-production environment, run the existing integration suite, then enable in production behind a config flag with a conservative TTL, and observe primary read volume before widening.

Compatibility

  • The 2.2.1 constraint changes widen the supported framework range but do not alter runtime behavior for existing users. Upgrading from 2.2.0 is a no-op at the application layer.
  • The real compatibility surface is elsewhere: cache driver support, Octane, and other connection-wrapping packages. Validate those explicitly rather than inferring from the Laravel constraint.

Sequencing

  1. Confirm the framework/PHP pair is in the CI matrix (see key questions). If Laravel 14 is constraint-only, treat Laravel 14 as unsupported until verified.
  2. Inventory connection-wrapping packages and confirm no conflict.
  3. Pilot in staging with an artificially induced replica lag to prove the sticky behavior actually fires.
  4. Production rollout behind a flag, with primary read volume and cache hit rate on a dashboard from day one.
  5. Only then relax the TTL toward the measured replica lag.

Operational Impact

Maintenance

  • Small, single-maintainer package. Release cadence is the positive signal here — 2.2.1 landed specifically to keep pace with PHP 8.5 and Laravel 14, which is the behavior you want from a dependency in the framework-internals layer.
  • The maintenance burden shifts to us: because it patches internals, every Laravel minor upgrade requires re-validating this package before the framework bump can ship. Budget that into upgrade planning rather than discovering it mid-upgrade.
  • AI-assisted PRs warrant a maintainer-review check on future releases; treat changelogs as claims to verify, not facts.

Support

  • Community-only, no commercial backing, no SLA. Acceptable for a narrow, well-understood correctness shim; not acceptable as the sole mechanism protecting a revenue-critical read path without a documented fallback.
  • Bus factor of one. Mitigate by keeping the rollback path (config flag + cache flush) documented in the runbook and by pinning the version so an abandoned upstream cannot break builds.

Scaling

  • Adds a cache round-trip to the request path. Negligible against typical request budgets, but it is a new synchronous dependency on every sticky check.
  • Primary read amplification is the real scaling concern: read capacity planning must assume a nonzero fraction of reads hit the primary during sticky windows. Model this against peak write rate, not average.
  • The package scales horizontally without coordination because state lives in the shared cache — provided the cache itself is highly available.

Failure modes

  • Cache eviction or miss: premature unstick, silently reintroducing the stale reads the package exists to prevent. Hardest failure to detect because nothing errors.
  • Cache store outage: either stale reads (fail open) or a primary overload event (fail closed). Both are serious; the mode must be known and chosen deliberately before rollout.
  • Octane/queue state leak: permanently sticky workers, pinning sustained read traffic to the primary with no error signal.
  • TTL shorter than actual replica lag: the package is enabled, appears healthy, and does not actually solve the problem.
  • Framework upgrade drift: a Laravel minor changes connection internals, the package's hook silently stops firing, and consistency regressions return with no alert.
  • Detection requires deliberate instrumentation: alert on primary read ratio and on sticky-flag hit rate. Absent those, every failure above is invisible until a customer reports stale data.

Ramp-up

  • Low for implementation — an engineer familiar with Laravel config can integrate in under a day.
  • Non-trivial for operational understanding. On-call must know that a cache flush changes read routing, that a TTL change alters primary load, and that "no errors" does not mean "working." A one-page runbook covering the flag, the flush, the TTL, and the two dashboards is the minimum bar before production.
  • Overall: low integration cost, moderate operational literacy cost, and a small but real ongoing upgrade tax. Justified if replica-lag stale reads are an actual, observed problem; unjustified as speculative hardening.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator