1 00:00:00,100 --> 00:00:01,440 ‫So, a quick lecture on something 2 00:00:01,440 --> 00:00:03,230 ‫called DynamoDB Write Sharding. 3 00:00:03,230 --> 00:00:04,350 ‫So, let's assume this use case 4 00:00:04,350 --> 00:00:05,900 ‫where we have a voting application, 5 00:00:05,900 --> 00:00:08,450 ‫and voting application people can vote 6 00:00:08,450 --> 00:00:10,300 ‫for candidate A and candidate B. 7 00:00:10,300 --> 00:00:11,600 ‫So, two candidates. 8 00:00:11,600 --> 00:00:14,730 ‫Now, if we used the partition key to be candidate ID, 9 00:00:14,730 --> 00:00:16,270 ‫the problem is that all the results 10 00:00:16,270 --> 00:00:18,230 ‫will go into two partitions only 11 00:00:18,230 --> 00:00:20,320 ‫because, well, the data is going to be partitioned 12 00:00:20,320 --> 00:00:22,980 ‫by either candidate A or candidate B, 13 00:00:22,980 --> 00:00:25,240 ‫which will generate issues for writes and for reads 14 00:00:25,240 --> 00:00:27,620 ‫so we're gonna get hot partition issues. 15 00:00:27,620 --> 00:00:29,950 ‫So, how do we solve this issue? 16 00:00:29,950 --> 00:00:33,440 ‫Well, a strategy is to distribute the candidate ID 17 00:00:33,440 --> 00:00:35,870 ‫better across partitions and to do so, 18 00:00:35,870 --> 00:00:37,330 ‫we're going to add a suffix, 19 00:00:37,330 --> 00:00:39,920 ‫or a prefix to the partition key value. 20 00:00:39,920 --> 00:00:41,400 ‫So, the idea is that we're now we're going to get 21 00:00:41,400 --> 00:00:43,190 ‫the candidate ID, and then we'll add, 22 00:00:43,190 --> 00:00:44,290 ‫for example, the number 11. 23 00:00:44,290 --> 00:00:46,920 ‫So candidate a 11, and add a row, 24 00:00:46,920 --> 00:00:49,010 ‫and then we're going to have candidate b 17, 25 00:00:49,010 --> 00:00:51,540 ‫candidate b 18, candidate a 20, 26 00:00:51,540 --> 00:00:53,360 ‫and the idea is that now the partition key, 27 00:00:53,360 --> 00:00:54,460 ‫is a lot more distributed, 28 00:00:54,460 --> 00:00:56,570 ‫because it takes more unique values 29 00:00:56,570 --> 00:00:59,820 ‫and therefore your data set is going to be fully written 30 00:00:59,820 --> 00:01:02,410 ‫and fully readable from your Dynamo DB table. 31 00:01:02,410 --> 00:01:05,530 ‫Now, two methods for creating this suffix or this prefix. 32 00:01:05,530 --> 00:01:07,560 ‫You can use a random suffix 33 00:01:07,560 --> 00:01:10,860 ‫or you can calculate it using a hashing algorithm. 34 00:01:10,860 --> 00:01:11,780 ‫Both of these things work. 35 00:01:11,780 --> 00:01:13,620 ‫The idea is that you want to get a very, 36 00:01:13,620 --> 00:01:15,200 ‫very distributed partition key. 37 00:01:15,200 --> 00:01:16,480 ‫That's all, it's just a theory lecture, 38 00:01:16,480 --> 00:01:17,930 ‫but you know this strategy now. 39 00:01:17,930 --> 00:01:20,683 ‫I hope you liked it and I will see you in the next lecture.