Choice PK and SK in DynamoDB

0 votes

I have the following two items which I need to store in dynamodb

  • Artists

  • Songs

The artists have an ID (unique for artists), name and gender. The Songs have an ID (unique for songs), title, genre, artist and rating.

How should I model this in DynamoDB?.

I was thinking about this: ID as the primary key and having a sort key that contains the artist or song so they are distinguished. Is this a good choice? For example, I find I see more variety in the sort key.

What about the field artist in song items? Should I just point to the ID of the artist?

Apr 12, 2022 in IoT (Internet of Things) by Rahul
• 9,680 points
804 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

One thing I found out (the hard way) about NoSQL (DynamoDB) modelling is that you need to know all your access patterns before you model your table. In an RDBMS, it's rather common to model first and optimize indexes later as access patterns change. This is not straightforward in NoSQL modelling (otherwise there would be massive migrations from RDBMS to NoSQL).

Having that said, I will now suggest a simplistic model and I will update my answer as the question is updated with access patterns (i.e. "I need to get all songs for an artist").

Artist:

PK: Artist-<Artist ID>, i.e. Artist-1234 SK: <Name> Attributes: Gender etc.

Song:

PK: Song-<Song ID>, i.e. Song-5678 SK: <Genre> Attributes: Genre, Artist ID, Rating

This approach will only allow you to get your entities by using their ID.

While it's common in NoSQL to de-normalize data (i.e. store artist data in song) for easiest/more efficient access, I'd go with storing the artist ID because it allows easier updates and better consistency.

answered Apr 13, 2022 by Aditya
• 7,680 points

edited Mar 5

Related Questions In IoT (Internet of Things)

0 votes
0 answers
0 votes
1 answer

How to get Unicast, Dns and Gateway Address in UWP?

Try this code Snippet I found here: https://social.msdn.microsoft.com/Forums/en-US/27a8b7a8-8071-4bc1-bbd4-e7c1fc2bd8d7/windows-10-iot-core-how-do-you-create-a-tcp-server-and-client?forum=WindowsIoT ...READ MORE

answered Jul 17, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,445 views
0 votes
1 answer

Finding the Unicast, DNS and Gateway Address in UWP

Try the PInvoke api methods from Iphlpapi.dll. ...READ MORE

answered Aug 20, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,022 views
0 votes
1 answer
0 votes
1 answer

Difference between particle.publish event and particle.subscribe event in particle.cloud

Particle.publish() Publish an event through the Particle Cloud ...READ MORE

answered Sep 18, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,657 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP