Skip to content

Fix backend infrastructure issues: Redis consolidation, migration mis… - #1009

Merged
ayomideadeniran merged 1 commit into
StellarDevHub:mainfrom
0xdevmes:fix/backend-infrastructure-issues
Jul 29, 2026
Merged

Fix backend infrastructure issues: Redis consolidation, migration mis…#1009
ayomideadeniran merged 1 commit into
StellarDevHub:mainfrom
0xdevmes:fix/backend-infrastructure-issues

Conversation

@0xdevmes

Copy link
Copy Markdown
Contributor

Fix Backend Infrastructure Issues

This PR addresses four critical infrastructure issues in the Web3-Student-Lab backend to improve resource management, database consistency, and concurrency safety.

Changes Made

#994 - Consolidate dual Redis connection managers

  • Modified RedisClient.ts to include pubClient and subClient properties with dedicated getter methods (getPubClient(), getSubClient(), getBullMQClient())
  • Refactored utils/redis.ts to re-export clients from the centralized RedisClient singleton, eliminating duplicate connection instances
  • Updated all 20+ files previously importing from utils/redis.ts to use the centralized redisClient via getter methods
  • This eliminates resource waste and enables proper caching by ensuring all Redis operations use a single connection manager

#999 - Fix SQLite vs PostgreSQL migration mismatch

  • Fixed migration_lock.toml to use postgresql provider instead of sqlite
  • Removed the SQLite dev.db file that was causing confusion between local development and production database configurations
  • Ensures Prisma migrations correctly target PostgreSQL in all environments

#988 - Complete read-replica database routing implementation

  • Read-replica routing middleware was already implemented in db/index.ts and requestContext.ts with proper context-aware routing
  • Added db-read-replica service to docker-compose.yml for local development and testing
  • Added DB_READ_REPLICA_URL environment variable to backend service configuration
  • Added read replica health check dependency to backend service
  • Enables read operations to be routed to read replicas for improved performance and scalability

#991 - Add pessimistic locking for wallet creation endpoints

  • Added pessimistic locking to the register function in auth/auth.service.ts
  • Used Prisma transaction with Serializable isolation level to prevent race conditions
  • Prevents concurrent registration attempts from assigning the same wallet address to multiple users
  • Ensures data integrity during wallet address assignment

Files Modified

  • 23 files changed, 276 insertions(+), 214 deletions(-)
  • Key files: RedisClient.ts, utils/redis.ts, auth.service.ts, migration_lock.toml, docker-compose.yml, and all Redis client imports across the codebase

Testing Recommendations

  • Test Redis pub/sub functionality with the new centralized client
  • Verify database migrations run correctly with the fixed migration lock
  • Test read-replica routing with the new docker-compose service
  • Test concurrent registration attempts to verify pessimistic locking works

Closes #994
Closes #999
Closes #988
Closes #991

…match, read-replica routing, and pessimistic locking

- Consolidate dual Redis connection managers into single RedisClient singleton
- Fix SQLite vs PostgreSQL migration mismatch in migration_lock.toml
- Add PostgreSQL read-replica service to docker-compose.yml
- Add pessimistic locking to wallet creation endpoints
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

@0xdevmes is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@0xdevmes 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

@ayomideadeniran

Copy link
Copy Markdown
Contributor

Pr under review.

1 similar comment
@ayomideadeniran

Copy link
Copy Markdown
Contributor

Pr under review.

@ayomideadeniran
ayomideadeniran merged commit 3dd95bf into StellarDevHub:main Jul 29, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment