Skip to content

How to use transaction through multiple services? #22

Answered by benbjohnson
maxinmos asked this question in Q&A
Discussion options

You must be logged in to vote

Good question. I typically make my service methods implement a transactional boundary so that I don't need to share the transaction outside of it. In the example you have, you don't have a shared transaction as the fileStorageService isn't likely transactional (assuming it's disk-backed or S3-backed). You can end up with the file on your storage service but your CreateUser() could fail.

You could model your Tx inside your application domain but that assumes that all your services that use myapp.Tx are transactional. Transactions really only make sense within a single service (e.g. a sqlite layer) as you can't easily implement transactions across multiple layers or implementations.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@maxinmos
Comment options

@benbjohnson
Comment options

@maxinmos
Comment options

Answer selected by benbjohnson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants