Laravel 13.38 Fixes Stale Reads from Database Replicas
Laravel 13.38 adds a PreventStaleDatabaseReads middleware and a DB::usingWritePdo() method. Both are meant to make sure users immediately see the data they just saved, even when your app reads from a database replica.
The problem Laravel 13.38 targets
Many apps split their database traffic: writes go to the primary database, reads come from a replica. It's a good way to spread the load. But a replica sometimes hasn't copied the latest data yet, so a user who just saved something may see the old version when the page reloads.
That's a stale read, meaning the data you read is already out of date. To the user, it feels like a bug: "I'm sure I just saved that, so why hasn't it changed?"
Two new additions
- PreventStaleDatabaseReads: a new middleware to stop users from reading stale data from a replica.
- DB::usingWritePdo(): a new method that is also aimed at letting users see their own writes when the app reads from a replica.
The source gives only a short summary and doesn't explain how either feature works or how to use it. For implementation details, check the official Laravel 13.38 release notes.
If your app already uses read replicas to handle traffic, this release is worth keeping an eye on. Stale data hurts most in flows where users expect instant results after saving, such as forms or account settings.