What is Amazon DynamoDB?
Amazon DynamoDB is a fully managed, serverless, NoSQL key-value and document database designed for high-performance applications at any scale. It offers built-in security, continuous backups, and automated multi-region replication.
Key Concepts
1. NoSQL Database
- Unlike Relational Databases (RDS), DynamoDB is non-relational.
- It uses Tables, Items, and Attributes.
- Schema-less: Different items in the same table can have different attributes (except for the Primary Key).
2. Primary Keys
- Partition Key (PK): Determines the partition where the item is stored. Must be unique if no Sort Key is used.
- Composite Key (Partition Key + Sort Key): Allows multiple items with the same PK but different Sort Keys (e.g., PK=UserID, SK=Timestamp).
3. Read/Write Capacity Modes
- On-Demand Mode: Pay per request. Best for unpredictable or spiky workloads. No capacity planning needed.
- Provisioned Mode: You specify the number of reads/writes per second (RCU/WCU). Best for predictable traffic. Cheaper if you know your usage.
4. Global Tables
- Automated multi-region replication.
- Provides 99.999% availability.
- Active-Active replication (you can write to the table in any region).
5. DynamoDB Streams
- Captures a time-ordered sequence of item-level modifications (insert, update, delete).
- Commonly used to trigger Lambda functions for post-processing.
6. DAX (DynamoDB Accelerator)
- A fully managed, in-memory cache for DynamoDB.
- Improves performance from milliseconds to microseconds.
Exam Tips
[!IMPORTANT] NoSQL vs SQL:
- If the question asks for a "relational database" or "complex joins", use RDS or Aurora.
- If the question asks for "key-value", "NoSQL", "single-digit millisecond latency", or "massive scale", use DynamoDB.
[!WARNING] DynamoDB is Serverless. You do not manage instances.
[!NOTE] If you need to cache DynamoDB data to get microsecond latency, use DAX.
Common Use Cases
- Mobile/Web Backends: User profiles, shopping carts, game states.
- Serverless Architectures: Perfectly pairs with AWS Lambda.
- High-Traffic Apps: Voting systems, ride-sharing apps, ad-tech data.
- Inventory Tracking: Real-time inventory management.