Causal Reads

Overview

Causal reads guarantee that read-only queries on replica servers still return the most current data, even if the replica server is lagging behind the primary server.

In some multi-node deployments, causal reads are always available. For example, MariaDB Xpand replicates data in a strongly consistent manner, so all queries on all nodes will return the most current data.

In some other multi-node deployments, read-only queries executed on replica servers can return stale data due to replication lag if the queries are not executed in a causally consistent manner. Causal consistency is the act of ensuring that interdependent operations maintain consistency by performing them in the same order on all servers. When causal consistency is applied to read-only operations, the operation is typically called a "causal read."

MariaDB database products have many different ways to implement causal reads, depending on the specific components and technologies involved:

Multi-Node Implementation

MaxScale Component

Enabling Causal Reads

MariaDB Replication

Read/Write Split Router (readwritesplit)

MaxScale's Read/Write Split Router (readwritesplit) has a built-in option to enable causal reads for MariaDB Replication. For more information, see Ensuring Causal Consistency with MaxScale's Read/Write Split Router.

Galera Cluster

Any

Galera Cluster supports causal reads. To enable it, set the wsrep_sync_wait system variable to 1. Its default value is 0.

MariaDB Xpand

Any

MariaDB Xpand executes read-only queries in a causally consistent manner by design, so no configuration is necessary to enable causal reads.

Any

Consistent Critical Read Filter (ccrfilter)

MaxScale's Consistent Critical Read Filter (ccrfilter) can be used to enable causal reads when it is used in tandem with MaxScale's Hint Filter (hintfilter), and any of MaxScale's routers that supports routing hints, like Read/Write Split Router (readwritesplit) and Hint Router (hintrouter).