1 00:00:00,000 --> 00:00:02,230 ‫So DynamoDB has a feature 2 00:00:02,230 --> 00:00:03,970 ‫called Optimistic Locking. 3 00:00:03,970 --> 00:00:05,130 ‫So the idea is that you can do 4 00:00:05,130 --> 00:00:07,510 ‫Conditional Writes in DynamoDB. 5 00:00:07,510 --> 00:00:08,400 ‫What does that mean? 6 00:00:08,400 --> 00:00:10,660 ‫That means that you want to ensure that an item 7 00:00:10,660 --> 00:00:13,150 ‫has not changed before update or delete it. 8 00:00:13,150 --> 00:00:14,000 ‫So you're saying, Hey, 9 00:00:14,000 --> 00:00:16,830 ‫I want to write this only if this condition is met 10 00:00:16,830 --> 00:00:19,400 ‫and this is called Optimistic Locking. 11 00:00:19,400 --> 00:00:20,233 ‫So the way it works 12 00:00:20,233 --> 00:00:23,000 ‫is that we have an attribute on our items, 13 00:00:23,000 --> 00:00:24,590 ‫which will act as a version number, 14 00:00:24,590 --> 00:00:27,510 ‫and we will check an equality condition 15 00:00:27,510 --> 00:00:29,130 ‫on this version number. 16 00:00:29,130 --> 00:00:30,040 ‫So let's take an example. 17 00:00:30,040 --> 00:00:31,410 ‫We have a DynamoDB table, 18 00:00:31,410 --> 00:00:34,010 ‫and we have an item with a user ID, a first name 19 00:00:34,010 --> 00:00:36,240 ‫and a version, which is one. 20 00:00:36,240 --> 00:00:38,450 ‫Now two clients at the same time 21 00:00:39,289 --> 00:00:41,600 ‫want to update this item 22 00:00:41,600 --> 00:00:43,820 ‫because they think that the first name is wrong. 23 00:00:43,820 --> 00:00:45,150 ‫So the client 1 is saying, 24 00:00:45,150 --> 00:00:48,250 ‫Hey, I want to update this to name = John, 25 00:00:48,250 --> 00:00:50,330 ‫only if version = 1. 26 00:00:50,330 --> 00:00:53,820 ‫And the client 2 says, I want to update name = Lisa 27 00:00:53,820 --> 00:00:56,210 ‫only if version = 1. 28 00:00:56,210 --> 00:00:58,970 ‫What's going to happen is that's one of these requests, 29 00:00:58,970 --> 00:01:00,810 ‫obviously, will make it to DynamoDB first. 30 00:01:00,810 --> 00:01:02,470 ‫And so then DynamoDB will go ahead, 31 00:01:02,470 --> 00:01:03,840 ‫and maybe it's the second one, 32 00:01:03,840 --> 00:01:05,920 ‫will update the first name to Lisa. 33 00:01:05,920 --> 00:01:09,300 ‫And will also update the version to 2, okay? 34 00:01:09,300 --> 00:01:10,790 ‫Now what's going to happen out of this 35 00:01:10,790 --> 00:01:14,260 ‫is that the client 1 updates will not go through 36 00:01:14,260 --> 00:01:15,590 ‫because now that DynamoDB says, 37 00:01:15,590 --> 00:01:20,090 ‫Hey, you told me I should do this update only if version = 1 38 00:01:20,090 --> 00:01:23,180 ‫but it turns out that now my version is = to 2 39 00:01:23,180 --> 00:01:26,960 ‫and therefore, the client will get a error message saying, 40 00:01:26,960 --> 00:01:29,260 ‫Hey, you don't have the right data. 41 00:01:29,260 --> 00:01:30,470 ‫And so therefore you should do a get 42 00:01:30,470 --> 00:01:33,620 ‫and begin try to update if you want to. 43 00:01:33,620 --> 00:01:36,727 ‫So this feature of Conditional Writes or Optimistic Locking 44 00:01:36,727 --> 00:01:38,810 ‫is something that the exam will test you on. 45 00:01:38,810 --> 00:01:39,643 ‫Okay? 46 00:01:39,643 --> 00:01:41,060 ‫So it's just a short intro. 47 00:01:41,060 --> 00:01:42,840 ‫It's not something I can demonstrate easily, 48 00:01:42,840 --> 00:01:43,840 ‫but hope you like this lecture. 49 00:01:43,840 --> 00:01:45,790 ‫And I will see you in the next lecture.