NestJS · Senior · Question 23 of 75
How do you keep transactions consistent across several services in one request without passing a transaction object everywhere?
- ✓Correct answer: Store the transaction (or entity manager) in ALS and have repositories pick it up, e.g. with
@nestjs-cls/transactional - 2Open a separate transaction in each service
- 3Use request-scoped repositories for every entity
Explanation
ALS keeps the transaction bound to the async flow of the request, so nested service calls join it.