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

Support master/replica databases #175

Open
jace opened this issue Feb 27, 2018 · 0 comments
Open

Support master/replica databases #175

jace opened this issue Feb 27, 2018 · 0 comments

Comments

@jace
Copy link
Member

jace commented Feb 27, 2018

For performance reasons, apps like Hasjob in production should have separate master and replica databases, running on different nodes:

  1. All writes happen on the master database
  2. All reads happen on the replica database
    a. …unless we just wrote to master, in which case read from master

Here are a couple of gists showing how this can be achieved transparently with Flask-SQLAlchemy:

We'll need a variation of the second gist to handle scenario 2a: record a dirty flag in application context (_app_ctx_stack.top) and send all queries to master for as long as the flag remains. We also need to debug and resolve the problem with self._flushing, as reported in the various comments on the first gist.

Coaster provides a copy of Flask-SQLAlchemy's SQLAlchemy object in the coaster.db module (not the db instance that is also provided). Our version of the subclass could reside here and be available for importing to apps.

@jace jace changed the title Support master/slave databases Support master/replica databases Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant