
Components of DynamoDB
Tables, Items, and Attributes
Tables in DynamoDB function similarly to tables in a relational database—they act as collections where data is stored. Each table contains multiple items, with each item representing a single entry (such as a user or a product). Items are composed of attributes that are analogous to columns in a relational database.
Primary Keys
Every item in a DynamoDB table is uniquely identified by a primary key. There are two types of primary keys in DynamoDB:- Simple Primary Key (Partition Key): Consists of a single attribute.
- Composite Primary Key: Consists of both a partition key and a sort key, ensuring uniqueness across the table by combining these attributes.
PersonID attribute serves as the primary key, ensuring that each person is uniquely identified. It is important to avoid using non-unique attributes (e.g., first names) as primary keys.
For tables with composite primary keys, DynamoDB uses the partition key to determine the physical storage location (via an internal hash function) and stores items with the same partition key in order, sorted by the sort key. This design allows multiple items to share the same partition key as long as their sort key values differ.
Composite Primary Key Example
Consider a music table that stores information about different songs. In this table, a composite primary key is defined by the combination of the artist and the song title. This uniqueness ensures that while an artist can have multiple songs—and different artists might have songs with the same title—the combination always remains unique.Secondary Indexes
Secondary indexes enable alternative query paths using non-primary key attributes. DynamoDB supports two types of secondary indexes:- Global Secondary Index (GSI): Features a partition key and an optional sort key that can differ from the table’s primary key attributes.
- Local Secondary Index (LSI): Uses the same partition key as the base table but requires a different sort key.

DynamoDB Streams
DynamoDB Streams is an optional feature that captures data modification events in near-real time. Every modification—whether an insert, update, or delete—creates a stream record that includes details such as the table name, timestamp, and a snapshot of the item. For example, when a new item is added to the table, DynamoDB Streams captures the complete image of the new item. Similarly, for an update, the stream records both the before and after images. When an item is deleted, the stream captures its pre-deletion image. Each stream record is retained for 24 hours. You can integrate DynamoDB Streams with AWS Lambda to trigger code execution in response to these events. For instance, in a customer table, a Lambda function could be triggered to send a welcome email whenever a new customer is added.Table Classes and Capacity Modes
DynamoDB offers two table classes for optimizing cost and performance:- Standard Table Class: The default option suitable for most workloads.
- Standard-Infrequent Access (Standard-IA): Designed for scenarios where storage cost is significant and data is accessed less frequently (e.g., application logs or historical records).
- Provisioned Mode: Requires capacity planning for predictable workloads.
- On-Demand Mode: Automatically scales capacity using a pay-per-read/write model, ideal for unpredictable workloads.

Key Features and Integrations
DynamoDB supports both key-value and document data models, offering a flexible schema that easily adapts to changing application requirements without the need for pre-defining a schema before data insertion.One of DynamoDB’s most impressive features is its serverless nature. With no servers to provision, patch, or manage, DynamoDB offers on-demand pricing with auto-scaling and maintains high availability even during unexpected traffic surges.
- Secondary Indexes: Provide additional query flexibility beyond the primary key.
- On-Demand Backup and Restore: Allow full backups of your tables at any time.
- Read/Write Capacity Modes: Offer both provisioned and on-demand throughput configurations.
- Integrations: Seamlessly integrate with AWS services such as Amazon S3, AWS Glue, Amazon Kinesis Data Streams, CloudWatch, and CloudTrail to support data streaming, monitoring, logging, and long-term data archiving.


Use Cases
DynamoDB is versatile and can be applied to a wide range of scenarios. It is particularly well-suited for:- High-concurrency, internet-scale applications that handle millions of requests per second.
- Applications managing user-generated content, metadata, and caching.
- Real-time video streaming and interactive content platforms due to its low-latency and multi-region replication features.
DynamoDB’s ability to handle unpredictable workloads and scale seamlessly makes it an excellent choice for applications with rapidly changing data access patterns and extensive read/write demands.
Summary
DynamoDB is a fully managed NoSQL database service by AWS that delivers fast, predictable performance and seamless scalability. Its key components include:- Tables: The primary data storage units.
- Items: Individual entries within each table.
- Attributes: The properties or fields of an item.
- Primary Keys: Unique identifiers for items, which can be either simple or composite (combining a partition key and a sort key).
- Secondary Indexes: Global and local indexes that extend query flexibility.
- Table Classes: Options include Standard and Standard-IA, allowing cost and performance optimization based on access patterns.
- Capacity Modes: Provisioned for predictable workloads or on-demand for unpredictable workloads.
