Interview › Databases & Caching
What is a transaction, and what do the ACID properties mean?
Databases & Caching · Intermediate level
Answer
A transaction is an all-or-nothing unit of work. ACID means Atomicity, Consistency, Isolation, and Durability: the database commits complete valid changes, controls concurrency, and preserves committed data across crashes.
Technical explanation
Stronger isolation can improve correctness but may increase blocking or retry requirements.
Deadlocks are handled by aborting a victim transaction; the application must retry the whole transaction safely.
Short transactions, consistent lock ordering, proper indexes, and idempotent retry logic are essential.
Hands-on example
Safe transfer example:
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT id FROM accounts WHERE id IN (1,2) ORDER BY id FOR UPDATE;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;On serialization failure or deadlock, retry the whole transaction, not just one statement.
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Databases & Caching interview questions
- What is WAL (write-ahead logging), and how does it support durability and replication?
- What is AWS DMS, and when would you use it?
- What is schema migration, and how do you run migrations safely in production?
- What is a deadlock, and how do databases detect and resolve them?
- What is connection exhaustion, and how do you prevent it?
- What is ElastiCache, and what does it manage?
- What is the difference between ElastiCache Redis and Memcached?
- What is Redis, and what core data types does it support?