Amazon DynamoDB Fundamentals
What you'll learn: Understand DynamoDB's NoSQL structure, key architecture, and how tables organize data using primary keys.
What is DynamoDB?
Amazon DynamoDB is a fully managed NoSQL database service designed for serverless architectures. Unlike traditional relational databases with rigid schemas and tables joined by foreign keys, DynamoDB stores data as flexible JSON-like documents called items in tables. Think of it like a massive, infinitely expandable filing cabinet where each drawer (partition) can grow independently.
Core Components
Tables and Items
A table is a collection of data. Each record is an item (similar to a row), containing one or more attributes (similar to columns). Unlike SQL, items in the same table can have different attributes—no fixed schema required.
Primary Keys
Every item must have a primary key, which uniquely identifies it. Two types exist:
Partition Key (Simple Primary Key): A single attribute that DynamoDB uses to distribute data across partitions. Example: userId in a users table.
Composite Primary Key (Partition Key + Sort Key): Combines two attributes. Items with the same partition key are stored together but sorted by the sort key. Example: userId (partition) + timestamp (sort) for user activity logs.
How Partitioning Works
DynamoDB uses the partition key's value in a hash function to determine which physical partition stores the item. This enables automatic horizontal scaling. The sort key lets you efficiently query ranges within a partition.
Basic Operations
PutItem: Create or replace an itemGetItem: Retrieve by primary keyQuery: Fetch items with a specific partition key (optionally filtered by sort key)Scan: Read entire table (expensive—avoid in production)
Key Takeaway: DynamoDB's power lies in its partition-based architecture—choose partition keys that distribute data evenly and support your access patterns for optimal performance.