Skip to content

Commit c3b28b8

Browse files
authored
add AZ_AFFINITY_REPLICAS_AND_PRIMARY read strategy example and diagram (#236)
### Description Adding documentation for the new read strategy AzAffinityReplicasAndPrimary relates to issues valkey-io/valkey-glide#2792 and valkey-io/valkey-glide#3085 <!-- Describe what this change achieves--> ### Issues Resolved <!-- List any issues this PR will resolve. --> <!-- Example: closes #1234 --> ### Check List - [x] Commits are signed per the DCO using `--signoff` By submitting this pull request, I confirm that my contribution is made under the terms of the BSD-3-Clause License. --------- Signed-off-by: Muhammad Awawdi <[email protected]>
1 parent 245e268 commit c3b28b8

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

content/authors/muhammadawawdi.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Muhammad Awawdi
3+
extra:
4+
photo: '/assets/media/authors/muhammadawawdi.jpeg'
5+
github: muhammad-awawdi-amazon
6+
---
7+
8+
Muhammad is a software engineer at AWS ElastiCache, building Valkey GLIDE and large-scale distributed systems. When he’s not building faster tech, he’s lifting weights, grilling barbecue, or geeking out over the latest innovations.

content/blog/2024-12-22-az-affinity-strategy.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title= "Reducing application latency and lowering Cloud bill by setting up your client library"
33
date= 2025-01-08 01:01:01
44
description= "By implementing AZ affinity routing in Valkey and using GLIDE, you can achieve lower latency and cost savings by routing requests to replicas in the same AZ as the client."
5-
authors= [ "asafporatstoler", "adarovadya"]
5+
authors= [ "asafporatstoler", "adarovadya", "muhammadawawdi"]
66
+++
77
How can adjusting your client library help you reduce Cloud costs and improve latency?
88

@@ -28,8 +28,9 @@ GLIDE provides flexible options tailored to your application’s needs:
2828
* ```PRIMARY```: Always read from the primary to ensure the freshness of data.
2929
* ```PREFER_REPLICA```: Distribute requests among all replicas in a round-robin manner. If no replica is available, fallback to the primary.
3030
* ```AZ_AFFINITY```: Prioritize replicas in the same AZ as the client. If no replicas are available in the zone, fallback to other replicas or the primary if needed.
31+
* ```AZ_AFFINITY_REPLICAS_AND_PRIMARY```: Prioritize replicas in the same AZ as the client. If no replicas are available in the zone, fallback to the primary in the same AZ. If neither are available, fallback to other replicas or the primary in other zones.
3132

32-
In Valkey 8, ```availability-zone``` configuration was introduced, allowing clients to specify the AZ for each Valkey server. GLIDE leverages this new configuration to empower its users with the ability to use AZ Affinity routing. At the time of writing, GLIDE is the only Valkey client library supporting the AZ Affinity strategy, offering a unique advantage.
33+
In Valkey 8, ```availability-zone``` configuration was introduced, allowing clients to specify the AZ for each Valkey server. GLIDE leverages this new configuration to empower its users with the ability to use AZ Affinity routing. At the time of writing, GLIDE is the only Valkey client library supporting the AZ Affinity strategies, offering a unique advantage.
3334

3435
## AZ Affinity routing advantages
3536

@@ -40,7 +41,7 @@ In Valkey 8, ```availability-zone``` configuration was introduced, allowing cli
4041

4142
2. **Minimize Latency** Distance between AZs within the same region— for example, in AWS, is typically up to 60 miles (100 kilometers)—adds extra roundtrip latency, usually in the range of 500µs to 1000µs. By ensuring requests remain within the same AZ, you can reduce latency and improve the responsiveness of your application.
4243

43-
**Example:**
44+
**Example 1:**
4445
Consider a cluster with three nodes, one primary and two replicas. Each node is located in a different availability zone. The client located in az-2 along with replica-1.
4546

4647
**With ```PREFER_REPLICA``` strategy**:
@@ -53,6 +54,20 @@ In Valkey 8, ```availability-zone``` configuration was introduced, allowing cli
5354
In this case, the client will read commands from a replica in the same client's AZ and the average latency is, for example, about 300 microseconds.
5455

5556
![AZ_AFFINITY Read strategy latency example](/assets/media/pictures/AZ_AFFINITY_strategy.png)
57+
58+
**Example 2:**
59+
Consider a cluster with three nodes, one primary and two replicas. Each node is located in a different availability zone. The client located in az-2 along with the primary node. The replicas are located in az-1 and az-3.
60+
61+
**With ```AZ_AFFINITY``` strategy**:
62+
In this case, the client attempts to read from a replica in the same AZ. Since none are available in az-2, it falls back to a replica in another AZ, such as az-1 or az-3.
63+
and the average latency is, for example, about 800 microseconds.
64+
65+
![AZ_AFFINITY Read strategy latency example](/assets/media/pictures/AZ_AFFINITY_strategy2.png)
66+
67+
**With `AZ_AFFINITY_REPLICAS_AND_PRIMARY` strategy**:
68+
In this case, the client first attempts to read from a replica in the same AZ. Since no local replica exists, it reads from the primary located in az-2. The average latency is, for example, about 300 microseconds.
69+
70+
![AZ_AFFINITY_REPLICAS_AND_PRIMARY Read strategy latency example](/assets/media/pictures/AZ_AFFINITY_REPLICAS_AND_PRIMARY_strategy.png)
5671

5772
## Configuring AZ Affinity Connections with GLIDE
5873

@@ -152,6 +167,9 @@ Setting up AZ affinity routing in GLIDE is simple, allowing you to leverage its
152167
## Conclusion
153168
By implementing AZ affinity routing in Valkey and using GLIDE, you can achieve lower latency and cost savings by routing requests to replicas in the same AZ as the client.
154169

170+
---
171+
*Updated May 2025 to cover the `AZ_AFFINITY_REPLICAS_AND_PRIMARY` strategy and a corresponding example.*
172+
155173
### Further Reading
156174
* [Valkey GLIDE GitHub Repository](https://github.com/valkey-io/valkey-glide)
157175
* [Valkey Documentation](https://valkey.io/)
21.7 KB
Loading
63.8 KB
Loading
42.6 KB
Loading

0 commit comments

Comments
 (0)