Want to speed up your reads?

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?

Pros:

  1. 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.
  2. Increased scalability: By offloading read requests to follower nodes, the leader node can focus on handling write requests, improving overall system scalability.
  3. Higher availability: Followers can serve as failover targets in case the leader becomes unavailable, ensuring high availability of data.
  4. Consistent reads: Followers read from a consistent snapshot of the data, ensuring that clients receive the most up-to-date data.

Cons:

  1. Increased replication traffic: Follower reads require additional replication traffic, which can increase network traffic and affect system performance.
  2. 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.
  3. Higher resource utilisation: Maintaining follower nodes requires additional resources, including storage, processing power, and memory, which can increase system costs.
  4. 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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!