What are Partition Keys and Sort Keys? | AWS DynamoDB | Tutorial for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let me talk about how partitioning actually happens and for that we have to select something called a partition key this is important this is a design question now let's say this is the data which I want to keep this is my data I want to store this data now I have to ensure that I select a unique value which will be called my partition key what is the partition key partition key is how my data is going to be stored across these copies which record would go where let's say I have let's say let's say I'm having let's consider these are three doors of a stadium so this is a stadium and there are three doors and there are thousands of people inside the stadium and you want them to move out you may say hey every male candidate will go from here every female candidate will go from here and then maybe child children will go from here what I did I did a partitioning of the crowd is it good or bad I would say it depends what if if it was a football match and no offense maybe lot of men are present which means I would have lot of people lining up here L kid this door is not at all being utilized where I have lot of people lining up here less crowd on female so maybe this was not a good design for distribution of my data what if instead of that in the same three gates what if if I have done like this let's say hey three gates and I'm saying anyone who is in the ticket range from 1 to 100 will use gate number one 101 to 200 will use gate number two and 2001 to 300 will use gate number three hope you get the idea now I have distributed my workload equally maybe in this time this is a good design right so it depends similarly when you are trying to store your data like we are trying to store it here we have this information and we want to store it what can can I do for it so I am focusing on creating a partition key let's see what that partition key would be I say partition key is going to be my book title which means my data would be stored as different different book names so what would happen in this case hey my primary key is my partition key so primary key and partition key same in this case how I'm going to distribute my data I am going to distribute my data based on this which means my Harry Potter would be the book based on that I would store my data but let's consider another situation let's say JK rolling comes up with another Harry Potter book which is second edition $25 price 15 chapter first edition has 12 chapters and $20 as a price now if my partition key was titled and now I say let's insert This Record also into Dynamo DB what it will do okay it will say okay what is your partition key Harry Potter let me updo it Harry Potter which means it will be removing this record and putting JK rolling and then 15 and 25 hope you're getting the point so as my book name is my key which is not a good design because a book may have second addition third addition and if I'm using this method in this case I won't be able to use a proper partition key this is not at all a good design for my application because this will create problem when I have similar book names right so what I should do in that case let me go ahead and try to find out a solution on that what if I say I am going to create a partition key sorry I'm going to create a primary key which will be combination of book name and combination of salt key what I did here I have added a extra parameter to make my primary key unique primary key should always always be unique in this case if I just selected book name it won't be unique and that's why what I did I said okay let me go ahead and add one more column which will be called my salt key so that combination will now become a unique value for me and that's how we select a primary key and a partition key or salt key right so using ISBN yes why not if we had ISBN number that would be best thing so my point to clarify this thing is whatever you select as your primary key should be giving you the best unique combination let me give another example here that what could be a bad design for your primary key let's say you have a online system come on let's create one more new let's say you have a online or you what is a TV program where you are are voting for your pro people voting for three candidates right or four candidates so candidate one vote candidate two candidate three candidate 4 now in this case if I said hey I am going to use candidate ID as my partition key so what would happen candidate a candidate B candidate C and candidate D I don't expect that my data would be equally distributed it may happen a was not at all popular only 10% vote came to him or her so only 10% vote came in right so that may not be a best way for them so only let me put a pen here and I have here Pen only 10% vote came in for them B was very popular so maybe 50 70% vote came for them so that will can create hot partitions for me so that's what we don't want we want to ensure that we are able to maintain our application properly and not create any hot partition so what I may do in that case hey with candidate ID or the TV presenter ID I would add a random timestamp so that it would become R become a a unique value so we need to ensure that we are going to utilize on partitioning so partitioning is very important you need to be thorough with what you are going to utilize for your application what type of application it is should I use only primary key or should I use primary and partition key both it all depends so let me quickly go to console and show that thing to you how you can decide that or how you can design it give me a minute so I'm going to Dynamo DB so I'm going to Dynamo DB and I'll try to show that so what I create here I create tables I do not create databases in Dynamo DB everything in Dynam DB start with a table Creation in traditional world you first create a database and in then database you create table in Dynamo DB's case we just start by creating tables directly so let's say these are my tables and I want to create a table here and I can give it a name let's say call it my all favorite books sorry for my typing mistakes but hopefully you are getting the idea so what I can do I can create a book and I can say hey what is going to be my partition key I would say book title and if it is not unique I can also say let me use addition in addition I can say your data type would be number whereas your book title would be a string right so in this case I could go ahead default setting read write and say create and my table would be ready but if I feel no my book title or let's say if this was a ISBN number then I don't have to need for a salt key at all I could skip it because ISBN is always going to be unique so it depends on how you want to design your application it is purely driven by your application design options are there in in Dynamo DV you need to understand a lot about designing because if you designed it wrong then you may end up into hot partition and you may not get the performance you are looking for another Advantage here in Dynamo DB is that you never specify the size of your database see basically you do not have database at all it is all table and you just say hey this is my table this is performance I need and that's all I want from this table I don't worry about what capacity what size it is you keep on sending as much data to Dynamo DB and at the back end it would take care of everything can I use multiple keys to compose my partition key 2 only so padan 2 only you have option here to select one partition key and one salt key only two but there are other option where you could create indexes in that you could use multiple combination for it that is possible that you could say hey I want to design multiple partitions and I want sorry I want to design multiple indexes and based on that we could select it so that was
Info
Channel: BeSA
Views: 3,025
Rating: undefined out of 5
Keywords: cloud computing, cloud training, cloud for beginners, aws for beginners, AWS, AWS RDS, Read Replicas, AWS Cloud, AWS DynamoDB tutorial, AWS DynamoDB deep dive, AWS DynamoDB partition key, AWS DynamoDB range key, dynamodb partition key, partition key, choosing the right dynamodb partition key, what is dynamodb, dynamodb, awssimplified, amazon dynamodb, aws dynamodb tutorial
Id: XpZeppLmABk
Channel Id: undefined
Length: 9min 42sec (582 seconds)
Published: Fri Nov 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.