Skip to content
RED SAGSkills
hard20 pts · first answer countstransactionsdatabase-performancearchitecture

Payment call inside a transaction

Under load this checkout starts failing with connection pool timeouts and lock waits, even though the queries themselves are fast. What is the main problem?

await prisma.$transaction(async (tx) => {
  const order = await tx.order.update({
    where: { id },
    data: { status: 'PAYING' },
  })
  await paymentProvider.charge(order.total)   // 300 ms to 5 s
  await emailService.sendReceipt(order.email) // 200 ms
  await tx.order.update({ where: { id }, data: { status: 'PAID' } })
})
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions