Making eventual consistency less shit !!
Reading your own writes:
- Let’s say I write to the DB and read from the replica, I might get inconsistent result if the data is not propagated to the DBs.
- To solve this
- We can read from the same DB.
- In case we’re reading from a replica, we can ask the DB if data from the particular timestamp is synced or not before reading from that replica.
- On the right, Data replication is implemented using Versioning and Timestamps(to know more read below).
Monotonic reads:
Monotonic reads are particularly relevant in distributed systems with data replication, where data is copied and maintained across multiple nodes. Here’s how monotonic reads can be implemented:
-
Versioning and Timestamps: Each data item can be versioned or timestamped. When a process reads a data item, it records the version or timestamp. Subsequent reads ensure they only return the same or newer versions.
-
Client-side Caching: Clients can cache the latest version of data items they have read. Any future read requests first check the cached version to ensure monotonicity.
-
Read Repair Mechanisms: During a read operation, if a node detects that it has an older version of the data item compared to the version the client has already seen, it can initiate a read repair process to fetch and return the latest version from other nodes.
Consistent prefix reads:
Consistent Prefix Reads is a consistency model in distributed databases that ensures all read operations see writes in a sequential order. In other words, if a series of writes (A, B, C) are made to a database, a read will see either A, A-B, or A-B-C, but never A-C or B-C. This model guarantees the order of operations but does not necessarily provide the most recent data immediately.
Use Cases
- E-commerce Applications: Ensuring order consistency in updates like price changes, stock updates, and product descriptions.
- Social Media Platforms: Ensuring posts and comments appear in the correct sequence across different regions.
- Collaborative Tools: Ensuring document edits are seen in the correct order, even if not all edits are immediately visible.