Find answers, ask questions, and connect with our
community around the world.

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?

  • MasonM

    September 27, 2021 at 10:07 am

    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” –

    The 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?

    • This discussion was modified 2 years, 9 months ago by  MasonM.
    • This discussion was modified 2 years, 9 months ago by  MasonM.
  • Carlo-TutorialsDojo

    September 28, 2021 at 1:12 am

    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.

    Carlo @ Tutorials Dojo

  • MasonM

    September 28, 2021 at 2:54 am

    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:


    • Carlo-TutorialsDojo

      September 30, 2021 at 2:51 am

      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.


      Carlo @ Tutorials Dojo

Viewing 1 - 3 of 3 replies

Log in to reply.

Original Post
0 of 0 posts June 2018