---
title: "Discussion on \"How to model relational data in DynamoDB\" | Hashnode"
description: "Discussion on \"How to model relational data in DynamoDB\". Understanding DynamoDB single table design, one-to-many and many-to-many relationships."
url: "https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to model relational data in DynamoDB](https://blog.stefanolaru.com/how-to-model-relational-data-in-dynamodb?utm_source=hashnode&utm_medium=feed)

Understanding DynamoDB single table design, one-to-many and many-to-many relationships.

Mar 14, 2022 · 7 min read · blog.stefanolaru.com  
Updated Mar 21, 2022  
Read the article

-   [#aws](https://hashnode.com/tag/aws)
-   [#dynamodb](https://hashnode.com/tag/dynamodb)
-   [#serverless](https://hashnode.com/tag/serverless)
-   [#monitoring](https://hashnode.com/tag/monitoring)
-   [#opensource](https://hashnode.com/tag/opensource)

## Written by

[Stefan Olaru](https://hashnode.com/@stefanolaru)

@stefanolaru

  
[View profile](https://hashnode.com/@stefanolaru)

Head of Development | Architect | 7x AWS Certified | AWS Community Builder | Serverless

An architect by trade, practicing architecture in the Cloud. 7x AWS Certified, AWS Community Builder, Serverless advocate, Vue enthusiast.

## Responses 4

Markdown supported · ⌘↵ to post

[Drew Davis](https://hashnode.com/@Drewdavis888)

[Apr 30, 2025](https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083/comment/68122b1eb392e875f950721d)

I wrote a npm package, dyna-record, which abstracts these design concepts. I’m interested to know what you think of it. I’m apparently not allowed to share links here but I wrote a blog title Unlock Relational Data Modeling in DynamoDB with dyna-record on medium

[Mohit Yadav](https://hashnode.com/@just-moh-it)

[Mar 20, 2022](https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083/comment/62368f71bef4c71aa6f10fb3)

Great to learn something! I'm new to DynamoDB and still confused why you prepended `project#` and `monitor#` to some GSIs, this would increase the redundancy and also unintentionally increase storage space.

Also, while querying, why do you query both, the primary key and the GSI, even though the schema says they contain the same data.

I might be totally getting the concept of GSIs wrong. Pardon me for that.

Thanks for the awesome and in-depth article 🎉

[Stefan Olaru](https://hashnode.com/@stefanolaru)

[Mar 21, 2022](https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083/comment/62368f71bef4c71aa6f10fb3#reply-62380c8c8e4fae3f767e0842)

Hey [Mohit Yadav](https://hashnode.com/@just-moh-it), good question.

It's called index overloading. The table can hold many different kinds of data items at one time, hence we use generic names for primary key (PK), sort key (SK), and global secondary index (GSI).

Prefixing allows to identify the entity to be queried, e.g. user-related items will always have PK starting with _user#_, so on.

The GSIs help with certain access patterns, let's say we have items like: PK:project#1234|SK:project#1234|GSI:org#1234|attrs PK:project#4321|SK:project#4321|GSI:org#1234|attrs

We can get the project details using `GetItem`, but to `Query` all projects of an org we'll have to use the overloaded GSI like `GSI=org#1234 AND begins_with(SK, project#)`.

[Mohit Yadav](https://hashnode.com/@just-moh-it)

[Mar 21, 2022](https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083/comment/62368f71bef4c71aa6f10fb3#reply-6238a691e6506757acb79c83)

Thanks for the in-depth answer, [Stefan](https://hashnode.com/@stefanolaru)!

Honestly speaking, I understand most of this, but some concepts are still a bit rusty... Explaining them may be out of the scope of this article, so I'll definitely learn them when I get into NoSQL DBs. 😃

[Pablo Curell Mompo](https://hashnode.com/@pcurell)

[Mar 18, 2022](https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083/comment/62342e8dbef4c71aa6f0d880)

Hey :)

Good article explaining the how, but I am left curious about the why :/

Why would you use a dynamoDB for relational data in lieu of just a relational database?

[Stefan Olaru](https://hashnode.com/@stefanolaru)

[Mar 18, 2022](https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083/comment/62342e8dbef4c71aa6f0d880#reply-62343802bef4c71aa6f0d9a9)

Hey Pablo,

I picked DynamoDB because of the flexible schema and scalability, and it's also very Serverless-friendly. As a plus, the on-demand pricing worked better for my use case.

When a relational database makes more sense, use that by all means.

[Pablo Curell Mompo](https://hashnode.com/@pcurell)

[Mar 18, 2022](https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083/comment/62342e8dbef4c71aa6f0d880#reply-623438646647c71acb64140c)

[Stefan Olaru](https://hashnode.com/@stefanolaru)

Ok, thanks for answering :)

[Mahavir Vataliya](https://hashnode.com/@mahavirvataliya)

[Mar 18, 2022](https://hashnode.com/posts/how-to-model-relational-data-in-dynamodb/622f167d38e0a0d99d32f083/comment/62342ce06647c71acb641273)

Best Article to start with dynamoDB Database design.
