Explain IndexedDB transactions and readonly vs readwrite modes

Understanding of IndexedDB's transactional model and concurrency.
Every operation needs a transaction; readonly allows concurrent readers, readwrite is exclusive; they auto-commit when idle.
What's really being asked
This question probes whether you understand that IndexedDB is built on a transactional database model rather than a simple key-value getter or setter. The interviewer wants to see if you know why every operation requires a transaction, how the API prevents race conditions between tabs, and whether you can contrast shared and exclusive access modes. Senior candidates should demonstrate awareness of transaction lifetimes, auto-commit behavior, and the implications of readwrite exclusivity on application throughput.
The full answer
First, state that every operation in IndexedDB always happens in the context of a transaction and you cannot execute commands or open cursors outside of one. Second, explain that readonly transactions allow multiple concurrent transactions to access the same object store simultaneously, which improves read throughput, while readwrite transactions acquire exclusive access to the stores in their scope and block other readwrite transactions. Third, mention that transactions have a well-defined lifetime and auto-commit when no new requests are made and the event loop clears, so attempting to use a transaction after it has completed throws exceptions. Fourth, connect this to the multi-tab scenario where without transactional operations, two app instances could interfere with each other's modifications.
The mistakes people make
A red flag is comparing IndexedDB to localStorage or a synchronous map and omitting the transaction requirement entirely. Another mistake is saying readonly and readwrite differ only in permission level without discussing concurrency; the interviewer cares about the locking model, not just mutability. Claiming that transactions are optional or that you can reuse a transaction indefinitely also signals a fundamental misunderstanding. Finally, confusing transaction scope with database versioning or suggesting that readwrite transactions can run concurrently on the same store will hurt your credibility.
What usually comes next
The interviewer might ask how you would handle a long-running readwrite transaction without blocking the UI, or what happens when two tabs try to upgrade the database version simultaneously. They could also ask about the difference between a transaction on multiple object stores versus a single store, or how error handling and abort work inside a transaction. Be ready to discuss whether readonly transactions ever block each other and how IndexedDB handles transaction scheduling in practice.
A concrete example
Imagine a dashboard that reads a large list of messages from an object store and occasionally marks one as read. You would open a readonly transaction to populate the list, allowing the user to scroll without blocking other reads. When the user clicks to mark a message as read, you open a separate readwrite transaction on the same store, which queues behind any existing readonly transactions and then executes exclusively to update that record. If you tried to reuse the original readonly transaction for the write, the API would throw because the transaction was readonly or already completed.
Interview question
In IndexedDB, how do readonly and readwrite transactions interact when accessing the same object store concurrently?
- a.Only one transaction of any mode can access a given object store at a time
- b.Multiple readonly transactions can run concurrently, but a readwrite transaction waits to execute exclusivelyCorrect
- c.All transactions run simultaneously because IndexedDB does not lock stores
- d.Readwrite transactions preempt readonly ones and run immediately
Why? this is the answer
Readonly transactions allow concurrent access to the same object store, while readwrite transactions acquire exclusive access and queue behind existing readers. Distractor D is wrong because readonly transactions do not block each other; exclusivity applies only to readwrite transactions.
Just read this? Test yourself on what you have been reading.
Read the original → developer.mozilla.org
- #indexeddb
- #transactions
- #web storage
- #browser apis
- #concurrency
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles