【问题标题】:Batching up notificationsBatching up notifications
【发布时间】:2022-12-27 20:06:42
【问题描述】:

I have a simple chat messaging system where users can send one-on-one messages to each other. It uses SignalR to send chat messages, and then the messages are stored in a database in this format:

SenderId | RecipientId | Message | SentDateTime | RecipientHasRead

Currently, when a userA sends a message to userB, the SignalR service immediately sends a push notification to userB at the same time as saving the message to the datbase.

UserB can then get overloaded with lots of notification. I need some way to batch the notifications.

For example, currently User B will get the following notifications:

10:00am: User A has sent you a new message 10:01am: User A has sent you a new message 10:01am: User A has sent you a new message 10:01am: User C has sent you a new message

I would prefer that User B will get something like this:

10:01am: You have 4 unread messages

What are some techniques to implement this? Should I just run a job every 5 minutes to check un-read messages for a given user in the past 5 mins and send that out?

【问题讨论】:

  • It sounds like you are sending a message to the user that they have X unread messages every time they get a message. Rather than sending a message, why not have a counter that just increments and displays how many messages they have. That could be updated whenever a message is sent and counting the messages in the table.

标签: push-notification notifications signalr


【解决方案1】:

Notification batching could be implemented in several ways. One is time-based batching where you have a specified batch window and during this time you keep the notifications in a batch, and then after that, you count the number of batched notifications and deliver.

For this, you could implement an in-memory store like Redis list for a batch and keep pushing into the batch for the specified window period. At Engagespot, we do a sophisticated version of this technique.

【讨论】:

    猜你喜欢
    • 2023-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多