DEV Community

Sri Mahalakshmi
Sri Mahalakshmi

Posted on

Ensuring Durability in a Digital Wallet System Using PostgreSQL


In digital wallet applications, once a transaction is completed, users expect it to remain saved even if the system crashes or restarts. This requirement is handled by the durability property in database systems.

To understand this, I performed a simple experiment using PostgreSQL.

First, I created an accounts table and inserted two users: Alice with a balance of 1000 and Bob with a balance of 500. This represented the initial state of the system.

Then, I performed a transaction to transfer 200 from Alice to Bob. Inside the transaction, 200 was deducted from Alice’s balance and added to Bob’s balance. After executing these operations, I committed the transaction. Once committed, the updated balances became 800 for Alice and 700 for Bob.

To simulate a system restart, I closed the database session and reconnected again. After reconnecting, I checked the account balances using a select query. The balances remained unchanged at 800 and 700.

This shows that once a transaction is committed, the changes are permanently stored in the database and are not lost, even after a restart. This property is known as durability.

If a failure occurs before the commit, the changes will not be saved. But if the failure happens after the commit, the data remains safe and consistent.

This experiment demonstrates how databases ensure reliability in real-world applications like digital payment systems, where maintaining correct and permanent transaction data is essential.

Top comments (0)