Databases, ORMs & Transactions Interview Questions (Node.js)
10 Databases, ORMs & Transactions questions from the Node.js track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Mid-level
How do database Connection Pools work, and what are the risks of exhausting them in Node.js?
A pool manages a set of pre-opened connections and shares them among requests; exhausting it queues requests and increases response times and timeouts.
Read the full explanation - Mid-level
How does Prisma ORM work in Node.js, and what role does its Query Engine / Query Compiler play?
Prisma generates a custom TypeScript client from schema.prisma and translates calls into SQL. It used to run through a Rust binary engine; recent versions (available since 6.16 and the default in Prisma 7) use a TypeScript Query Compiler with driver adapters and no Rust engine.
Read the full explanation - Senior
Compare Drizzle ORM and TypeORM in terms of architecture and performance in Node.js.
Drizzle is a lightweight, zero-overhead SQL-like query builder without binary engines, while TypeORM is a traditional ORM using the Data Mapper/Active Record patterns and relying on reflection and decorators.
Read the full explanation - Mid-level
How does Mongoose manage its MongoDB connection, and what is the role of command Buffering?
Mongoose provides an advanced ODM layer; Command Buffering lets model queries be issued before the initial connection is ready and queues them until the connection succeeds.
Read the full explanation - Junior
How do parameterized queries protect Node.js applications from SQL Injection?
Parameterized queries separate SQL code from data through placeholders ($1, ?); the database receives parameter values as literals that cannot be interpreted as code.
Read the full explanation - Senior
How do you safely implement Database Transactions and isolation levels in Node.js?
Reserve a specific client from the pool, run BEGIN and the operations, then COMMIT on success or ROLLBACK in a catch block.
Read the full explanation - Senior
What is the N+1 problem in database queries, and how does DataLoader solve it in Node.js?
It occurs when one main query is followed by N queries, one per record, to fetch related data; DataLoader batches and caches requests into a unified query.
Read the full explanation - Senior
How do you design query routing between a Primary database and Read Replicas?
Create two separate connection pools: one for the Primary for writes and transactions, and one for Replicas for reads with load balancing.
Read the full explanation - Senior
How do you perform Database Migrations without service downtime (Zero-Downtime)?
Follow the Expand and Contract pattern so the database schema supports both the old and new application code during deployment.
Read the full explanation - Senior
How do you implement Distributed Locks with Redis across multiple Node.js servers?
Use SET with NX and PX options to store a random token with a timeout, and release the lock with a Lua script that verifies the token.
Read the full explanation