Skip to content

Document read replication and transaction behaviour#574

Open
Rochet2 wants to merge 2 commits intosequelize:mainfrom
Rochet2:patch-1
Open

Document read replication and transaction behaviour#574
Rochet2 wants to merge 2 commits intosequelize:mainfrom
Rochet2:patch-1

Conversation

@Rochet2
Copy link
Copy Markdown

@Rochet2 Rochet2 commented Sep 6, 2023

It appears that there is no documentation that I could find on read replication and how useMaster is not needed for select queries in a transaction for consistency. This PR should document the default behaviour of SELECT queries in a transaction when using read replication.

In V7 there will be a new setting for transactions to allow going to read pool only.
It could also be mentioned here maybe?

I also wonder (have not tested) what happens if one explicitly sets useMaster true/false inside a transaction.
Maybe something to document as well.

@Rochet2 Rochet2 requested a review from a team as a code owner April 11, 2024 20:16
@Rochet2 Rochet2 requested review from WikiRik and ephys April 11, 2024 20:16
@ephys ephys requested a review from Copilot April 5, 2026 15:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the read replication documentation to clarify how pool selection behaves when running queries inside transactions.

Changes:

  • Clarifies that transactional reads/writes default to using the write pool.
  • Adjusts the existing description of how useMaster and SELECT interact with replication pools.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

If you want to modify these, you can pass pool as an options when instantiating Sequelize, as shown above.

Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. Read replica are switched using a basic round robin scheduling.
Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replica are switched using a basic round robin scheduling.
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

This new sentence is grammatically incorrect and ambiguous: "When all reads and writes when using transactions will be sent…". Consider rewriting as separate, clear sentences (e.g., "Within a transaction, all queries use the same connection. With replication enabled, transactions default to acquiring from the write pool, so SELECTs in that transaction also use the write pool."). This more directly explains why SELECT behaves differently in a transaction.

Suggested change
Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replica are switched using a basic round robin scheduling.
Each `write` or `useMaster: true` query will use the write pool. `SELECT` queries will use the read pool by default. Within a transaction, all queries use the same connection, so with replication enabled they are sent to the write pool by default. Read replicas are switched using a basic round robin scheduling.

Copilot uses AI. Check for mistakes.
If you want to modify these, you can pass pool as an options when instantiating Sequelize, as shown above.

Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. Read replica are switched using a basic round robin scheduling.
Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replica are switched using a basic round robin scheduling.
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

Correct grammar: "Read replica are" should be "Read replicas are".

Suggested change
Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replica are switched using a basic round robin scheduling.
Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replicas are switched using a basic round robin scheduling.

Copilot uses AI. Check for mistakes.
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.

3 participants