Dynamodb Data modeling

0

Hey there i am new at dynamoDB. I am a bit confused regarding 1 to Many relation and data duplication in dynamodDB. i have search in documentaion regarding data modeling there i found social media example of data modeling example following is the screen shot i have attaced . Enter image description here.. So according to the example in the red mark the PK is userId i.e u#12345#following and the user who are following is in the SK. So if you want to getFollowerListByUserID so to get a list of users who are following a given user, we'll need to Query the base table with a key condition of PK=<userID>#follower. By this example we can get list of all users id who are following u#12345. but on the real world scenario we not only want the id we also want data also . like follower name, image, profile data like all these thing to show on frontend side. but on this example there is no data attached of followers. if i also attached the data on the follower items then there would be data duplication around every item user is following some one. and if user update his data he also need to update data on every follower item.

preguntada hace 8 meses299 visualizaciones
1 Respuesta
1
Respuesta aceptada

To avoid data duplication, you first Query the list of users. From the list returned, you then do a BatchGetItem which can return you up to 100 followers profile information per request. Then you lazily load this, so get 100 and populate your dashboard. If the user scrolls past 80 users, fetch the next 100 in the list and continue paging as much as the user scrolls.

profile pictureAWS
EXPERTO
respondido hace 8 meses
  • ok lets just say if a user has 5000 followers . then i am going fetch all list of followeres data by calling batchGetItem 50 time am i right?

  • Correct, but you only call the batchget when needed. You wouldn't load all 5000 items in one go.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas