# Transactional Client

> Send messages as part of a DB transaction — both commit or both roll back.

- **Category**: Integration
- **Subcategory**: Messaging Endpoints
- **Canonical URL**: https://designpattern.fyi/patterns/transactional_client/

---

## Description
Clean, reusable architecture pattern.


## Use Cases
Order Service updates order status to CONFIRMED in the DB and sends an OrderConfirmed message to the broker — both in one transaction. If anything fails, the rollback undoes both. No orphaned messages, no silent data inconsistency.





## Trade-offs


### Advantages

- Atomic consistency between state change and message publishing

- No dual-write problem — one transaction governs both

- Prevents orphaned messages (message sent but DB write failed)

- Prevents lost messages (DB write succeeded but message never sent)




### Considerations & Drawbacks

- True distributed transactions (XA) are slow and operationally complex

- Transactional Outbox is the preferred modern alternative — adds its own complexity

- Not all brokers support transactional message sending

- Performance overhead from transaction coordination







---
**Reference**: [Original Source](https://www.enterpriseintegrationpatterns.com/patterns/messaging/TransactionalClient.html)

