DynamoDB table design for notifications

0 votes

Technologies used: AWS, Lambda, DynamoDB, Python.

I am not very experienced in DynamoDB/NoSQL and my case is the following:

  1. I need to store messages sent to users, each user (identified by user_id) can have multiple messages (identified by message_id).
  2. I need to send a notification to the user about all his/her messages stored in the table.
  3. Notifications need to be sent at a specified time based on the user setting.
  4. Users can have multiple notification times set - this is not limited, so one user may want to be notified once a day for example at noon and the other user may want to be notified for ex. 4 times a day (ex. 7.15, 11:00, 15:00 and 18:00), full flexibility here is preferred.

There will be a lambda running every couple of minutes to get the messages that I need to notify the users about. Lambda "knows what time it is" and wants to get only messages from users who want to get their notifications at this point based on their preferences.

Current DynamodDB table design is the following: user_messages table - Primary Key (Partition Key: user_id, Sort Key: message_id), attributes: message_text, creation_time etc.

My struggle is - how to design the DB in an optimal way to limit the number of RCUs consumed and compute time on lambda when extracting those messages. It would be simpler if I'd allow each user to have only one notification time set. I'd just create a notification time attribute and a new GSI where the notification would be the partition key but this would limit the user too much.

I am not sure how to approach it in case of multiple notification times per user, got 2 possible scenarios now:

1. limit the notification setting time to N, for example, 3 max per user, store the preferences in 3 attributes and create 3 GSI's, in such case the lambda would query the table 3 times each run - this doesn't look elegant and I am concerned about the hard limit on the number of notifications.

The table design would look like this in such case: user_messages table - Primary Key (Partition Key: user_id, Sort Key: message_id), attributes: message_text, creation_time etc., GSI_1 (notfication_time_1), GSI_2 (notification_time_2), GSI_3 (notification_time_3).

2. create a separate table with user preferences, like Partition Key: notification_time, attribute: user_id

In such a case the lambda would have to get all user_id for a particular notification time and iterate over user_messages_table to get user messages, which means if I have 1000 users to notify I'd need to query user_messages_table 1000 times. Doesn't look good from the performance point of view and will consume a lot of RCUs.

I am stuck here as none of the above solutions seems optimal for me.

Do you see any other approach I could take here?

Apr 5, 2022 in Others by Kichu
• 19,050 points
306 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
0 answers
0 votes
0 answers

How to check if DynamoDB table exists?

I'm a new user in boto3 and ...READ MORE

Mar 14, 2022 in Others by Edureka
• 13,630 points
1,175 views
0 votes
0 answers

How is it possible for DynamoDB to support both Key-Value and Document database properties at the same time

As per DynamoDB's documentation, it supports both ...READ MORE

Apr 5, 2022 in Others by Kichu
• 19,050 points
270 views
0 votes
1 answer

How to generate the "create table" sql statement for an existing table in postgreSQL

Create a table for a demo: CREATE TABLE ...READ MORE

answered Jun 20, 2022 in Others by nisha
• 2,190 points
97 views
0 votes
1 answer

Find max and second max salary for a employee table MySQL

SELECT MAX(SALARY) FROM Employee WHERE SALARY < ...READ MORE

answered Nov 7, 2022 in Others by gaurav
• 22,960 points
181 views
0 votes
1 answer

Use Excel pivot table as data source for another Pivot Table

Press the keys Alt+D+P in a new ...READ MORE

answered Nov 11, 2022 in Others by narikkadan
• 53,920 points
597 views
0 votes
0 answers

To query Last 7 days data in DynamoDB

HashKey(Date) ,RangeKey(timestamp) This is what my dynamo DB ...READ MORE

Apr 9, 2022 in Others by Kichu
• 19,050 points
719 views
0 votes
0 answers

how to design db schema of an e-learning platform in dynamodb?

I am designing No-SQL DB schema for ...READ MORE

Apr 19, 2022 in AWS by Rahul
• 9,670 points
227 views
0 votes
1 answer

Amazon DynamoDB: warning

Yes, you should address this problem. You can ...READ MORE

answered Aug 30, 2018 in AWS by Priyaj
• 58,100 points
245 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP