The cost of linearizable reads in distributed databases illustration

The cost of linearizable reads in distributed databases

Marco Bambini
Marco Bambini
2 min read
Nov 15, 2023

In the intricate world of distributed databases, achieving linearizable reads involves ensuring that when data is read from the database, users receive the most recent and accurate version. This concept is akin to having a single, cohesive copy of data seamlessly spread across an entire distributed system

Building a distributed database system is a delicate balance between efficiency and raw speed. SQLite Cloud is no exception. Leveraging the robust SQLite library and incorporating the Raft consensus algorithm, we aim to strike the right balance for optimal performance.

Upon sending a request to our cluster, our architecture intelligently identifies the closest node (with the lowest latency) to handle the request automatically. For instance, if you send a SELECT statement from Milan to a node in Paris, you can expect a latency of 10 to 30 milliseconds, assuming efficient network routes and minimal congestion.

Ensuring linearizable reads with the Raft consensus algorithm involves checking if the Raft log is up-to-date. If the selected node is a follower, a request to the leader node must be sent, incurring a latency cost directly proportional to the geographical distance.

If, for example, the leader node is in San Francisco, the latency can range from 100 to 150 milliseconds. While acceptable for some applications, it may be crucial for others to minimize this delay, particularly considering the cluster's topology.

void do_command (client_t *client) {
TimeAverage Time in ms
From Milan to Paris (RTT)20
From Paris to San Francisco (RTT)125
SQLite query time5

Recognizing that not all applications require the strict linearizable read constraint, SQLite Cloud provides the flexibility to disable this guarantee reducing the query time to an expected 25ms range.

This option can be disabled in the dashboard or with a custom command:


The do_command example:

void do_command (client_t *client) {
    if (client->guarantee_linearizable) check_linearizable();

In essence, the quest for linearizable reads in a distributed database environment involves weighing the benefits of strong consistency against the costs of increased coordination overhead, latency, scalability challenges, and system complexity.

SQLite Cloud offers the choice to tailor these considerations to the specific needs of your application, striking a balance between performance and consistency.

Real-Time Full-Text Site Search with SQLite FTS5 extension

How (and why) we brought SQLite to the Cloud

More Articles

Try it out today and experience the power of SQLite in the cloud.

Deploy Now
Subscribe to our newsletter
The latest news, articles, and resources, sent to your inbox.

© 2024 SQLite Cloud, Inc. All rights reserved.