CHAPTER 14
Beginner
AWS DynamoDB Basics
Updated: May 15, 2026
25 min read
# CHAPTER 14
AWS DynamoDB Basics
1. Introduction
Relational databases (like MySQL in RDS) are rigid. They require strict tables, columns, and relationships. If you want to store a billion records and retrieve one in under 5 milliseconds, a traditional SQL database will struggle as it grows. For hyper-scale, unstructured data, AWS provides Amazon DynamoDB—a fully managed, serverless, NoSQL database designed to deliver single-digit millisecond performance at absolutely any scale.2. Learning Objectives
By the end of this chapter, you will be able to:- Contrast Relational (SQL) and Non-Relational (NoSQL) databases.
- Understand the core components of DynamoDB (Tables, Items, Attributes).
- Define Partition Keys and Sort Keys.
- Understand DynamoDB's Serverless nature.
- Identify common use cases for DynamoDB.
3. Beginner-Friendly Explanation
Imagine a strict filing cabinet vs. a flexible sticky note wall.- SQL (RDS): A rigid filing cabinet. Every folder *must* have exactly a Name, Age, and Email. If you try to add a folder with a "Phone Number," the cabinet rejects it because the column doesn't exist. You have to shut down the cabinet, redesign the metal frame, and restart it.
- NoSQL (DynamoDB): A massive wall of sticky notes. Each sticky note just needs a unique ID number. Beyond that, you can write anything you want. Note 1 has a Name and Age. Note 2 has a Name and a list of Favorite Movies. The database doesn't care. It is infinitely flexible.
4. DynamoDB Components
DynamoDB uses different terminology than SQL:- Table: The collection of data (Similar to a SQL Table).
- Item: A single record in the table (Similar to a SQL Row).
- Attribute: A piece of data attached to the item (Similar to a SQL Column, but they are completely dynamic and can vary per item!).
5. Primary Keys (The Most Critical Concept)
Because DynamoDB stores data across thousands of hidden physical servers, it needs a way to instantly locate your data. You MUST define a Primary Key when creating a table.There are two types:
-
1.
Partition Key (Single Key): A unique identifier, like a
UserID. DynamoDB uses this ID in a hashing algorithm to determine exactly which physical server holds the data. It enables instant lookups.
- 2. Partition Key + Sort Key (Composite Key): Used for querying related items.
-
*Example:* An e-commerce orders table. The Partition Key is
UserIDand the Sort Key isOrderDate. This allows you to instantly ask: "Find all orders for User 42 (Partition Key), sorted by Date (Sort Key)."
6. The Serverless Advantage
DynamoDB is completely Serverless. With RDS, you have to provision an EC2-like instance (db.t3.micro). You pay for it even if no one is using the database.
With DynamoDB, there are no servers to manage. You simply create a table and start throwing data at it. You pay purely for the Storage (GBs) and the exact number of Read/Write requests you make. It scales from 0 to 1 million requests per second automatically.
7. Mini Project: Build a Simple DynamoDB Table
Let's create a serverless NoSQL table.Step-by-Step Tutorial:
- 1. Open the AWS Console and search for DynamoDB.
- 2. Click Create table.
-
3.
Table name: Enter
MusicLibrary.
-
4.
Partition key: Enter
Artist(String).
-
5.
Sort key: Enter
SongTitle(String).
- 6. Leave the rest as Default settings and click Create table.
- 7. Once active, click into the table and select Explore table items.
- 8. Click Create item.
-
9.
For Artist, type
The Beatles. For SongTitle, typeHey Jude.
-
10.
Click Add new attribute -> String. Name it
Genreand valueRock.
- 11. Click Create item.
-
12.
Create a second item: Artist:
The Beatles, SongTitle:Let It Be. Add a *different* attribute:YearReleased(Number):1970.
*Notice how Item 1 has a "Genre" but no "Year", and Item 2 has a "Year" but no "Genre". This is the flexibility of NoSQL!*
8. Best Practices
-
Understand Data Access Patterns: In SQL, you build normalized tables and use complex
JOINqueries to fetch data later. In DynamoDB,JOINoperations do not exist! You must design your Partition/Sort keys based *exactly* on how your application will query the data.
9. Common Mistakes
- The "Scan" Operation: If you ask DynamoDB to find an item using the Partition Key (a "Query"), it takes 2 milliseconds. If you ask it to find an item based on a random attribute (e.g., "Find all users whose favorite color is Blue"), DynamoDB has to perform a "Scan." It will read every single item in the entire table to find the blue ones. Scans are incredibly slow and will cost you massive amounts of money on large tables. Always use Queries!
10. Exercises
- 1. Contrast a DynamoDB "Item" with a SQL "Row". What is the primary structural difference regarding attributes?
- 2. Why is performing a "Scan" operation in DynamoDB discouraged for large datasets?
11. MCQs with Answers
Question 1
A gaming company needs a highly scalable database to store player high scores. The database must handle millions of unpredictable read/write requests per second with single-digit millisecond latency, without requiring the team to manage underlying servers. Which AWS service is best suited?
Question 2
When designing a DynamoDB table, which component acts as the mandatory unique identifier used by the internal hashing algorithm to distribute data across physical servers?
12. Interview Questions
- Q: Explain the fundamental differences between Amazon RDS and Amazon DynamoDB. In what specific architectural scenario would you advocate for NoSQL over a Relational SQL database?
- Q: Detail the difference between a DynamoDB "Query" and a "Scan". Why is understanding data access patterns prior to table creation critical in DynamoDB?