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 THIS TESTS: 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.
A GOOD ANSWER COVERS: 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.
COMMON WRONG ANSWERS: 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.
LIKELY FOLLOW-UPS: 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.
ONE 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.
Source: developer.mozilla.org
Read the original → developer.mozilla.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.