Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emailing in microservice architecture

Sorry about my english - if some thing is not clear please ask me in comments - i will clarify this.

I build system in microservice architecture. I have one service with user information, one service for "offers", and one service for "ideas". Services "offers" and "ideas" comunicate (by Restful API) with "User" service on login and other operations. And i wonder - how to deal with emails? Each service have it separate frontend and send emails after some actions (eg. when some third person open link with some offer the user who create this offer will get email, or when some user create idea the manager will get email). Moreover, on each service frontend, manager can create "periodic" mailing with season statistical data or just some other information. Each service email looks differently and have different content.

I have many choices and don't know which will be better. This are some propositions:

  1. Each service has his own separate emailing system and send all kinds of email (after action, and periodic) independent.
  2. The "user service" have "engine" to send action and periodic emails and other services give the task. Inside task there is link to service who give task and that link will generate email content (for example witch statistical data in periodic email). This solution is complicated...
  3. The "user service" has only engine to periodic emails (tasks have link to generate email body...) but email after actions are send from each microservice indepenndent
  4. Create new microservice only for sending email (periodic and "after action") with proper API. Ofcourse each service like "offers" should send also link (to themself) in mailing task - this link will be call when the periodic email will be send and the response of this link will be generated body of email....

Which one will be better? Or may be there is some better alternative?

like image 697
Kamil Kiełczewski Avatar asked Jan 02 '17 22:01

Kamil Kiełczewski


1 Answers

Sending emails it's like making request to another service (via SMTP). So, that's a good approach when every service will be able to send emails.

But, of course there's some common logic for sending emails like rendering templates, sending code, configurations and so on. This logic should be shared between services via common code (dll, package and so on).

So, in this way:

  1. Every service doesn't depend on another service when it needs to send an email
  2. Common code for sending email is shared between services
  3. You don't have development, deployment and network overheads in the case of having dedicated email sending serviced

One drawback of this approach is that every service should have the same email configuration (SMTP address, login, password and so on). But if you share configurations between all services it's not a problem.

like image 111
Vasyl Zv Avatar answered Sep 30 '22 04:09

Vasyl Zv