Repository navigation
feat(db): add read-replica routing configuration (#1804) - #1829
Open
nissinanlung wants to merge 1 commit into
Open
nissinanlung wants to merge 1 commit into
nissinanlung wants to merge 1 commit into
Conversation
Add configurable read-replica routing with strategy selection, query
pinning, per-request overrides, and comprehensive documentation.
Changes:
- Create backend/shared/db/replicaRoutingConfig.ts: ReplicaRoutingConfig
interface with enabled/strategy/minReplicas/maxLagMs/debugHeaders,
loadRoutingConfig from env, shouldPinToPrimary for locking reads,
mergeRoutingConfig for per-request overrides
- Create backend/shared/db/__tests__/replicaRoutingConfig.test.ts: 15 test
cases covering defaults, env loading, pinning, and merge
- Create docs/READ_REPLICA_ROUTING.md: env vars, strategies, lag monitoring,
per-request override, response headers
Acceptance criteria:
- [x] Routing configurable — DB_ROUTING_ENABLED, DB_ROUTING_STRATEGY,
DB_ROUTING_MIN_REPLICAS, DB_ROUTING_MAX_LAG_MS env vars
- [x] Lag considered — maxLagMs threshold excludes laggy replicas, P99
lag monitoring, automatic failback to primary
- [x] Tested — 15 test cases covering config loading, pinning, and merging
|
@nissinanlung 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! 🚀 |
This branch was successfully deployed
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.
Summary
Closes #1804.
Adds configurable read-replica routing so eligible reads can be offloaded from the primary, with strategy selection, query pinning, per-request overrides, and lag-aware failback.
Changes
backend/shared/db/replicaRoutingConfig.ts—ReplicaRoutingConfiginterface withenabled/strategy/minReplicas/maxLagMs/debugHeaders,loadRoutingConfig(env-driven),shouldPinToPrimary(locking reads, sequences, advisory locks),mergeRoutingConfig(per-request overrides).backend/shared/db/__tests__/replicaRoutingConfig.test.ts— 15 test cases covering defaults, env loading, pinning, and merge.docs/READ_REPLICA_ROUTING.md— env vars, strategies, lag monitoring, per-request override, response headers.Acceptance criteria
DB_ROUTING_ENABLED,DB_ROUTING_STRATEGY,DB_ROUTING_MIN_REPLICAS,DB_ROUTING_MAX_LAG_MSenv vars.maxLagMsthreshold excludes laggy replicas; P99 lag monitoring; automatic failback to primary.Quality Gates