Introduce ReplicationCoordinator to support multiple AZs #35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a draft PR to solicit some initial feedback.
I've got a branch of HEY using this at https://github.com/basecamp/haystack/pull/7837 which is deployed in the beta1 environment.
I've got a branch of Solid Queue using this interface at flavorjones/solid_queue#1
And I've got a MovableWriter gem that implements this interface for replicated SQLite (still very rough, needs to be tested and the processes table does not yet do the right thing) at https://github.com/basecamp/fizzy/pull/580
Motivation / Background
It's common for applications that are deployed across multiple availability zones (using a replicated database) to create an ad-hoc method for processes to discover which zone is "active", meaning the zone primarily responsible for writing to the database.
For example, a team may choose to use a MySQL system variable to indicate the data center where the primary database sits. In which case, they need to write code to make sure all Rails processes in all zones query this efficiently (it may be slow to access in non-primary zones) and are notified if the primary zone changes, as in the case of a data center failover.
Detail
ReplicationCoordinator::Base
is introduced to allow developers to write code that determines whether a process is in an active zone, and then:Additionally, a test helper class is provided to simplify testing failover behavior.
Finally, Rails is configured by default to use a simple concrete replication coordinator,
SingleZone
, which always indicates the caller is in an active zone.Additional information
TODO - link to the Solid Queue PR once it's open
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]