Skip to main content
In this lesson we cover Amazon DynamoDB — a fully managed, serverless NoSQL database from AWS designed for low-latency access, seamless scaling, and high availability. You’ll learn core concepts, data modeling patterns, indexing options, stream processing, cost-optimization choices, and common integrations.
DynamoDB is intended for high-traffic, rapidly changing workloads where predictable low-latency access and minimal operational overhead are required. Use it for user profiles, session stores, leaderboards, real-time analytics metadata, and other internet‑scale applications.
A presentation slide titled "Why do we need DynamoDB?" showing an Amazon DynamoDB icon and a NoSQL icon, plus five benefit icons labeled Managing and Scaling, Serverless, Handle High Traffic, Automatic Sharding, and Operations. The slide is © KodeKloud.
Why use DynamoDB?
  • Fully managed and serverless: no servers to provision or maintain.
  • Seamless scaling and automatic sharding for large data sets.
  • Low-latency single-digit millisecond reads/writes.
  • Durable and highly available with integrated backups, replication, and recovery options.
Because DynamoDB is a managed AWS service, AWS handles the underlying compute and storage resources, patching, fault tolerance, and capacity distribution so you can concentrate on application logic.

Core concepts

  • Table — the primary container for items.
  • Item — a single record (JSON-like document).
  • Attribute — a named field in an item (scalar or nested).
Example: People table (schema-less items)

Primary key design

Every DynamoDB table requires a primary key that uniquely identifies each item. Primary keys determine how data is partitioned and organized. For the People table above, PersonID is a good partition key. Avoid using non-unique attributes (e.g., FirstName) as a primary key. DynamoDB uses the partition key value as input to an internal hash function. When using a composite key, the partition key determines the physical partition while the sort key orders and scopes items within that partition.
Primary key selection is critical for performance and scalability. Choose partition keys that distribute traffic evenly (avoid “hot” partition keys) and use sort keys to model access patterns (ranges, time series, or aggregated grouping).
A diagram titled "DynamoDB – Composite Primary Key" showing a composite primary key broken into two attributes: the first attribute maps to the partition key and the second attribute maps to the sort key.
Example: Music table using a composite primary key The Music table uses Artist (partition key) + SongTitle (sort key). This lets you fetch all songs by an artist or filter songs within a title range.
Query patterns enabled by a composite key:
  • Query all items with a specific Artist.
  • Query items for Artist with range filters on SongTitle (e.g., between “A” and “M”).

Secondary indexes

Secondary indexes let you query the table using different keys than the primary key, providing flexible access patterns. Limits: up to 20 GSIs and 5 LSIs per table.
A diagram titled "Secondary Index" showing Amazon DynamoDB flowing into a Table and then an Index. The index branches to boxes for Global Secondary Index and Local Secondary Index with notes about partition/sort key differences and item limits.
Index example (GSI: GenreAlbumTitle) Suppose you need queries by Genre and AlbumTitle. Create a GSI named GenreAlbumTitle:
  • Genre = partition key for the index
  • AlbumTitle = sort key for the index
DynamoDB automatically projects key attributes from the base table to the index; you can choose to project additional attributes. The index stays in sync: updates, inserts, and deletes in the base table are reflected in the index. Example items as they appear in the GenreAlbumTitle index:

DynamoDB Streams

DynamoDB Streams capture data modification events (INSERT, MODIFY, REMOVE) and expose them as an ordered stream for up to 24 hours. Each stream record includes metadata and item image(s) depending on the event type. Typical stream record images:
  • INSERT — the entire new item image.
  • MODIFY — the before and after images of the changed item.
  • REMOVE — the entire item image before deletion.
A common architecture is to connect a DynamoDB Stream to an AWS Lambda function for near real-time processing (e.g., send welcome emails when a new customer item has an EmailAddress). INSERT example
MODIFY example (before and after)
REMOVE example
Useful integrations for streams:
  • Trigger AWS Lambda functions for event-driven workflows.
  • Send events to Kinesis Data Streams for complex real-time processing.

Table classes and capacity modes

DynamoDB provides options to balance cost and performance. All secondary indexes inherit the base table’s table class. You can change table class and capacity mode from the Console, CLI, or SDK.

Key features at a glance

  • Flexible data models: key-value and document.
  • Serverless operation and automatic partitioning.
  • On-demand and provisioned capacity modes.
  • Secondary indexes (GSI, LSI) for alternate query patterns.
  • On-demand backup & restore and point-in-time recovery.
  • Global tables for active-active multi‑Region workloads.
  • Integration with analytics and streaming services.
A presentation slide titled "DynamoDB – Features." It displays seven numbered feature cards with colorful icons, listing items like Key‑Value/Document Data Models, Serverless, Global Tables, Secondary Indexes, On‑Demand Backup & Restore, and Read/Write Capacity Modes.

Integrations and analytics

DynamoDB works with many AWS services to enable analytics, streaming, and monitoring:
  • Streams → AWS Lambda for event-driven processing. See: AWS Lambda
  • Export to Amazon S3 for archival and downstream analysis. See: Amazon S3
  • Use AWS Glue, Amazon Athena, or Amazon Redshift for analytics and ETL.
  • Monitor with Amazon CloudWatch and audit with AWS CloudTrail.
  • Stream to Amazon Kinesis Data Streams for real-time analytics.
A diagram of Amazon DynamoDB integrations: the left side shows the DynamoDB icon and a “Configure Key Features” list (NoSQL workbench, encryption at rest, on‑demand capacity, global tables, point‑in‑time recovery, PartiQL). The center/right show exporting/analyzing/streaming data to AWS services like Amazon S3, AWS Glue Elastic Views, Amazon Kinesis Data Streams, AWS CloudTrail, and Amazon CloudWatch.

Common use cases

  • Internet-scale user profiles, shopping carts, and metadata storage.
  • Real-time applications: gaming leaderboards, chat/message metadata, streaming metadata.
  • Session stores and caching with consistently low latency.
  • Event-driven architectures using Streams + Lambda for near-real-time workflows.

Summary

DynamoDB is a fully managed NoSQL database optimized for performance and scalability. Key takeaways:
  • Core entities are tables, items, and attributes.
  • Choose primary keys carefully: partition key or partition+sort key (composite).
  • Use GSIs and LSIs to support alternate query patterns.
  • DynamoDB Streams enable near real-time processing; stream records are retained for 24 hours.
  • Use table classes and capacity modes to optimize cost and performance for your workload.
A presentation slide titled "Summary DynamoDB" with a turquoise left panel and bullet points on the right explaining secondary indexes (GSI, LSI) and table classes (Standard, Standard-IA, On-Demand). The slide includes numbered icons for sections and a small copyright notice.

Watch Video