What is a DynamoDB LSI (Local Secondary Index) ?

Поділитися
Вставка
  • Опубліковано 1 жов 2024

КОМЕНТАРІ • 100

  • @Sami-ec9sd
    @Sami-ec9sd 4 місяці тому +2

    There is one limitation when using LSI:
    Your Data being stored within the same partition key isn't anymore allowed to exceed 10GB. If you have reached 10GB you wont be able to add more items (you get the error ItemCollectionSizeLimitExceededException).
    You can read about this in the aws doc with the title "Local Secondary Indexes" and the subtitle "Item collections in Local Secondary Indexes"

  • @zacsonskaria
    @zacsonskaria 4 роки тому +10

    The PartitionKey + SortKey may not be unique, since two subjects in a forum can have same LastPostDateTime. It may not be relevant since it is just an example and the focus is something else, however it can cause confusion in my opinion.

    • @BeABetterDev
      @BeABetterDev  4 роки тому +1

      Hi Zacson, thanks for pointing this out. You are absolutely correct.

    • @pikachu5223
      @pikachu5223 2 роки тому +1

      There you can use the suffix pattern

    • @rongrongmiao3018
      @rongrongmiao3018 Рік тому

      If you use Unix epoch time it would be unique

    • @zacsonskaria
      @zacsonskaria Рік тому +1

      @@rongrongmiao3018 Why do you think that the unix epoch time won’t collide when generated at the same time?

  • @adamkinsey3139
    @adamkinsey3139 2 роки тому +1

    So...let's design and sell a "NoSQL" database, and then add in "fancy" features so that users can pay extra to have a fraction of the SQL features?
    I genuinely don't understand why you would choose to use a "NoSQL" database for any use-case like this....and I would love to know!

    • @BeABetterDev
      @BeABetterDev  2 роки тому

      Hi Adam,
      Thank you for the comment. I have a video on RDS vs DynamoDB that attempts to answer your question. You can watch it here: ua-cam.com/video/crHwekf0gTA/v-deo.html
      Hope this helps,
      Daniel

  • @SpotCallerzWrestling
    @SpotCallerzWrestling 4 роки тому +11

    This is exactly what I needed! Thanks very much. Saved me a lot of money.

  • @sunwoojeong9996
    @sunwoojeong9996 2 роки тому +2

    Thank you for your lecture. Is LSI sth like a sort key, without having the uniqueness limitation of (partition key, sort key) pair?

    • @BeABetterDev
      @BeABetterDev  2 роки тому

      Hi Sunwoo, that's a good way of thinking about it!

    • @sunwoojeong9996
      @sunwoojeong9996 2 роки тому

      @@BeABetterDev Got it. Also, for GSI, the whole table (data) is physically replicated to multiple machines. Is LSI also copying some portion of data (the data corresponding to the right partition key) and storing them in different orders?

  • @mqtt07
    @mqtt07 Рік тому +4

    One other limitation, just to be clear, is that you can change the sort key, not the partition key in an LSI

  • @yogiHalim
    @yogiHalim 4 роки тому +3

    great vid. Thanks.
    First example on 4:00 mins, first approach scan on entire table, should read all data including forum name EC2 and RDS. You stopped at S3 while not entirely wrong but mildly confusing at first as compared to second approach.

    • @yogiHalim
      @yogiHalim 4 роки тому +2

      Thanks for the code snippets 7:05 mins (just leaving a shortcut here)

  • @alekseiborsenkodev
    @alekseiborsenkodev 2 роки тому +1

    Nice explanation, but I have a little correction. You CAN NOT search by endsWith. only beginwith

  • @windowcrystal4012
    @windowcrystal4012 4 роки тому +5

    Speed: Scan then filter < query on partition key < LSI

  • @hejiaji
    @hejiaji 2 роки тому +1

    In this example, how can the primary key be assured to be unique? ForumName(Partition key) + LastPostDateTime(SortKey) could definitely be duplicated right?

  • @worddoc4322
    @worddoc4322 3 роки тому +3

    Thank you for the video. I have a question: once a sort key has been set, a table keeps its data sorted by that key. LSI is considered as an extension of the sort key. How the table gets sorted by a pack of sort key + multiple LSI? I think there is something different behind LSI. Could you shed light on it please?

    • @niteshgupta8436
      @niteshgupta8436 2 роки тому

      I also have the same doubt. Please explain.

  • @zeretil
    @zeretil Рік тому

    This is confusing to me as a rookie -- isn't your partitionkey supposed to be unique? Even when using the Sort Key as part of your partition key, there can be duplicates when two forum posts are updated at the same time?

  • @roboprofit2548
    @roboprofit2548 3 роки тому +4

    Great video. Keep in mind that more LSI more cost. AWS DOC ==> "A table with many local secondary indexes incurs higher costs for write activity than tables with fewer indexes"
    However, writing to the base table with 2 LSIs still cost 1 WCU IF you don't write to LSIs as well. If you write to 1 LSI then it costs 2 WCUs ( 1 for the table and 1 for LSI)

    • @BeABetterDev
      @BeABetterDev  3 роки тому +1

      Great point! Thanks for sharing.

    • @bradw2k
      @bradw2k 3 роки тому

      When would a write to a table not result in a write also to its GSI?

    • @tahiraziz193
      @tahiraziz193 2 роки тому

      Hi @Robo Profit would be great if you can share any reference please? i have gone through the AWS documentation but couldn't find this. Thanks

    • @roboprofit2548
      @roboprofit2548 2 роки тому

      @@bradw2k when you don't write to the index and only write to the base table

  • @sardesaisantosh
    @sardesaisantosh Рік тому

    how can an entire table scan will happen when you have a partition key on forumname in the example for fetching records with s3 and subject = aaa

  • @_arshadm
    @_arshadm 2 роки тому +2

    You left one of the most important questions unanswered. Does the LSI range key attribute also need to be unique in combination with the hash key (i.e. LSI is just another sort key)

    • @renatolimasantos8618
      @renatolimasantos8618 2 роки тому +2

      From aws docs:
      "In a DynamoDB table, the combined partition key value and sort key value for each item must be unique. However, in a local secondary index, the sort key value does not need to be unique for a given partition key value. If there are multiple items in the local secondary index that have the same sort key value, a Query operation returns all of the items that have the same partition key value. In the response, the matching items are not returned in any particular order."

    • @_arshadm
      @_arshadm 2 роки тому

      @@renatolimasantos8618 Thanks, I was looking for this additional info. This makes the LSI a lot more useful.

  • @mugssyy
    @mugssyy 2 роки тому +2

    Hi ! Your videos are great! I had trouble understanding the LSI and GSI for a long time. Thank you . going through more of your content.

  • @prvinsharma
    @prvinsharma 2 роки тому +1

    Well explained! I was going through PluralSight and got lost there with LSI and GSI. Had to hop in here as the first and greatfully the last for LSI. GSI would be next. Thanks

  • @aamersohail474
    @aamersohail474 3 роки тому +2

    Thank you so much for exemplifying it so clearly.

  • @jeffinj7707
    @jeffinj7707 3 роки тому +1

    Very helpful. A quick question: I have a large JSON data, how can I create a table with that JSON structure. And can we populate the table with a JSON file?

  • @spider279
    @spider279 2 роки тому +1

    You are the hero who saves me for my presentation of dynamoDB at class , such a great explaination

  • @karahisarli
    @karahisarli 4 роки тому +2

    Great videos and explanation, appreciate the effort, tried couple of blogs/documents but very clearly stated here. Can you please give some tutorials on schema design specially some relations?

    • @BeABetterDev
      @BeABetterDev  4 роки тому

      Thanks serdar. I'll look into incorporating relations in an upcoming video!

  • @jwalaivaturi
    @jwalaivaturi 3 роки тому +1

    Thanks for the awesome video. Queries or scans on a local secondary index consume read capacity units from the base table and updates consume write capacity units from the base table. What do you mean by no extra cost with LSI?

    • @Xhez2slash
      @Xhez2slash 3 роки тому +1

      It is compared to the GSI, where if you create an another GSI for your table that would incur extra cost. (provision extra wcu/rcu for the table created)

  • @juancpgo
    @juancpgo 4 роки тому +3

    Great content. 👍 Thank you.

  • @gdemelo
    @gdemelo 9 місяців тому

    Great explanation. I would recommend providing SDK examples with Javascript/NodeJS or Python, instead of Java, though.

  • @Viet100
    @Viet100 3 роки тому

    I have a question for scan operation. if I scan by PK and Subject="aaa" for example, does dynamodb scan/read "LastPostDateTime"? or it just scan the specified column (not all columns).

    • @BeABetterDev
      @BeABetterDev  3 роки тому +1

      Hi Clouder,
      Scans will return the entire row, so all the columns.
      Hope this helps.

    • @Viet100
      @Viet100 3 роки тому

      @@BeABetterDev thanks for your effort. keep it up.

  • @jeevanthomaskoshy8979
    @jeevanthomaskoshy8979 3 роки тому +1

    Won't LSI also duplicate the data like the global secondary index?
    So wouldn't that lead to increased cost ?

    • @sauer.voussoir
      @sauer.voussoir 3 роки тому

      same question, if does also create a new table copy like GSI

  • @sameeshoncloud9
    @sameeshoncloud9 4 роки тому +3

    amazing work buddy

  • @MohammadFaizanAli786
    @MohammadFaizanAli786 4 роки тому +1

    It's a great video but could you explain how Amazon does it internally? How does it not create more tables and still gives such fast results? If we have local index can we choose to not provide it?

    • @BeABetterDev
      @BeABetterDev  4 роки тому

      Hey Mohammad,
      Unfortunately there isn't much documentation in terms of how aws structures LSIs so really its anyone's guess.

  • @sonny23ization
    @sonny23ization 3 роки тому

    why is this strongly consistent?

  • @josereneherrerauribe-ceiba8047
    @josereneherrerauribe-ceiba8047 4 роки тому +1

    Hello, excellent video! You have any java repository with examples?

    • @BeABetterDev
      @BeABetterDev  4 роки тому

      Hi Jose, I unfortunately dont but will look into setting one up. Thanks for watching.

  • @ahmedal-shamari414
    @ahmedal-shamari414 4 роки тому +1

    thanks for your awesome Video
    can I ask about the brief difference between GSI and LSI? from the 2 videos I think the difference that LSI must be defined at table creation time, no Extra Cost, max 5 LSI per table, it is alternative to range key while GSI can be defined any time, need extra cost, no limitation per table, also GSI= new Partition key + new sort key
    am I correct with the above?
    thanks and best regards

    • @BeABetterDev
      @BeABetterDev  4 роки тому

      Hi yes you are correct. Also keep in mind the purpose of the LSI and GSI are fundamentally different. LSI helps you define more range-like queries on a different index. Whereas GSI allows you to perform direct key lookups on the corresponding index.

    • @josecruz2574
      @josecruz2574 4 роки тому +1

      @@BeABetterDev so if looking for a specific index - GSI would be more appropriate?

  • @ognjenaskovic1830
    @ognjenaskovic1830 2 роки тому

    Hey, total newbie to Dynamo here. I have a question regarding combination of GSI and LSI. So, if my table has one GSI and one LSI defined, can I do the query which uses GSI as a hash key value and LSI as a range key value ? That would make my life a lot easier, but I'm not sure if it is possible. Will appreciate any help :)

  • @pravinbudage3942
    @pravinbudage3942 2 роки тому +1

    You have explained it very smoothly and cleared all the doubts. Thanks

  • @TomerBenDavid
    @TomerBenDavid 4 роки тому +1

    Very clear! Last limitations section was great. I would also suggest to add what are the drawbacks when should you not use it obviously it does not come for free and you might want to use a different db like a mirror in some other place to do these queries based on your intent there is a reason it's a simple kv. Great video many thanks.

  • @JesusAlfredoHernandezOrozco

    Great video!
    Really well explained. I recommend it!

  • @LifeDude
    @LifeDude 3 місяці тому

    Awesome

  • @ralfrolfen5504
    @ralfrolfen5504 6 місяців тому

    perfect!

  • @__noob__coder__
    @__noob__coder__ 11 місяців тому

    Which coding font are you using ?

  • @mhlaskar1991
    @mhlaskar1991 4 роки тому +1

    Does LSI doubles the space like GSIs?

    • @BeABetterDev
      @BeABetterDev  4 роки тому +1

      Hi Mahbubul,
      LSIs do not take extra space.
      Thanks for watching!

    • @The6thProgrammer
      @The6thProgrammer 3 роки тому

      @@BeABetterDev I don't believe this answer is correct. I believe similar to GSIs the LSIs will consume more space and consume WCUs as well. See here docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html where it is mentioned in the AWS documentation "The smaller the index, the less that it costs to store it, and the less your write costs are". This is why there is a trade-off in how many additional attributes you would want to project in your LSI.

    • @warrenjohnson5971
      @warrenjohnson5971 3 роки тому

      @@The6thProgrammer No more read units but more space consumed I guess?

  • @arhabersham
    @arhabersham 3 роки тому +1

    Well explained ❤️

    • @BeABetterDev
      @BeABetterDev  3 роки тому

      Thanks Alfredo! Glad you enjoyed :)

  • @ankitgarg568
    @ankitgarg568 4 роки тому +1

    Great video. Helped me a lot!!

  • @eric19435
    @eric19435 4 роки тому

    Nice video. What is the use case of GSI and LSI? What is the different between them?

    • @BeABetterDev
      @BeABetterDev  4 роки тому +1

      Hi Eric,
      GSIs allow you to query for specific attributes other than the partition key. LSIs allow you to perform 'range-like' queries on your LSI's range key.

  • @vagifk2864
    @vagifk2864 4 роки тому

    Should LSI be unique within the same table?

    • @BeABetterDev
      @BeABetterDev  4 роки тому

      It does not necessarily have to be.

  • @abhishekpaithane6292
    @abhishekpaithane6292 2 роки тому

    great explanation!

  • @angry740
    @angry740 4 роки тому +1

    Excellent!!

  • @krishnasmusicchart4897
    @krishnasmusicchart4897 2 роки тому

    Explained excellently, sir

  • @rickfarina9835
    @rickfarina9835 4 роки тому

    What is the criteria to use an LSI vs. a GSI? Or, is there now no benefit to using LSIs?

    • @BeABetterDev
      @BeABetterDev  4 роки тому +1

      Hi Rick,
      LSIs can unfortuantely only be defined when the table is created and solve a bit of a different purpose than LSIs. LSIs allow you to perform 'range-like' queries on a data field provided you know the partition key. GSIs allow you to perform direct lookups or queries on fields other than the partition key.
      Hoep this helps!

    • @rickfarina9835
      @rickfarina9835 4 роки тому

      @@BeABetterDev Hi... First, thank you for this series of AWS videos. Absolutely fantastic!!
      On the LSI/GSI difference, it caused me to re-read the docs and do some testing. I still have the understanding that a GSI can be built over the same Partition Key (PK); and can use either the same or different Sort key (SK) than the base table, which I believe implies a range. For example: "Select PK='x' and SK between 10 and 15".
      I believe this represents a "Range-Query" that you mentioned above. If this is true, doesn't that mean the GSI has essentially the same Query capabilities as the LSI? If so, I'm sill not sure what benefit the LSI has over the GSI, other than it's stored along with the base table rather than creating its own Partitions as the GSI does. Thanks again, so much. Rick

  • @leiliu83
    @leiliu83 4 роки тому

    So for LSI, hash key + range key does not need to be the same

  • @xamry_
    @xamry_ 4 роки тому

    Thanks, to the point and easy to understand.

  • @ravisaraswat6519
    @ravisaraswat6519 4 роки тому

    You are great , keep up the excellent wok.

  • @harshjain8823
    @harshjain8823 Рік тому +1

    take some break when you finish a sentence.

  • @waytospergtherebro
    @waytospergtherebro Рік тому

    This is the single most useless "database" anyone has ever designed.