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

added read replica support #2195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

added read replica support #2195

wants to merge 1 commit into from

Conversation

mekilis
Copy link
Collaborator

@mekilis mekilis commented Nov 19, 2024

This merge request adds support for read replicas to improve the scalability and efficiency of database read operations by distributing the load across multiple instances. It introduces a random selection strategy for choosing replicas and makes several key updates across the codebase to integrate this functionality.

The changes are explained below.

1. Config Enhancements

The database configuration has been expanded to include support for read replicas using the following JSON structure:

"database": {
    "read_replicas": [
        {
            "host": "localhost",
            "username": "convoy",
            "password": "convoy",
            "database": "convoy",
            "port": 5436
        },
        {
            "host": "localhost",
            "username": "convoy",
            "password": "convoy",
            "database": "convoy",
            "port": 5437
        }
    ],
    "host": "localhost",
    "username": "convoy",
    "password": "convoy",
    "database": "convoy",
    "port": 5435
}

Additionally, a read-replicas-dsn configuration option has been introduced to simplify CLI replica setup and integration:

"read-replicas-dsn": [
    "postgres://convoy:convoy@localhost:5436/convoy",
    "postgres://convoy:convoy@localhost:5437/convoy"
]

2. Repository Refactoring

Database handling in files like endpoint.go, event.go, event_delivery.go, and user.go has been refactored. Instead of directly using *sqlx.DB, these repositories now rely on the database.Database interface. This enables dynamic selection between the primary database and a read replica based on the specific needs of the function being executed.

3. Feature Gating

The read replica functionality is gated behind a license check to ensure the feature is only available to licensed users.

4. Random Selection Strategy

A random replica selection strategy has been implemented to evenly distribute read operations across available replicas, balancing the load and improving performance. This approach was chosen over a Round Robin strategy or database-level replica management to maintain simplicity and flexibility in the application layer.

These changes maintain backward compatibility while improving flexibility and performance.

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.

1 participant