Prisma Interview Questions
Q: What is Prisma and how does it differ from other ORMs?
Prisma is a next-generation ORM for Node.js/TypeScript consisting of three tools: Prisma Client (auto-generated, type-safe query builder), Prisma Migrate (schema migration system), and Prisma Studio (GUI). Unlike ActiveRecord-style ORMs (TypeORM, Sequelize with class-based entities), Prisma generates a fully type-safe client from the schema — all queries return typed results with no casting needed.
Q: What is the difference between prisma migrate dev and prisma migrate deploy?
prisma migrate dev creates and applies new migrations in development — it also re-generates the Prisma Client and can reset the database. prisma migrate deploy only applies pending migrations in production — it never modifies the schema.prisma file or resets the database. Always use deploy in CI/CD pipelines.
Q: What is the difference between select and include?
include adds relation fields to the default result (all scalar fields + specified relations). select lets you explicitly choose which fields to return — more efficient as it only fetches what you specify. You cannot use both at the top level; within a nested include/select, you can use the other.
Q: How do you handle N+1 queries in Prisma?
Prisma prevents N+1 by batching relation queries automatically when using include. When you write include: { posts: true }, Prisma issues two queries (one for users, one for all their posts) and joins them in memory — not one query per user. For DataLoader-style batching in GraphQL, Prisma works well with graphql-dataloader.
Q: How do you handle soft deletes in Prisma?
// Add deletedAt to schema
model User {
deletedAt DateTime?
}
// Soft delete
await prisma.user.update({
where: { id: userId },
data: { deletedAt: new Date() },
});
// Always filter in queries (or use Prisma middleware)
prisma.$use(async (params, next) => {
if (params.model === 'User' && params.action === 'findMany') {
params.args.where = { ...params.args.where, deletedAt: null };
}
return next(params);
});Q: How do you paginate efficiently with Prisma?
// Offset pagination (simple but slow on large datasets)
const users = await prisma.user.findMany({ skip: page * limit, take: limit });
// Cursor pagination (fast, works with sorted data)
const users = await prisma.user.findMany({
take: 10,
cursor: { id: lastSeenId }, // start after this cursor
skip: 1, // skip the cursor itself
orderBy: { id: 'asc' },
});
// Return cursor for next page
const nextCursor = users.length === 10 ? users[9].id : null;Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free