architecture

0xclj 2020-10-23T06:39:10.018500Z

I’m working on designing a notification system that supports “Reply by Email” similar to: • https://github.blog/2011-03-10-reply-to-comments-from-emailhttps://docs.gitlab.com/ee/administration/reply_by_email.html I’m not quite able to find any relevant resource/articles that talk about its architecture. Rails has Action Mailbox that assists in this but what I’m working on would be a purely Clojure implementation. Does anyone have any pointers on this?

2020-10-23T07:21:40.019400Z

HI @mail.acharyarahul.now, we have been running a similar thing using: https://postmarkapp.com it’s pretty solid and price is very reasonable.

2020-10-23T07:25:36.020600Z

here you can find detail documentation and some examples https://postmarkapp.com/developer/user-guide/inbound/parse-an-email

0xclj 2020-10-23T08:12:36.020800Z

Hi @jmayaalv, was checking out https://sendgrid.com/docs/for-developers/parsing-email/setting-up-the-inbound-parse-webhook/#other-inbound-parse-documentation, will check out Postmark APIs as well, Thanks. I actually wanted to discuss the architecture of the notification system of which this is a small part. I missed out on explaining that. Here’re the details: Say there’s a list which has items and multiple people can act on the list. Upon any update on the shared list, all other participants should be notified of it (like how the Github PR comment works). And anyone in the shared list should be able to respond to that email and it’d trigger an action (like posting the Github comment) and that in turn updates the list and sends out emails again. I’d like to discuss the system design for this.

0xclj 2020-10-23T08:33:09.021200Z

0xclj 2020-10-26T07:24:29.030800Z

> useful building block for dispatch Where and when would you recommend implementing this? weavejester/intentions ~ It’s not under active development though, not sure if that’s something to think about - seen a lot of Clojure libraries that are abandoned before they make it to 1.0.0

2020-10-27T15:47:25.031200Z

A lot of Clojure libraries work fine and require no further patching 🙂 Intentions is not a framework or something. It is one useful construct. It is tested, it works. There is hardly ever any breaking change in anything clojure. Also, Semver is not very popular in clojure, largely because breaking changes are uncommon. Many projects follow a Major.Minor.CommitCount numbering, where Major.Minor bumping is an indication of the amount of new things or changed things.

1
2020-10-27T15:52:40.031400Z

W.r.t. to multimethods, for instance for your problem of sending notifications, imagine that a notification looks like { :notification/content "bla bla" :notification/title "Bla." :notification/href "<https://mything.com/actions/dealwithbla?uuid=blabla123>" :notification/recipient-id some-user-uuid-here :notification/channel :notification.channel/sms } . You can write (defn send-notification [notification] ...) with a big case or cond based on the value associated to the :notification/channel key. Or you can (defmulti send-notification :notification/channel) and then (defmethod send-notification :notification.channel/sms) . More examples at https://clojuredocs.org/clojure.core/defmulti

2020-10-27T15:56:59.031600Z

Supporting several channels can be tacked on top of it without changing the single-channel schema. Say you expand your notification schema to have :notification/channels (plural) on a notification map. You can then use any looping construct. A for would be clear enough to me - some people would prefer reduce . Would look like (defn emit-all-channels-of-notification [notification] (for [ch (:notification/channels notification)] (send-notification (assoc notification :notification/channel ch)))) .

0xclj 2020-10-29T04:49:36.034200Z

Interesting, I’ve not yet dived into the details of code-implementation yet but this does give me stellar pointers on how to go about it when I do. multimethods are cool! Thanks a lot for the clear and consie explanations @zor, appreciate it 😄

2020-10-29T15:59:48.034600Z

You're welcome 🙂 I was hoping to be corrected in my shortcomings by someone - you know what they say about being wrong on the Internet right - but ... apparently I'm saying consensual stuff here.

😅 1
2020-10-23T11:50:40.021300Z

How do you see yourself solving this ? What does your current design look like ?

0xclj 2020-10-23T11:57:59.021600Z

Hey @zor, here’s the design I’ve come up with:

Notes:
ECS = Email communication System.
Using sendgrid as an example Email Service Provider.

- Have color coded the flow. ECS has two parts, appropriate path would be chosen based on the event of send or receive.
- Send Email flow begins by reading data from `UpdateList` Topic. (Follow Blue)
- Receive Email flow begins by receiving Webhook callback (Sendgrid). (Follow Orange)

2020-10-23T12:03:38.022Z

What does ECS stand for here ? Entity-Component-System ?

0xclj 2020-10-23T12:10:58.022200Z

ECS = Email communication System. 

It's the name of the Notification system I'm designing. Currently focused on email but would be later extended to include SMS/Push.
Basically the send-email email and reply-to email parts(the blue and orange box) would be under this but which is to be picked, is decided dynamically, thus 2 flows(arrows) indicating the possible paths.

0xclj 2020-10-23T12:25:48.022400Z

The blue flow: I’ll have a consumer/subscriber subscribed to UpdateList Topic. So any new message that comes (as “Update Message”) will then be immediately stored in the database, then the db-id will be sent to the background worker. The background worker will fetch the record from the db and resolve the necessary details like the list info, thread meta, email template and the email address. Once the data is processed, the processed data would then be stored in the db again. It’d then send the email to other subscribers/recipients using Sendgrid* API and the response would be stored in the db. The orange flow: Once the email is responded to, it’ll hit the Sendgrid* Inbound parser webhook and will send the callback response to ECS. The callback response payload will be stored in the DB and then the db-id will be sent to the background worker. The background worker will then resolve the list-info and will publish a new message to the UpdateList topic. Which will cause re-sending of the email notification to the rest of the subscribers.

1
2020-10-23T12:37:43.022700Z

I would separate the inbound (webhook that happens to be hit by sendgrid inbound service) from the outbound (sendgrid API) in that diagram. When you say, later extensible to SMS/Push, you probably mean you intend to have more outbound channels. Once we do that we notice that the flow becomes pretty much unidirectional, looking like :inbound -&gt; (store-inbound) -&gt; :queue-a -&gt; (handle-inbound-and-prep-outbound) -&gt; :queue-b -&gt; (send-outbound) -&gt; :outbound.

0xclj 2020-10-23T12:58:51.023100Z

> When you say, later extensible to SMS/Push, you probably mean you intend to have more outbound channels. Yeah, that’s right. > Once we do that we notice that the flow becomes pretty much unidirectional, looking like `:inbound -> (store-inbound) -> :queue-a -> (handle-inbound-and-prep-outbound) -> :queue-b -> (send-outbound) -> :outbound`. The intend is to have multiple selectable outbounds later. So yeah, it makes sense to separate it.

0xclj 2020-10-23T13:01:29.023300Z

Thanks!

2020-10-23T13:27:33.023500Z

multimethods are a useful building block for dispatch. (and their combining cousin, weavejester/intentions (on GitHub))

👍 1
😀 1