0

I'm reading through an article on why SQL databases are hard to scale and problems with ACID.

Here's the link to the short article: Link

Today's solution is usually post-write replication, where each transaction is executed first at some primary replica, and updates are propagated to other replicas after the fact. Basic master-slave/log-shipping replication is the simplest example of post-write replication, although other schemes which first execute each transaction at one of multiple possible masters fall under this category. In addition to the possibility of stale reads at slave replicas, these systems suffer a fundamental latency-durability-consistency tradeoff: either a primary replica waits to commit each transaction until receiving acknowledgement of sufficient replication, or it commits upon completing the transaction. In the latter case, either in-flight transactions are lost upon failure of the primary replica, threatening durability, or they are retrieved only after the failed node has recovered, while transactions executed on other replicas in the meantime threaten consistency in the event of a failure.

I'm assuming that by the former statement, it is pointing to the semi-synchronous replication and by latter it points to the asynchronous replication such that a commit is said to be successful as soon as the transaction is committed on the primary replica.

However, I didn't quite get what does it mean by losing the transaction upon failure and how are in-flight transactions lost in synchronous replication and not the semi-synchronous case? Can anyone help to explain?

Isn't a transaction saved to disk before it's being executed?

1 Answer 1

1

Isn't a transaction saved to disk before it's being executed?

With synchronous replication, new data in a transaction is:

  1. written to the transaction log,
  2. depending on the implementation, maybe also write to the data file,
  3. sent to the secondary system, which
  4. writes it to disk, and then
  5. sends an acknowledgement back to the primary.
  6. Only then does the primary COMMIT the data.
  7. If it wasn't written to the data file in step 2, it's written there now.

If the primary goes down, then the secondary system (which has the data) should be promoted to be the new primary. Thus, no data loss.

In the latter case, either in-flight transactions are lost upon failure of the primary replica, threatening durability, or they are retrieved only after the failed node has recovered, while transactions executed on other replicas in the meantime threaten consistency in the event of a failure.

That's the well-known trade-off of async replication.

2
  • Some clarifications: Shouldn't the 7th step come before the 6th one cuz. primary should only COMMIT the data only if it has the changes committed to the data file first? Also, In case of synchronous replication, suppose primary fails after the changes got acknowledged by the secondary system(but before ''COMMITted'' response is given back to the application), so when you promote a secondary replica, do you promote it with this new data or the old data cuz the primary/master still hasn't given back the ''COMMITted'' message back.
    – asn
    Apr 2 at 13:50
  • @ajaysinghnegi I'm sure this is all somewhere in the Postgresql docs.
    – RonJohn
    Apr 2 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.