feat: implement read replicas, queue-based math updates, and fix scal…#393
Merged
nicobao merged 1 commit intoOct 21, 2025
Merged
Conversation
nicobao
force-pushed
the
load-testing-solve-performance-issues
branch
from
October 21, 2025 19:19
1cf631e to
6bfa0ed
Compare
…ability issues Read Replica Infrastructure: - Add read replica support with automatic query routing via withReplicas() - Primary DB for writes, replica for SELECTs across API and math-updater - AWS RDS configuration with Secrets Manager support Queue-Based Architecture: - Replace needsMathUpdate flag with conversation_update_queue table - Rate limiting based on lastMathUpdateAt (actual processing time) - Race-condition safe updates with requestedAt timestamp matching Counter Reconciliation: - Self-healing counters reconciled by math-updater every 20s - Eliminates expensive COUNT queries from opinion/vote hot path - Updates lastReactedAt to track conversation activity Math-Updater Scalability Fixes: - Upgrade pg-boss v10→v11 with 'singleton' queue policy - Prevent concurrent job execution for same conversation - Fix Drizzle ORM stack overflow with per-batch CASE statements (1000/batch) - Handle 113k+ votes, 19k+ opinions without crashes (50-85s processing time) Load Testing: - Add k6 load testing with 2 scenarios (single/multiple conversations) - Grafana dashboards + Prometheus monitoring for PostgreSQL - UCAN crypto implementation for authenticated k6 tests Performance Impact: - Eliminated database lock contention causing system hangs under load - Sequential math processing (no concurrent waste) - Self-healing counters accurate within 20 seconds - System responsive under 200 (very active) concurrent users per conversation Documentation: - Comprehensive performance analysis with load test results - Counter reconciliation strategy documentation - AWS RDS deployment guide with read replica architecture
nicobao
force-pushed
the
load-testing-solve-performance-issues
branch
from
October 21, 2025 19:20
6bfa0ed to
fe9e525
Compare
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.
…ability issues
Read Replica Infrastructure:
Queue-Based Architecture:
Counter Reconciliation:
Math-Updater Scalability Fixes:
Load Testing:
Performance Impact:
Documentation:
Python-bridge