Designing a Notifications table

i need basically a notification table, app is similar to slack in design, create a notification when a user posts a message to a channel, whenever somebody reacts to a message, follow, etc im having trouble grouping/batching notifications. if 100 people like a message, i dont want to create 100 rows, it would be more efficient to just send a number with the context, but im not sure how to do this because you cant use a counter in a non-counter table. any pointers?

but im not sure how to do this because you cant use a counter in a non-counter table. any pointers?

The answer is to denormalize, you hold the likes for posts under a single/separate table. Although, if I am following you correctly, a “Slack” type of app would allow for multiple different types of reactions. So rather than a likes table, why not a reactions_by_message where you store each reaction separately and then simply count to retrieve the grand total?

This could also work with UDTs/collections considering they don’t get too big.

wouldn’t this require a batch read though? i read that those are to be avoided generally. so say i pull 8 messages via a group_chat_id, thats just one query, but to now get the reaction counts for each reaction on the message, i have to extract each message_id and do a batch read request

also ive gotten conflicting advice on this, ive also been told to just increment a count with LWT’s directly on the message

You will probably pull messages within a specific timestamp, as a chat app is really a sliding window of event. That allows you to concurrently and efficiently avoid large partitions when a specific group_chat_id becomes popular or subject to spams.

If you use UDTs or collections to store the reactions along each message, then the job is done and you should have everything you need going forward.

If you decide to store it under a different table, you would probably also read the same group_chat_id and time-window, which would retrieve you the reactions for each message you stored upfront.

also ive gotten conflicting advice on this, ive also been told to just increment a count with LWT’s directly on the message

Seems like an overkill for a chatapp which can tolerate eventual consistency - though I’d pick and choose whatever approach works best for the scale you’re after.

2 Likes

this was very helpful thank you for replying

on a side note what are your thoughts on batch reads in general? the idea of extracting relevant ids after querying one partition, and then using those ids to batch get another set of information from another partition? the most important thing ive noted so far is that ideally you should only every query one partition at a time