Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres read replica support #2019

Merged
merged 6 commits into from
Jun 27, 2024
Merged

Conversation

akhilmhdh
Copy link
Member

Description πŸ“£

This PR introduces the feature for Infisical to use postgres read replica. The write operation and transactions goes through the primary/master instance. The read operation go through read replica.

If read replicas are not provided master instance is used.

Type ✨

  • Bug fix
  • New feature
  • Breaking change
  • Documentation

Tests πŸ› οΈ

# Here's some code block to paste some code snippets

@akhilmhdh akhilmhdh added πŸš€ feature request New feature or request 🧨 backend This would need backend changes. labels Jun 25, 2024
@akhilmhdh akhilmhdh requested a review from maidul98 June 25, 2024 11:39
@akhilmhdh akhilmhdh self-assigned this Jun 25, 2024
Copy link

gitguardian bot commented Jun 25, 2024

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

πŸ”Ž Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9387833 Triggered Generic Password 259c01c docker-compose.dev-read-replica.yml View secret
9387833 Triggered Generic Password 259c01c docker-compose.dev-read-replica.yml View secret
9387833 Triggered Generic Password 259c01c docker-compose.dev-read-replica.yml View secret
πŸ›  Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


πŸ¦‰ GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link
Collaborator

@maidul98 maidul98 left a comment

Choose a reason for hiding this comment

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

Also tested on my end, works well

@@ -1,4 +1,4 @@
import { Knex } from "knex";
import { Knex as KnexOriginal } from "knex";
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: if KnexOriginal is the same as Knex, what does this do?

Copy link
Member Author

Choose a reason for hiding this comment

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

if (!readReplicaDbs.length) return db;

const selectedReplica = readReplicaDbs[Math.floor(Math.random() * readReplicaDbs.length)];
return selectedReplica;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I updated to round robin so there is even distribution of queries to read dbs. Maybe in the future we can add this counter to Redis to make it better

@maidul98 maidul98 merged commit 1b2a1f2 into Infisical:main Jun 27, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧨 backend This would need backend changes. πŸš€ feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants