0

I have a DynamoDB table and items in the table that look something like this:

{
   "id":"id",
   "randomData":{
      "randomData1":"randomData1",
      "randomData2":"randomData2"
   },
   "status":"status",
   "subTasks":[
      {
         "subTaskId":"subTaskId",
         "subTaskType":"subType",
         "subTaskAnyData":"subTaskAnyData",
         "subTaskStatus":"status",
      },
      {
         "subTaskId":"subTaskId",
         "subTaskType":"subType",
         "subTaskAnyData":"subTaskAnyData",
         "subTaskStatus":"status",
      },
      {
         "subTaskId":"subTaskId",
         "subTaskType":"subType",
         "subTaskAnyData":"subTaskAnyData",
         "subTaskStatus":"status",
      }
   ]
}

So I have the top-level id (primary / partition key) attribute, but also inside the subTasks array, there is the subTaskId.

Is there an efficient way to query the table and get the data i.e. the one subTask object based on subTaskId?

Or should I consider redesigning the table and having the subtasks in a separate table?

Nimantha
  • 6,405
  • 6
  • 28
  • 69

1 Answers1

0

In short,

No it's over kill, because you must get the full object or/and perform a lot of scans.

It's depend of what many times you request the subTaskId, you may use a separate table or perform a monotable with another GSI (subTaskId as Secondary Index) with queries as much efficient than scans.

Hatim
  • 1,116
  • 1
  • 8
  • 14
  • Thanks Hatim! I would probably need the specific subtask often enough, checking the status, retry etc. Not sure I understand the monotable approach, and subTaskId as secondary index since I'll always have multiple subtasks? – programator Dec 20 '21 at 16:02
  • Sorry for the delay, you can use like a monotable to store all your data. you need to simulate all types of request to design it perfectly like ( get task by Taskid, get subtask by SubTask id, get all subtaskd by Taskid) ==> https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-modeling-nosql-B.html – Hatim Dec 21 '21 at 10:25
  • I've found [this tool](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/workbench.html) to be helpful when trying to visualize a table design around certain access patterns – bd_ Dec 26 '21 at 05:52