WHOATEMYNOODLES
WHOATEMYNOODLES

Reputation: 897

How would I store a user following/followers table?

Right now I'm using dynamodb for a chat application where a user joins a room and they would see everyone else's messages.

How would I structure my table? My primary key is the room's id, but I am unsure how I would structure the users inside the chatroom for this table.

Making the user's uuid as a key with a boolean seems incorrect -

"6d5e2ce1-cfc7-4722-ae35-c7dfd24c1e94" : true

Upvotes: 1

Views: 219

Answers (1)

Horatiu Jeflea
Horatiu Jeflea

Reputation: 7414

Considering you are storing in a RoomActivity table just user data, not actual chat messages, I would go with:

RoomActivity
------
roomActivityId (hash key, uuid)
roomId (gsi, uuid)
userId (gsi, uuid)
joinedDate (timestamp)
status (enum - JOINED, LEFT,...)

where User and Room are separate tables containing specific data about them.


I would personally have a new entry for every status change and considering in my code only the latest entry (by timestamp), but you can also update the status directly.

If you want to get all users from a room, use the roomId index.

If you want to get all rooms of a user, use userId index.

Upvotes: 2

Related Questions