feat: implement database sharding strategy (#602)#704
Open
amankoli09 wants to merge 1 commit into
Open
Conversation
|
@amankoli09 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! 🚀 |
Contributor
|
kindly resolve conflict and fix workflow. |
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.
Closes #602
Overview
This PR introduces the horizontal database sharding subsystem for the TeachLink backend, It enables our application to scale horizontally by distributing PostgreSQL load across multiple independent nodes.
Key Features & Acceptance Criteria Met
docs/SHARDING_STRATEGY.md.ShardRoutersupports 4 strategies:ShardMigrationServiceperforms batched, zero-downtime, idempotent cross-shard migrations (INSERT ... ON CONFLICT DO NOTHING), including a dry-run phase and rollback support.ShardRebalanceServicemonitorspgpool utilization across shards, detecting when thresholds (e.g.SHARD_REBALANCE_HIGH_WATERMARK=80%) are breached to automatically orchestrate migration plans.ShardHealthServicetracks query latencies, active connections, pool utilization, and error rates per shard.ShardConnectionManagerlazily initializes and caches TypeORMDataSourceinstances for memory-efficient resource sharing.Changes Made
src/sharding/*: All core sharding logic, controllers, and services.src/app.module.ts: WiredShardingModuleinto core application providers.src/config/env.validation.ts&.env.example: Added validation logic and examples forSHARD_COUNTand rebalance thresholds.docs/SHARDING_STRATEGY.md: The complete operator runbook and architecture specification.Verification
ShardRoutervalidating ring distribution, deterministic routing, and replica fallback mechanisms.lint-staged,eslint,prettier) andtsc --noEmitchecks passed successfully.Closes #602