feat: lag-aware DB read routing (#715) - #796
Open
Bug00Joe wants to merge 1 commit into
Open
Conversation
Add ReplicaLagMonitor and per-query readQuery routing that steers SELECTs to the primary when cross-region replica lag exceeds the SLO. Emits db.replica.route_primary on fallback and db.replica.recovered when lag drops back below threshold. Declares REPLICA_* env schema.
|
@Bug00Joe Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Author
|
@thlpkee20-wq done closes #715 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds lag-aware read routing for cross-region replicas. When replica lag exceeds the RPO SLO,
readQuery()steers SELECTs to the primary and emitsdb.replica.route_primary. When lag recovers, replica routing resumes anddb.replica.recoveredis emitted.Related Issue
Closes #715
Changes
🗄️ Lag-aware routing
src/db/replicaLagMonitor.tspg_last_xact_replay_timestamp().db.replica.recovered.src/db/pool.ts—readQuery()applies routing per-query (not per-connection); emitsdb.replica.route_primaryon primary fallback.src/config/env.ts— declaresREPLICA_DB_URL,REPLICA_LAG_THRESHOLD_MS,REPLICA_POLL_INTERVAL_MS.src/db/replicaLagMonitor.test.ts— recovery metric assertion.docs/lag-aware-read-routing.md— docs for Multi-region failover: cross-region replica lag SLO with automatic read routing #715.Verification Results
pool.tsper-queryreadQuery()db.replica.route_primaryon primary fallbackdb.replica.recoveredTimeline