Performance: Transactions
MEDIUM IMPACT
Transactions affect the backend response time and can indirectly impact frontend loading and interaction speed by delaying data availability.
await dataSource.transaction(async (manager) => { await manager.update(User, { id: userId }, data1); await manager.update(Order, { id: orderId }, data2); await manager.update(Payment, { id: paymentId }, data3); });
async function updateUserData(userId, orderId, paymentId, data1, data2, data3) { await userRepository.update({ id: userId }, data1); await orderRepository.update({ id: orderId }, data2); await paymentRepository.update({ id: paymentId }, data3); }
| Pattern | DB Calls | Transaction Overhead | Response Delay | Verdict |
|---|---|---|---|---|
| Multiple separate DB calls | 3 separate calls | None | High latency due to multiple round-trips | [X] Bad |
| Single transaction wrapping all calls | 1 transaction with 3 operations | Minimal overhead | Lower latency, atomic update | [OK] Good |