BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News AWS Reduces Latency and Costs for Key/Value Datastores with AZ Affinity Routing and GLIDE Valkey

AWS Reduces Latency and Costs for Key/Value Datastores with AZ Affinity Routing and GLIDE Valkey

Log in to listen to this article

AWS recently introduced Availability Zone (AZ) awareness in version 1.2 of the open source Valkey General Language Independent Driver for Enterprise (GLIDE) client library. By implementing AZ affinity routing in the open source key/value datastore, developers can reduce latency and costs by directing requests to replicas within the same AZ as the client.

Valkey GLIDE is an open source, multi-language client library for Valkey and Redis OSS. Written in Rust, it was released by the AWS team last summer. With Valkey 8 introducing "availability-zone" configuration, allowing clients to specify the AZ for each Valkey server, GLIDE now leverages this feature to support AZ affinity routing.

Source: AWS blog

GLIDE now supports three routing strategies. With the PREFER_REPLICA strategy, the client reads commands from any available replica, while the PRIMARY strategy ensures data freshness by always reading from the primary. The new AZ_AFFINITY strategy directs the client to read commands from a replica in the same AZ as the client. Asaf Porat Stoler, software development manager at AWS, and Adar Guma Ovadya, software engineer at AWS, write:

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.

Source: Valkey Blog

The AZ affinity routing algorithm offers two key advantages: reducing data transfer costs, since cross-zone transfers often incur additional charges in cloud environments, and minimizing latency between AZs within the same region, improving application responsiveness. Stoler and Ovadya illustrate these savings with an example:

An application in AWS with a Valkey cluster of 2 shards, each with 1 primary and 2 replicas, the instance type is m7g.xlarge. The cluster processes 250MB of data per second and to simplify the example 100% of the traffic is read operation. 50% of this traffic crosses AZs at a cost of $0.01 per GB, the monthly cross-AZ data transfer cost would be approximately $3,285. In addition the cost of the cluster is $0.252 per hour per node. Total of $1,088 per month. By implementing AZ affinity routing, you can reduce the total cost from $4,373 to $1,088, as all traffic remains within the same AZ.

The configuration depends on the specific language, and the developer must first configure the availability zone for Valkey nodes. For example, in Java:

client.configSet(Map.of("availability-zone", az), new ByAddressRoute("address.example.com", 6379))

The next step is to instantiate GLIDE with AZ-specific targeting enabled:

GlideClusterClientConfiguration config = GlideClusterClientConfiguration.builder()
	.address(NodeAddress.builder()
    	.host("address.example.com")
    	.port(6379)
    	.build())
	.readFrom(ReadFrom.AZ_AFFINITY)
	.clientAZ("us-east-1a")
	.build()
GlideClusterClient client = GlideClusterClient.createClient(config).get();

Valkey GLIDE supports Valkey 7.2 and later, as well as Redis open-source 6.2, 7.0, and 7.2. However, AZ affinity routing is only available with Valkey 8.0.

About the Author

BT