Skip to main content
InterviewHubPRO
Section Overview
Q24

Question 24 of 50

Part 3: Advanced Architecture, Scale & Internals (Senior / Lead)

48%
Amazon DynamoDB (50 Qs)•Part 3: Advanced Architecture, Scale & Internals (Senior / Lead)

How do you model Many-to-Many relationships in DynamoDB?

senior LevelSystem DesignDynamoDB

In Simple Words: Modeled using an Adjacency List pattern via Global Secondary Indexes:

  • Example: Students and Classes:
    • Base Table: PK = "STUDENT#1", SK = "CLASS#Math"
    • GSI1: Invert keys: GSI1_PK = SK ("CLASS#Math"), GSI1_SK = PK ("STUDENT#1")
  • To list all classes for a student: Query base table where PK = "STUDENT#1".
  • To list all students in a class: Query GSI1 where GSI1_PK = "CLASS#Math".