[Backend] Database Read Replicas & Connection Pooling Optimization with PgBouncer
Overview & Background
As event volume and active stream queries grow, database connection limits and read query contention can degrade API latency. Setting up explicit read/write splitting in Prisma along with connection pooling optimization ensures backend responsiveness during high-traffic streaming volume.
Technical Specification & Architecture
- Read/Write Splitting with Prisma:
- Configure Prisma read-replica extension (
@prisma/extension-read-replicas) inbackend/src/lib/prisma.ts. - Direct write mutations (indexer worker, user creations) to primary DB instance.
- Route high-volume read endpoints (
/streams,/events,/summary) to read replicas.
- Configure Prisma read-replica extension (
- Connection Pool Tuning:
- Tune
pg.Poolparameters inbackend/src/lib/pg-pool.ts:- Max connections per container: 20
- Idle timeout: 10,000ms
- Connection timeout: 2,000ms
- Tune
- Docker Compose & Production Setup:
- Include PgBouncer sidecar configuration in
docker-compose.yml.
- Include PgBouncer sidecar configuration in
Target Files
backend/src/lib/prisma.tsbackend/src/lib/pg-pool.tsdocker-compose.yml
Acceptance Criteria
- [ ] Prisma routes read queries to read replica when
DATABASE_READ_REPLICA_URLis configured. - [ ] Eliminates connection exhaustion under load tests (1,000 concurrent requests).
- [ ] Graceful fallback to primary DB when replica is unavailable.
let me work on this issue
Hi @maintainers, I am ready to resolve this!
Execution Plan for [Backend] Database Read Replicas & Connection Pooling Optimization with PgBouncer:
- Backend Implementation: Structure
[Backend] Database Read Replicas & Connection Pooling Optimization with PgBouncerwith strict input validation, idempotent handlers, and proper error codes. - Integration Tests: Provide automated tests covering both valid payloads and failure scenarios.
Why assign me?
- Proven Proof-of-Work: #1 contributor on Mova Store (28 merged Web3 PRs) and official ElizaOS contributor.
- Fast Turnaround: Dedicated to shipping a tested, production-grade PR within 12–24 hours.
- Zero Maintainer Burden: Self-documenting code with green CI and tests included so you don't spend time debugging.
Ready to deliver within 12–24h—please feel free to assign it to me!
Hi everyone,
I can tackle [Backend] Database Read Replicas & Connection Pooling Optimization with PgBouncer. Proposed implementation roadmap:
- [ ] Analysis: Inspect current behavior and edge cases in
LabsCrypt/flowfi - [ ] Implementation: Structure backend handlers for
[Backend] Database Read Replicas & Connection Pooling Optimization with PgBouncerwith strict input validation, proper HTTP error codes, and idempotent execution. - [ ] Testing: Cover implementation with end-to-end integration tests for standard and edge-case inputs.
- [ ] PR: Atomic commit with clean git hygiene and passing CI
Looking forward to contributing—please feel free to assign!
@benedict102 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
I would like to work on this issue
ℹ️ Repo Maintainers: To accept this application, review their application or assign @benedict102 to this issue.
@Marvellous805 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
Hi maintainer I can fix this.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Marvellous805 to this issue.
@aduagba4133 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
I am a detail-oriented and reliable individual with strong skills in research, data entry, online tasks, and following instructions. I am committed to delivering accurate and high-quality work within deadlines and am available to start tasks immediately.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @aduagba4133 to this issue.
Congratulations, @Marvellous805! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on September 30, 2026.
🧑💻 @Marvellous805: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
🎉 This issue has been marked as completed on GrantFox!
@Marvellous805's PR #1558 was approved and merged by @K1NGD4VID.
🏆 @Marvellous805: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (175 total points). Track your full progress on GrantFox.
👏 Great work, @Marvellous805! Keep contributing to LabsCrypt.
This issue has been marked as completed by a Drips Wave moderator for @Marvellous805 as part of the Stellar Wave Program's 9th Wave 🥳
Moderator's reason: [Auto-assessed] The contributor's PR #1558 was successfully merged by maintainer @K1NGD4VID on 2026-10-08. The changes correctly implement Prisma read replicas, connection pooling configuration updates, and PgBouncer integration as requested in issue #1325.
😎 @Marvellous805: You earned 150 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here.
🧑💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.
ℹ️ Note: This issue was marked complete via moderation. Points were issued even though the GitHub issue remains open.