amazon-web-servicesnosqlamazon-dynamodbamazon-dynamodb-data-modeling

Finding the best way to put a tiered document into DynamoDB


I've been working with regular SQL databases and now wanted to start a new project using AWS services. I want the back end data storage to be DynamoDB and what I want to store is a tiered document, like an instruction booklet of all the programming tips I learned that can be pulled and called up via a React frontend.

So the data will be in a format like Python -> Classes -> General -> "Information on Classes Text Wall"

There will be more than one sub directory at times.

Future plans would be to be able to add new subfolders, move data to different folders, "thumbs up", and eventual multi account with read access to each other's data.

I know how to do this in a SQL DB, but have never used a NoSQL before and figured this would be a great starting spot.

I am also thinking of how to sort the partition, and I doubt this side program would ever grow to more than one cluster but I know with NoSQL you have to plan your layout ahead of time.

If NoSQL is just a horrible fit for this style of data, let me know as well. This is mostly for practice and to practice AWS systems.


Solution

  • DynamoDb is a key-value database with options to add a secondary indices. It's good to store documents that doesn't require full scan or aggregation queries. If you design your tiered document application to show only one document at a time, then DynamoDB would be a good choice. You can put the documents with a structure like this:

    DocumentTable:
    {
     "title": "Python",
     "parent_document": "root"
     "child_documents": ["Classes", "Built In", ...]
     "content": "text"
    }
    

    Where:

    You can also have another table with a table of contents for a user's tiered document, which you can use for easier navigate over the documents, however in this case you need to care about consistency of this table.

    Example:

    ContentsTable:
    {
        "user": -- primary key for this table in case you have many users
        "root": [
            "Python":[
                "Classes": [
                    "General": [
                        "Information on Classes Text Wall"
                    ]
                ]
            ]
        ]
    }
    

    Where Python, Classes, General and Information on Classes Text Wall are keys for DocumentTable.title. You can also use something instead of titles to keep the keys unique. DynamoDB maximum document size is 400 KB, so this would be enough for a pretty large table of contents