Skip to content

perf: postgres read replica routing for analytics queries#576

Merged
0xVida merged 2 commits intoStellar-Fluid:mainfrom
promisszn:feature/234-db-read-replicas
Apr 25, 2026
Merged

perf: postgres read replica routing for analytics queries#576
0xVida merged 2 commits intoStellar-Fluid:mainfrom
promisszn:feature/234-db-read-replicas

Conversation

@promisszn
Copy link
Copy Markdown
Contributor

  • server/src/utils/db.ts: export replicaDb client alongside primary prisma; replicaDb uses DATABASE_REPLICA_URL when set, falls back to DATABASE_URL so dev/staging environments work without a replica
  • Route heavy read-only SELECT queries to the replica:
    • adminAnalytics.ts (30-day transaction aggregation)
    • adminTransactions.ts (up to 1000-row listing)
    • adminSAR.ts (findMany/findUnique/count/groupBy) while keeping the single sARReport.update() on the primary write path
  • DATABASE_REPLICA_URL documented in .env.example with RDS and streaming replication examples
  • 4/4 read/write splitting unit tests pass

Closes #234

- server/src/utils/db.ts: export replicaDb client alongside primary prisma;
  replicaDb uses DATABASE_REPLICA_URL when set, falls back to DATABASE_URL
  so dev/staging environments work without a replica
- Route heavy read-only SELECT queries to the replica:
  - adminAnalytics.ts (30-day transaction aggregation)
  - adminTransactions.ts (up to 1000-row listing)
  - adminSAR.ts (findMany/findUnique/count/groupBy) while keeping the
    single sARReport.update() on the primary write path
- DATABASE_REPLICA_URL documented in .env.example with RDS and streaming
  replication examples
- 4/4 read/write splitting unit tests pass

Closes Stellar-Fluid#234

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 25, 2026

@promisszn 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! 🚀

Learn more about application limits

@0xVida 0xVida merged commit 8de19ff into Stellar-Fluid:main Apr 25, 2026
6 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database Read Replicas for High-Traffic Analytics Queries

2 participants