What is ACID in Databases?

Listen to this Post

Featured Image
ACID is a foundational set of properties that ensure reliable transactions in relational databases.

🔹 A – Atomicity

→ Guarantees that all operations in a transaction are completed successfully or none are applied at all.

“All or nothing.”

🔹 C – Consistency

→ Ensures that a transaction brings the database from one valid state to another, maintaining integrity rules.

“No rule-breaking allowed.”

🔹 I – Isolation

→ Transactions execute independently. Intermediate states are not visible until the transaction is committed.

“No interference.”

🔹 D – Durability

→ Once a transaction is committed, its results persist even in the event of a system crash.

“Permanent and safe.”

You Should Know:

1. Atomicity in Action (SQL Example)

BEGIN TRANSACTION; 
UPDATE accounts SET balance = balance - 100 WHERE user_id = 1; 
UPDATE accounts SET balance = balance + 100 WHERE user_id = 2; 
-- If any step fails, ROLLBACK undoes all changes 
COMMIT; 

Linux Command (Using `sqlite3` for Testing):

sqlite3 test.db "BEGIN TRANSACTION; UPDATE accounts SET balance = balance - 100 WHERE user_id = 1; UPDATE accounts SET balance = balance + 100 WHERE user_id = 2; COMMIT;"

2. Ensuring Consistency (Constraints in SQL)

ALTER TABLE orders ADD CONSTRAINT fk_customer FOREIGN KEY (customer_id) REFERENCES customers(id); 

PostgreSQL Check:

psql -U postgres -c "\d orders"  Verifies foreign key constraints 

3. Isolation Levels (MySQL Example)

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; 
START TRANSACTION; 
SELECT  FROM transactions WHERE account_id = 1; 
-- Other transactions cannot modify until this completes 
COMMIT; 

Check Isolation Level in PostgreSQL:

psql -U postgres -c "SHOW default_transaction_isolation;" 

4. Durability via WAL (Write-Ahead Logging)

Enable WAL in PostgreSQL:

echo "wal_level = replica" >> /etc/postgresql/14/main/postgresql.conf 
systemctl restart postgresql 

Verify Durability in SQLite:

sqlite3 test.db "PRAGMA journal_mode=WAL;" 

5. ACID Compliance in NoSQL (MongoDB Example)

db.runCommand({ 
beginTransaction: 1, 
txnNumber: NumberLong(1), 
operations: [ 
{ op: "update", ns: "test.accounts", query: { user_id: 1 }, update: { $inc: { balance: -100 } } }, 
{ op: "update", ns: "test.accounts", query: { user_id: 2 }, update: { $inc: { balance: 100 } } } 
], 
commitTransaction: 1 
}); 

MongoDB Durability Check:

mongod --dbpath /data/db --journal  Enables journaling for crash recovery 

What Undercode Say:

ACID principles are critical for transactional integrity. In cybersecurity, databases without ACID compliance risk corruption, race conditions, and data breaches. Always enforce:
– Atomicity → Use `ROLLBACK` in SQL or compensating transactions in NoSQL.
– Consistency → Apply strict schema validation (CHECK constraints).
– Isolation → Test with `READ UNCOMMITTED` vs. SERIALIZABLE.
– Durability → Enable WAL, journaling, or replication (pg_basebackup in PostgreSQL).

Expected Output:

-- Atomicity test 
BEGIN; 
INSERT INTO logs (event) VALUES ('ACID Check'); 
ROLLBACK; -- Entry should NOT persist

-- Durability test 
BEGIN; 
INSERT INTO logs (event) VALUES ('Durability Passed'); 
COMMIT; 
-- Even after a crash, this log must exist 

Prediction:

As distributed databases grow, ACID will evolve with hybrid models (e.g., Google Spanner’s “External Consistency”). Expect stricter compliance in blockchain ledgers.

Relevant URL:

PostgreSQL ACID Compliance Docs

References:

Reported By: Aaronsimca What – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 Telegram