1

I understand transactions were developed to meet two requirements:

  1. Concurrent DB access
  2. Resilience to system failures

I understand how the concurrency issue is motivated; to overcome the database consistency problem.

However, I have a question: How do transactions help system resilience to failures?

Hannah Vernon
  • 70,041
  • 22
  • 171
  • 315

2 Answers2

2

If I understand your question, the "resilience to system failure" is handled by the server to ensure that the transaction either:

  1. Succeeds in committing the transaction.

Or:

  1. Ensures that a non-committed transaction rolls back to the previous state.

In other words, the transaction completes successfully or else (in a failure) all the in-flight changes are undone since the transaction is incomplete.

RLF
  • 14,015
  • 2
  • 33
  • 47
1

One common answer to this question is to examine how a bank transfer might work.

Transferring money from account A to account B will have at least two distinct processes:

Account A decreases total
Account B increases total

If the system were to fail after the first process completed, and each separate process committed the data, then account A would be decreased and account B wouldn't be increased. The money would be effectively "lost".

Wrapping this in a transaction means that both processes must succeed for the transaction to be committed. It is not possible for money to be "lost".

Phil Sumner
  • 1,867
  • 11
  • 13