Home › Forums › AWS › AWS Certified DevOps Engineer Professional › Local vs global secondary indices – why is this answer correct?
-
Local vs global secondary indices – why is this answer correct?
Carlo-TutorialsDojo updated 3 years ago 2 Members · 4 Posts -
I bought the practice exam and I’m confused by the answer to the following question:
“An educational startup has developed an e-learning platform hosted in AWS, where they sell their online courses. The CTO is planning to release an online forum that will allow students to interact with each other and post their questions. This new feature requires a new DynamoDB table named Thread in which the partition key is ForumName and the sort key is Subject. Below is a diagram that shows how the items in the table must be organized:<image redacted>
The forum must also find all of the threads that were posted in a particular forum within the last three months as part of the system’s quarterly reporting.
Which of the following is the MOST suitable solution that you should implement?”
The quiz says the correct answer is to use a local secondary index with “LastPostDateTime” as the sort key, but I chose the answer to use a global secondary index, because that’s what’s recommended in the official documentation:
“In general, you should use global secondary indexes rather than local secondary indexes.
The exception is when you need strong consistency in your query results, which a local
secondary index can provide but a global secondary index cannot” – https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general.htmlThe explanation the quiz gives for why that answer is wrong is “because using a local secondary index is a more appropriate solution to be used in this scenario”. But there’s no mention about the need for strong consistency in the scenario, and global secondary indices have many advantages over local secondary indices, so why is a local secondary index more appropriate here?
-
Hello Mason,
Thanks for your feedback.
Technically, a GSI with the LastPostDateTime as the sort key would work too. However, it is deemed as not the MOST suitable option because GSIs are usually used if you want to have a different partition key and sort key (optional), thus, the query will be ‘global’ because it’ll span across all partitions. Creating a GSI with the same partition key defeats its purpose of being ‘global’. Furthermore, you don’t need to recreate a DynamoDB table to create a GSI. You can create a GSI on an existing table.
Let me know if this answers your question.
Regards,
Carlo @ Tutorials Dojo -
Hi Carlo,
Thanks for the reply, but it contradicts the official documentation, which says “In general, you should use global secondary indexes rather than local secondary indexes”. I can’t find anything that says you should prefer LSIs when the partition key is the same, or that creating a GSI with the same partition key “defeats its purpose”.
It’s not official, but here’s a great article that gives a flowchart showing when you should choose GSI over a LSI, and when I follow the flowchart, it’s clear that the right answer in this scenario is a GSI: https://www.dynamodbguide.com/local-or-global-choosing-a-secondary-index-type-in-dynamo-db/
Mason
-
Hello MasonM,
I understand that consistency is one of the criteria in choosing a secondary index type. However, in the scenario, it wasn’t clear which consistency the application needs so it shouldn’t be assumed. The question is leaning more toward choosing the most suitable solution available for the presented scenario. You should also pay attention to little details. For an instance, recreating a new table to create a GSI is already a red flag. This is an example of nuances that you should be aware of in the actual exam.
Let me know your thoughts.
Regards,
Carlo @ Tutorials Dojo
- This reply was modified 3 years ago by Carlo-TutorialsDojo.
-
Log in to reply.