Improve Application Latency With Read Replicas Using YugabyteDB [Video]
Learn how to optimize read latency for users worldwide by utilizing YugabyteDB's read replica nodes. Achieve scalability and low latency for real-time data.
Join the DZone community and get the full member experience.
Join For FreeScalability and low latency are crucial for any application that relies on real-time data. One way to achieve this is by storing data closer to the users.
In this post, we'll discuss how you can use YugabyteDB and its read replica nodes to improve the read latency for users across the globe.
Whether you prefer reading or watching, let’s walk through a practical example using an application that streams market orders to see how you can achieve low latency for reads regardless of a user's location.
YugabyteDB Managed Cluster
Let's say you have a YugabyteDB Managed cluster consisting of three nodes running in the United States.
Next, assume the following:
- You start the application that connects to this cluster and streams market orders into the database.
- A user from the United States opens a database connection and queries for the most popular stocks. In this case, the latency will be around 20 milliseconds.
- However, if a different user from Southeast Asia sends the same query, the latency will be much higher—around 190 milliseconds.
The increased latency for users from distant locations, such as Southeast Asia, can negatively impact the experience. One of the options to tackle this issue is by storing data closer to the users with read replicas.
Deploying Read Replica
Read replicas store a full or partial copy of the primary database. Directing read queries from the users to the nearest read replica makes it possible to improve the read latency significantly.
Let’s add a replica node to the USA-based YugabyteDB Managed cluster to demonstrate how replicas work in practice. The replica will be added to the asia-east1 region.
Follow these steps to set up your replica node:
- Navigate to your YugabyteDB Managed cluster dashboard.
- Click on "Configure Read Replicas."
- Select the "asia-east1" region.
- Confirm the configuration.
The replica node in Southeast Asia will be ready within a few minutes. Once the node becomes active in the specified region, it synchronizes with the main database to keep the data consistent.
Connecting Users to Nearby Replica Nodes
The next step is to connect the users from Southeast Asia to the newly deployed replica node in the asia-east1 region. Once that’s done, it's time to compare the latencies.
Now, when users from Southeast Asia query for the most popular stocks again, the latency drops dramatically to 20 milliseconds – similar to the latency for the user from the United States.
As a result, users from both locations will have a comparably better user experience thanks to the improved latency.
Summary
Read replicas can significantly improve the read latency for users in distant locations. By deploying replica nodes in different regions and connecting users to their nearest replica, you can match the experience for all of your users, regardless of where they are located.
Opinions expressed by DZone contributors are their own.
Comments