I have a workflow that has an email form. The requirements are the following: A user completes the form that contains email fields and submits it. If everything goes well then an email model object is created and stored in the database, and then the data are sent to a rabbit queue. When the queue gets processed an email is generated (this is a different with html body and everything) and gets send to the SMTP server to send it and then another database model is created which I call note and gets stored in the database as well (this will appear as an action item in the history). If it fails at some point I rollback and put the message back to the queue for a retry.
The system is a preexisting one and I am required to add an email integration so if some stuff feel unnecessary or round about it's what me and the client have decided so I can't anything more about it and honestly in the larger context of the business they make sense.
As you can see there are a lot of stuff happening and I am bit unsure about where everything should happen and what concerns are grouped together. My initial thoughts are that there are two transactions. First the initial email db model. I feel like I should process the form and save it to the database and then send it to its merry way to the queue to be processed successfully hopefully at a later point. Then when the queue gets processed another transaction is happening - email html gets generated, sent to SMTP and if SMTP returns success then a note gets created and stored in the db and the transaction gets committed. Otherwise rollback, put it back in the queue, retry and after 3 retries put it in a dead letter queue.
I think that makes sense but I wanted to get another POV.