How to choose a partition key in DynamoDB for a chat app

前端 未结 1 900
滥情空心
滥情空心 2021-01-24 12:22

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

相关标签:
1条回答
  • 2021-01-24 12:31

    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:

    • if your app write/read thousands of msges per day, so you wont get many partitions (depends also on you data size).

    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.

    0 讨论(0)
提交回复
热议问题