Want to speed up your reads?
Be a Leader and a Follower :-)
In CockroachDB, a follower is a replica of a database that synchronises with the leader to ensure data consistency and availability. The leader is the node that accepts write requests and coordinates updates to the database. The followers replicate the leader's data and respond to read requests from clients.
When a client sends a read request, the CockroachDB cluster selects a follower that is closest to the client and responds with the requested data. The follower checks with the leader to ensure that the data it is serving is up-to-date, and if necessary, it synchronises with the leader before responding to the client. This ensures that the client always receives the most recent data.
Followers in CockroachDB also serve as failover targets in case the leader becomes unavailable. If the leader fails, the followers can elect a new leader and continue to serve read and write requests. This ensures high availability and durability of data even in the event of failures.
In summary, followers in CockroachDB are replicas of the leader database that synchronise with the leader to ensure data consistency and availability. They serve read requests from clients and can also act as failover targets in case of leader failure.
What are the pros and cons?
- Improved read performance: Follower reads can be faster than reading from the leader because the follower nodes are typically geographically closer to the client, reducing network latency.
- Increased scalability: By offloading read requests to follower nodes, the leader node can focus on handling write requests, improving overall system scalability.
- Higher availability: Followers can serve as failover targets in case the leader becomes unavailable, ensuring high availability of data.
- Consistent reads: Followers read from a consistent snapshot of the data, ensuring that clients receive the most up-to-date data.
- Increased replication traffic: Follower reads require additional replication traffic, which can increase network traffic and affect system performance.
- Possible staleness of data: Although followers read from a consistent snapshot, there may be some latency in replicating updates from the leader, resulting in some stale data being served to clients.
- Higher resource utilisation: Maintaining follower nodes requires additional resources, including storage, processing power, and memory, which can increase system costs.
- Possible impact on write performance: Follower reads can impact the performance of write operations because followers require time to synchronise with the leader and update their data.
In summary, follower reads in CockroachDB can improve read performance, scalability, availability, and consistency but can also increase replication traffic, resource utilisation, and potential data staleness.
It is essential to carefully consider the trade-offs and design a system that balances the benefits and costs of follower reads to achieve the desired performance and reliability characteristics.
At Cockroach Labs we are alway available to answer your queries and see how our database can benefit your business and save you money. Go on! reach out, it could be the best thing you ever do!
Where do follower reads come in handy?
Follower reads in CockroachDB can be beneficial in several scenarios. Here are a few examples:
- Read-heavy workloads: Follower reads are particularly useful in read-heavy workloads, where the majority of requests are read operations. Offloading these read requests to followers can improve overall system performance and scalability.
- High availability requirements: Follower reads can help ensure high availability of data in CockroachDB. If the leader becomes unavailable, follower nodes can serve read requests and elect a new leader, ensuring that data remains accessible to clients.
- Geographically distributed deployments: In geographically distributed deployments, follower reads can improve read performance by allowing clients to read data from nodes closer to their location, reducing network latency.
- Cost optimisation: Follower reads can help reduce costs in CockroachDB by offloading read requests to less expensive follower nodes, while the leader node focuses on handling more expensive write requests.
- Analytics workloads: Follower reads can be useful in analytics workloads, where clients need to perform complex read queries on large data sets. Follower nodes can handle these queries, reducing the load on the leader and improving overall system performance.
Thanks for reading. Have a great day!