What is a database transaction, and what do the letters in ACID mean? Give an example where you need one.
What the interviewer wants to hear
- A transaction groups several operations into one unit of work
- Atomicity: all or nothing; Consistency: constraints hold
- Isolation: concurrent transactions do not see each other's partial work
- Durability: committed data survives crashes
- Concrete example such as a money transfer or order plus stock update
Model answer
A transaction is a group of database operations that succeed or fail together. ACID describes its guarantees. Atomicity means all or nothing: if anything fails, the whole transaction rolls back. Consistency means the database moves from one valid state to another, so constraints like foreign keys and unique keys still hold. Isolation means concurrent transactions do not see each other's half-finished work; the isolation level, such as read committed or serializable, controls how strict that is. Durability means that once COMMIT returns, the data survives a crash, usually thanks to a write-ahead log. A classic example is a bank transfer: debiting one account and crediting another must happen together, or money disappears. Another is placing an order, where I insert the order rows and decrease stock in one transaction so they never disagree.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Backend Developer questions
- How would you design a REST API for a simple blog with posts and comments? Mention URLs, methods and status codes.
- When would you choose a SQL database and when a NoSQL database?
- What is the difference between authentication and authorization? How would you implement both in an API?
- Explain what happens on the backend from the moment a request hits your server until a response is sent.
- What is a database index, and what are its costs? How do you decide which columns to index?
- What are logs, metrics and traces, and how would you use each one to run a backend service?
- How would you test a new POST /orders endpoint? Which kinds of tests would you write?
- Why do backend teams package services with Docker, and what makes a good Dockerfile?
- Explain the HTTP status code classes and give examples of codes a REST API commonly returns.