I have a requirement to use DynamoDB for a chat app that will be used occasionally, on an event day. The app will be reading/writing few thousands of messages on a particular da
my first recommendation is to move to a proper db (like elasticsearch) that answer this usage (time based search) and create a new index for each day
but if still you want to use dynamodb, a good hack can be:
lets assume you are going to have 3 partitions. your keys can be like that:
HashKey: Event day name + 'part_X' (where x is a number between 1-5. it can be a round rubin, or some '%' on a user_id or something like that)
SortKey: Message timestamp
so in your case, to get last 20 comments: you should get 20 comments from each partition (hash = event_day_name_part_1, event_day_name_part_2 ..) and then get to top recent.