# Laravel Read Replicas: Prevent Stale Reads After a Write

DevFeed: [Laravel Read Replicas: Prevent Stale Reads After a Write](<https://devfeed.tech/articles/laravel-read-replicas-prevent-stale-reads-after-a-write-97626.md>)

Original publisher: [Read original article](<https://laravel-news.com/laravel-prevent-stale-database-reads>)

Author: Paul Redmond

Published: 2026-10-22T23:20:21Z

Content type: tutorial

Language: en

Sources: [Laravel](<https://devfeed.tech/sources/laravel.md>)

Topics: [read-replica](<https://devfeed.tech/topics/read-replica.md>), [Laravel](<https://devfeed.tech/topics/laravel.md>), [middleware](<https://devfeed.tech/topics/middleware.md>), [consistency](<https://devfeed.tech/topics/consistency.md>), [Eloquent ORM](<https://devfeed.tech/topics/eloquent.md>)

Tags: [database](<https://devfeed.tech/tags/database.md>), [lag](<https://devfeed.tech/tags/lag.md>), [laravel](<https://devfeed.tech/tags/laravel.md>), [middleware](<https://devfeed.tech/tags/middleware.md>), [news](<https://devfeed.tech/tags/news.md>), [prevent](<https://devfeed.tech/tags/prevent.md>), [read-replicas](<https://devfeed.tech/tags/read-replicas.md>), [replica](<https://devfeed.tech/tags/replica.md>), [replica-lag](<https://devfeed.tech/tags/replica-lag.md>), [write](<https://devfeed.tech/tags/write.md>)

## AI overview

Laravel 13.38 adds `PreventStaleDatabaseReads` to address replica lag across separate requests: after a request modifies records, the middleware stores a session timestamp, then routes reads to the write server on subsequent requests for a configurable window (two seconds by default). Set the window to cover the longest lag seen in replica metrics; a shorter window can still expose stale data. This differs from the `sticky` connection option, which only keeps reads on the writer for the remainder of the same request. For code that needs fresh reads regardless of the user's recent writes, `DB::usingWritePdo()` routes all reads inside a callback to the writer, including relationship queries; the connection returns to its prior setting when the callback finishes or throws. Queries in a transaction already use the writer. The article also notes that middleware tests should avoid `RefreshDatabase`, whose transaction would make queries use the writer even without the middleware.

## Source excerpt

Laravel's PreventStaleDatabaseReads middleware keeps a user's reads on the write database after they save, so read replica lag doesn't show them old data. The post Laravel Read Replicas: Prevent Stale Reads After a Write appeared first on Laravel News. Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.