Search code examples
iosamazon-dynamodb

How to use DynamoDB table to create friends in iOS application?


I am trying to create an application like Facebook where people can become friends with one another. I want to be able to use DynamoDB to create these relationships. From what I have seen online people think that the relationship should look like this:

    userid  friendid

      1       2

      1       3

      2       3

I got this but in dynamoDB you can't repeat the userID in the table, so I am looking for other methods. If anyone can help in any way I would really appreciate it, because I am struggling to understand the concept.


Solution

  • There are two ways you can achieve this

    • Make userId as Hash and friendId as Range : By this method you will be able to store all the friends of particular user, With data grows if your users have 1000 friends than you will fetch 1000 records at a time for single user.
    • Design table with userId as Hash and for FriendId use set/list/map data type. Advantage of this would be that you will consume only 1 read per user and get all the friendIds in one go.

    This is very abstract level, try to think all the functionalities that you need to provide in the app and design tables accordingly.