Skip to content

[Feature] Database Connection Retry and Backoff#127

Merged
MuhammedMagdyy merged 4 commits into
mainfrom
feat/db-connection-retry
Sep 4, 2025
Merged

[Feature] Database Connection Retry and Backoff#127
MuhammedMagdyy merged 4 commits into
mainfrom
feat/db-connection-retry

Conversation

@MuhammedMagdyy

Copy link
Copy Markdown
Owner

This PR improves the reliability of the database connection logic by adding retry mechanisms to both the Prisma and Redis database clients. Instead of failing immediately when a connection cannot be established, the clients will now attempt to reconnect multiple times with exponential backoff before exiting the process.

Database connection reliability improvements:

  • Added retry logic with exponential backoff to the connect method in PrismaDatabaseClient, allowing up to 10 attempts to connect before exiting the process.
  • Added similar retry logic with exponential backoff to the connect method in RedisDatabaseClient, also allowing up to 10 attempts before exiting.

@MuhammedMagdyy MuhammedMagdyy self-assigned this Sep 2, 2025
Copilot AI review requested due to automatic review settings September 2, 2025 16:17
@MuhammedMagdyy MuhammedMagdyy added the enhancement New feature or request label Sep 2, 2025
@MuhammedMagdyy MuhammedMagdyy requested review from Copilot and removed request for Copilot September 2, 2025 16:17

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds database connection retry and backoff mechanisms to improve connection reliability for both Prisma and Redis clients. The changes introduce a generic retry utility function with exponential backoff that replaces the previous immediate-failure behavior.

Key changes:

  • Created a generic retryAndBackoff utility function with exponential backoff algorithm
  • Refactored Prisma and Redis database clients to use the new retry mechanism instead of immediate process exit on connection failure

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/utils/functions.ts Implements the generic retry and exponential backoff utility function
src/database/RedisClient.ts Replaces immediate failure with retry logic for Redis connections
src/database/PrismaClient.ts Replaces immediate failure with retry logic for Prisma connections

Comment thread src/utils/functions.ts
Comment thread src/utils/functions.ts Outdated
@MuhammedMagdyy MuhammedMagdyy merged commit df44070 into main Sep 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants