ACID: The four guarantees a transactional database gives: Atomicity, Consistency, Isolation, Durability. ACID describes four guarantees of database transactions. Atomicity means all changes in a transaction happen, or none do. Consistency means rules such as foreign keys and constraints hold afterwards. Isolation means parallel transactions do not see each other's unfinished work. Durability means committed data survives a crash.
The standard example is a bank transfer. Money leaves one account and arrives in another. If the system crashes halfway, atomicity ensures you do not end up with money that vanished.
What should you keep in mind with ACID?
In application code, use a transaction whenever several writes belong together, such as creating an order and its order lines. In Laravel that is DB::transaction(function () { ... }). If any step throws an exception, everything is rolled back. Keep transactions short, though, because long ones hold locks and slow down everyone else.
What does an example of ACID look like?
-- Atomic: both or neither BEGIN; UPDATE accounts SET bal = bal - 100 WHERE id = 1; UPDATE accounts SET bal = bal + 100 WHERE id = 2; COMMIT;
Use when code runs things at the same time - threads, async/await, queues and workers, parallel requests, cron jobs, webhooks that retry - or when a bug only happens "sometimes" or under load. Covers race conditions, deadlocks, mutexes/locks, atomic operations, idempotency, message queues and backpressure, with Laravel and database examples.
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.