InterviewHubPRO
Section Overview
Q54

Question 54 of 60

Part 5: Production Scale, Deployment & Observability (51 - 60)

90%
Node.js & Libuv•Part 5: Production Scale, Deployment & Observability (51 - 60)

The Outbox Pattern in Node.js.

In Simple Words: Write business state mutations and domain event payloads into an outbox database table within the same atomic database transaction. A separate background worker tails the outbox table and publishes events to RabbitMQ or Kafka.

typescript
await prisma.$transaction(async (tx) => {
  const order = await tx.order.create({ data: { userId, amount } });
  await tx.outbox.create({
    data: {
      eventType: 'ORDER_PLACED',
      payload: JSON.stringify(order)
    }
  });
});