Skip to content

Conversation

gulbaki
Copy link

@gulbaki gulbaki commented Jul 14, 2025

Fixes: #23
Implements support for AZAffinity and AZAffinityReplicasAndPrimary read strategies based on the Valkey blog post on AZ Affinity.
Developers can now use:
scaleReads: "AZAffinity" | "AZAffinityReplicasAndPrimary", clientAz: "zone-a" // etc.
During Redis initialization, a HELLO 3 call is made to retrieve the availabilityZone, which is then saved under each node instance.
A new selectNodeAz method was introduced. This method is called internally when scaleReads is set to AZAffinity or AZAffinityReplicasAndPrimary. Based on the strategy, it routes commands to the most suitable node:
AZAffinity logic:

  1. Prefer a replica in the same AZ
  2. If not available, pick a replica from a different AZ
  3. If none, fallback to master.

AZAffinityReplicasAndPrimary logic:

  1. Prefer a replica in the same AZ
  2. If not available, fallback to local master
  3. Then to remote replica
  4. Then to remote master

Tests
Tests were added to cover each of the above scenarios.
However, two tests sometimes pass and sometimes fail:
I couldn't figure out exactly why this happens. I couldn’t find a solution
AZAffinity → selects remote replica when no local replica exists
AZAffinityReplicasAndPrimary → selects local primary when no local replica exists

and I’m unsure if I’ve placed the test logic in the best place,
or if additional handling is needed in selectNodeAz or elsewhere

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.

Implement az-affinity-strategy

1 participant