电子邮件通知架构问题
我们正在寻求开发一种电子邮件通知服务,可以根据我们系统内发生的某些操作(用户注册)或每周五发送的摘要电子邮件,每天、每周或每小时安排电子邮件发送。
确保不发送重复电子邮件的最佳方法是什么?我们考虑过让应用程序在发生系统操作时将一条记录写入队列,但这似乎又存在一个故障点。或者也许只是让所有通知数据驱动,例如,选择创建日期大于现在的所有用户。但在这种情况下,我们需要一种方法来确保服务再次运行时不会发送重复的电子邮件..
任何想法都会很棒!
We are looking to develop an email notification service where emails can be scheduled daily, weekly, or hourly based on certain actions that happen within our system (User Registration) or summary emails sent every Friday for example.
What is the best way to handle making sure duplicate emails are not sent? We thought about maybe having the application write a record to a queue whenver a system action happens but this would seem to have one more point of failure. Or maybe just making all notifications data driven, for example, select all users where created on date is greater than now. But with this scenario we need a way to make sure if the service runs again duplicate emails are not sent..
any ideas would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的 2 美分
1) 队列。队列非常适合您希望拥有“单入口和单出口”架构类型的任务。队列解耦系统并允许您对系统进行负载平衡。它们通常与一端和另一端的多个工作人员一起使用。您只需将(可能很多)消息添加到队列中,然后运行批量出队。 IMO认为这是不合理的内存和资源消耗。
2) 通过用户数据驱动。实现起来容易得多,但是对于每个通知,您将检查每个用户,并且会给数据库带来沉重的负载。
3) 通过用户通知进行数据驱动。或者,您可以创建一个单独的表 UserNotifications,每个用户注册后都会添加到该表中。在给定的时间范围内选择所需的用户要容易得多,并且不需要将它们存储在内存中。发送通知后,您可以从 UserNotifications 表中删除该用户。
My 2 cents
1) Queues. Queues are great for the tasks where you want to have a 'single entry and single exit' type of architecture. Queues decouple the systems and allow you to load balance the system. They are usually used with the multiple workers on one and another end. You will just add (maybe a lot) of messages to the queue, and later run a bulk dequeue. IMO that is irrational memory and resource consumption.
2) Data-driven via Users. Much easier to implement, however for each notification you will check every user and will put heavy load on db.
3) Data-driven via UserNotifications. Alternatively, you can create a separate table UserNotifications, where each user will be added once he has registered. It is much easier to select the needed users within given time frame and you don't store them in memory. Once notification sent, you remove the user from UserNotifications table.