DatabasesAdvancedplaybook

DynamoDB Single Table Design: Advanced Modeling Patterns

Master the art of Single Table Design in DynamoDB. Learn how to model 1:N and M:N relationships using GSI overloading and adjacency lists.

Sachin SarawgiApril 20, 20262 min read2 minute lesson
Recommended Prerequisites
NoSQL Schema Evolution: Strategies for Zero-Downtime Data Growth

DynamoDB Single Table Design: The Senior Engineer's Guide

Single Table Design is often considered the "Holy Grail" of DynamoDB modeling. Instead of creating a table for every entity, you store multiple entity types in a single table, using generic primary keys like PK and SK.

Why Single Table Design?

  1. Performance: You can fetch an entity and all its related items (e.g., an Order and its OrderItems) in a single Query call.
  2. Cost: Reduces the overhead of managing multiple tables and their individual provisioned throughput.
  3. Simplicity: One table to monitor, backup, and scale.

The Core Concept: Generic PK/SK

Instead of user_id or order_id, we use:

  • PK (Partition Key): e.g., USER#123 or ORDER#ABC
  • SK (Sort Key): e.g., METADATA or ITEM#456

Modeling Relationships

1. One-to-Many (1:N)

To store a User and their many Addresses:

  • User Item: PK=USER#123, SK=METADATA
  • Address Item: PK=USER#123, SK=ADDR#789

By calling Query(PK='USER#123'), you get the user profile and all their addresses in one shot.

2. Many-to-Many (M:N)

To store Students and their Courses, we use an Adjacency List pattern:

  • Student-Course Link: PK=STUDENT#1, SK=COURSE#MATH
  • Course-Student Link (via GSI): We create a GSI where the SK is the Partition Key. This allows us to query "All courses for a student" and "All students for a course."

GSI Overloading

GSI Overloading is the secret sauce. You can use the same GSI columns (GSI1_PK, GSI1_SK) to store different attributes depending on the entity type. This prevents you from hitting the 20 GSI limit per table.

When NOT to use Single Table Design

  • Analytics: If you need to perform ad-hoc scans across the entire dataset.
  • Varying Access Patterns: If your access patterns change frequently, a rigid single table can become a maintenance nightmare.
  • Exporting to Data Lake: Multi-table designs are often easier to process in Glue/Athena.

Summary

Single Table Design is about shifting the complexity from the database engine to your application logic. By pre-joining your data at write time, you achieve the massive, consistent scale that DynamoDB is famous for.

Learning Path: Databases Track

Keep the momentum going

Step 17 of 54: Your next milestone in this track.

Next Article

NEXT UP

The Expand-Contract Pattern: Zero-Downtime Database Schema Changes

1 min readAdvanced

📚

Recommended Resources

Designing Data-Intensive ApplicationsBest Seller

The definitive guide to building scalable, reliable distributed systems by Martin Kleppmann.

View on Amazon
Kafka: The Definitive GuideEditor's Pick

Real-time data and stream processing by Confluent engineers.

View on Amazon
Apache Kafka Series on Udemy

Hands-on Kafka course covering producers, consumers, Kafka Streams, and Connect.

View Course

Practical engineering notes

Get the next backend guide in your inbox

One useful note when a new deep dive is published: system design tradeoffs, Java production lessons, Kafka debugging, database patterns, and AI infrastructure.

No spam. Just practical notes you can use at work.

Sachin Sarawgi

Written by

Sachin Sarawgi

Engineering Manager and backend engineer with 10+ years building distributed systems across fintech, enterprise SaaS, and startups. CodeSprintPro is where I write practical guides on system design, Java, Kafka, databases, AI infrastructure, and production reliability.

Keep Learning

Move through the archive without losing the thread.

Related Articles

More deep dives chosen from shared tags, category overlap, and reading difficulty.

More in Databases

Category-based suggestions if you want to stay in the same domain.