1 00:00:00,160 --> 00:00:01,450 ‫So another theory lecture 2 00:00:01,450 --> 00:00:04,290 ‫about all the writes you can do on DyamoDB, 3 00:00:04,290 --> 00:00:06,270 ‫just so you have a really good understanding of them. 4 00:00:06,270 --> 00:00:08,240 ‫So the first one is concurrent writes, 5 00:00:08,240 --> 00:00:10,827 ‫which we have an item and say to the users, 6 00:00:10,827 --> 00:00:11,920 ‫"Want to update the item." 7 00:00:11,920 --> 00:00:12,967 ‫So the first one say, 8 00:00:12,967 --> 00:00:15,050 ‫"Hey, update this item to value equals one." 9 00:00:15,050 --> 00:00:15,927 ‫And the second one says, 10 00:00:15,927 --> 00:00:18,900 ‫"Hey, I want you to update the item with value equals two." 11 00:00:18,900 --> 00:00:21,330 ‫Now what happens? Well, they're both going to succeed. 12 00:00:21,330 --> 00:00:23,930 ‫So the first one will maybe update to value equals one. 13 00:00:23,930 --> 00:00:25,290 ‫The second updates to value equals two. 14 00:00:25,290 --> 00:00:27,040 ‫And so maybe the second write 15 00:00:27,040 --> 00:00:28,800 ‫will overwrite the first writes, 16 00:00:28,800 --> 00:00:30,550 ‫if it happens afterwards, okay? 17 00:00:30,550 --> 00:00:32,900 ‫But one of them will be overwritten. 18 00:00:32,900 --> 00:00:34,960 ‫And this is not a very desired behavior 19 00:00:34,960 --> 00:00:36,780 ‫because two of them try to update an item 20 00:00:36,780 --> 00:00:37,870 ‫and both get success, 21 00:00:37,870 --> 00:00:40,410 ‫but obviously only one of them really succeeded. 22 00:00:40,410 --> 00:00:42,150 ‫So that's why it's called concurrent writes. 23 00:00:42,150 --> 00:00:43,040 ‫So how can we solve this? 24 00:00:43,040 --> 00:00:44,560 ‫We can do conditional writes. 25 00:00:44,560 --> 00:00:46,777 ‫In conditional writes, the idea is that the user says, 26 00:00:46,777 --> 00:00:49,890 ‫"Hey, I want to get this item with value equals one, 27 00:00:49,890 --> 00:00:52,810 ‫but only if the value is currently zero." 28 00:00:52,810 --> 00:00:54,367 ‫And the second person says, 29 00:00:54,367 --> 00:00:56,880 ‫"Hey, I want you to do the value of this item 30 00:00:56,880 --> 00:01:00,550 ‫with value equals two, but only if the value is zero." 31 00:01:00,550 --> 00:01:02,210 ‫What's going to happen now is that, for example, 32 00:01:02,210 --> 00:01:04,240 ‫the first write is going to be accepted. 33 00:01:04,240 --> 00:01:05,980 ‫So the value will be equals one. 34 00:01:05,980 --> 00:01:07,700 ‫And the second write is going to fail 35 00:01:07,700 --> 00:01:08,880 ‫because at the time 36 00:01:08,880 --> 00:01:11,070 ‫of evaluating the condition value equals zero, 37 00:01:11,070 --> 00:01:12,567 ‫it turns out that then it would to be able say, 38 00:01:12,567 --> 00:01:13,400 ‫"Hey, you know what? 39 00:01:13,400 --> 00:01:14,900 ‫Actually, the value now is one." 40 00:01:14,900 --> 00:01:16,960 ‫So we shouldn't do your writes. 41 00:01:16,960 --> 00:01:20,370 ‫So this is a way to solve the concurrency problems. 42 00:01:20,370 --> 00:01:23,340 ‫And that's why it's called optimistic locking. 43 00:01:23,340 --> 00:01:26,010 ‫Now another kind of writes you can do are atomic writes. 44 00:01:26,010 --> 00:01:27,747 ‫So in this example, the user say, 45 00:01:27,747 --> 00:01:29,930 ‫"Hey, I want you to increase the value by one," 46 00:01:29,930 --> 00:01:30,763 ‫and the user two say, 47 00:01:30,763 --> 00:01:32,690 ‫"I want to increase the value by two." 48 00:01:32,690 --> 00:01:34,760 ‫Now both writes are going to succeed. 49 00:01:34,760 --> 00:01:37,370 ‫And the value in total will be increased by three. 50 00:01:37,370 --> 00:01:39,290 ‫So one plus two equals three. 51 00:01:39,290 --> 00:01:42,310 ‫And finally, nothing to do with these kind of concurrency, 52 00:01:42,310 --> 00:01:45,780 ‫but just batch writes is when a user writes or updates 53 00:01:45,780 --> 00:01:47,810 ‫many items at a time, okay? 54 00:01:47,810 --> 00:01:48,690 ‫So now you know, 55 00:01:48,690 --> 00:01:50,800 ‫all the types of writes you have in DynamoDB, 56 00:01:50,800 --> 00:01:52,660 ‫and it should make sense to you at the exam. 57 00:01:52,660 --> 00:01:55,610 ‫I hope you liked it and I will see you in the next lecture.