DynamoDB

DynamoDB 

Amazon DynamoDB is a fully-managed, serverless, NoSQL database service offered by AWS that delivers single-digit millisecond performance at any scale. It supports document and key-value data structures and automatically handles partitioning, replication, scaling, durability, and availability. DynamoDB is widely used for mission-critical workloads, real-time applications, mobile backends, microservices, serverless architectures, and high-performance distributed systems.

This detailed guide explores DynamoDB concepts, components, API operations, partitioning logic, consistency models, indexing, security, pricing, hands-on examples, and best practices. The content is structured with SEO-optimized keywords such as β€œDynamoDB tutorial”, β€œWhat is DynamoDB”, β€œDynamoDB architecture”, β€œDynamoDB vs RDS”, β€œDynamoDB query examples”, β€œDynamoDB partition key”, β€œDynamoDB GSI”, β€œDynamoDB performance tuning”, and more.

1. Introduction to Amazon DynamoDB

DynamoDB is a NoSQL database designed to deliver consistent low-latency responses for applications. It automatically scales up and down based on workload demands and distributes data across partitions to maintain performance. As a serverless database, DynamoDB abstracts infrastructure management, allowing developers to focus solely on application logic.

1.1 Characteristics of DynamoDB

  • Serverless – No servers to manage
  • NoSQL – Key-value and document model
  • Highly available – Multi-AZ replication by default
  • Automatic sharding/partitioning
  • High throughput and low latency
  • Event-driven integrations (via DynamoDB Streams)
  • On-demand or provisioned capacity modes
  • Supports transactions (ACID compliance)

1.2 Cases of DynamoDB

  • Real-time bidding platforms
  • E-commerce catalogs
  • Gaming leaderboards
  • IoT device metadata storage
  • Session management
  • Serverless applications (Lambda + DynamoDB)
  • Social media apps (likes, followers, messages)

2. DynamoDB Core Concepts

2.1 Tables

DynamoDB stores data in tables, similar to relational databases but without fixed schemas. Items in a table may have different attributes.

2.2 Items

An item is a record in DynamoDB, analogous to a row. Items are stored as JSON-like attribute-value pairs.

2.3 Attributes

Attributes are key-value pairs inside an item. DynamoDB supports the following data types:

  • Scalar types – String, Number, Binary, Boolean
  • Document types – Map, List
  • Set types – String Set, Number Set, Binary Set

2.4 Primary Key

Each DynamoDB table requires a primary key which uniquely identifies each item. Two types:

a) Partition Key only (Simple Primary Key)

Items are distributed based on the partition key value.

b) Partition Key + Sort Key (Composite Primary Key)

Allows multiple items with the same partition key but different sort keys.

2.5 Partitioning

DynamoDB uses a partitioning algorithm to determine where items are physically stored. The partition key is hashed to determine the storage partition. Hot partitions occur if one partition key receives too many requests, affecting performance.

2.6 Provisioned vs On-Demand Capacity

DynamoDB supports two capacity models:

On-Demand

  • Pay-per-request
  • No capacity planning needed
  • Best for unpredictable workloads

Provisioned

  • Set read and write capacity (RCU/WCU)
  • Auto scaling available
  • Cheaper for predictable workloads

3. DynamoDB Read and Write Operations

3.1 Read Consistency Modes

Eventually Consistent Reads

The default read mode. Data may take a short time to replicate across partitions.

Strongly Consistent Reads

Returns the latest data but only available in single-region tables.

3.2 Write Operations

DynamoDB provides four main write APIs:

  • PutItem
  • UpdateItem
  • DeleteItem
  • BatchWriteItem

4. Indexes in DynamoDB

4.1 Local Secondary Index (LSI)

LSI uses the same partition key as the base table but with a different sort key. It allows the creation of alternate views of data at query time.

4.2 Global Secondary Index (GSI)

GSI allows you to define an alternative partition key and sort key. GSIs support high-speed queries without scanning the entire table.

4.3 GSI vs LSI

  • GSI can have different partition keys; LSI cannot
  • GSI has separate throughput capacity
  • LSI limited to 5 per table; no limit for GSIs

5. DynamoDB Streams

DynamoDB Streams captures item-level changes and stores them for 24 hours. Streams enable event-driven architectures and seamless integrations with AWS Lambda.

Uses of DynamoDB Streams

  • Triggering AWS Lambda functions
  • Implementing real-time analytics
  • Data replication across regions
  • Change data capture (CDC)

6. DynamoDB Security

6.1 Authentication & Authorization

DynamoDB uses AWS IAM for access control. Fine-grained access control (FGAC) enables item-level permissions.

6.2 Encryption

  • Encryption at Rest (default using KMS)
  • In-transit encryption using HTTPS/TLS

6.3 Backup Options

  • Point-in-Time Recovery (PITR)
  • On-demand backup & restore

7. DynamoDB Pricing

DynamoDB pricing depends on various components:

  • Read Capacity Units (RCU)
  • Write Capacity Units (WCU)
  • Data storage
  • On-Demand mode pricing
  • Streams
  • DAX caching

8. Hands-On DynamoDB Examples

8.1 Create a DynamoDB Table (CLI)


aws dynamodb create-table \
  --table-name Students \
  --attribute-definitions \
      AttributeName=StudentID,AttributeType=S \
      AttributeName=CourseID,AttributeType=S \
  --key-schema \
      AttributeName=StudentID,KeyType=HASH \
      AttributeName=CourseID,KeyType=RANGE \
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

8.2 Insert an Item


aws dynamodb put-item \
  --table-name Students \
  --item '{
      "StudentID": {"S": "101"},
      "CourseID": {"S": "AWS101"},
      "Name": {"S": "Rahul"},
      "Score": {"N": "95"}
  }'

8.3 Query Items


aws dynamodb query \
  --table-name Students \
  --key-condition-expression "StudentID = :id" \
  --expression-attribute-values  '{":id":{"S":"101"}}'

8.4 Scan Table


aws dynamodb scan --table-name Students

8.5 Update an Item


aws dynamodb update-item \
  --table-name Students \
  --key '{
      "StudentID": {"S": "101"},
      "CourseID": {"S": "AWS101"}
  }' \
  --update-expression "SET Score = :newScore" \
  --expression-attribute-values '{":newScore":{"N":"98"}}'

8.6 Delete an Item


aws dynamodb delete-item \
  --table-name Students \
  --key '{"StudentID": {"S":"101"}, "CourseID": {"S":"AWS101"}}'

9. DynamoDB Accelerator (DAX)

DAX is a fully managed, in-memory caching layer for DynamoDB, improving read performance by up to 10x and reducing read latency to microseconds.

DAX Benefits

  • Microsecond read latency
  • Reduces DynamoDB read costs
  • Fully managed, fault-tolerant

10. DynamoDB Global Tables

Global tables enable multi-region, fully replicated DynamoDB tables for global applications. They allow low-latency reads and writes across regions.

Benefits

  • High availability
  • Disaster recovery
  • Low-latency global access

11. DynamoDB vs Other Databases

11.1 DynamoDB vs RDS

DynamoDB RDS
NoSQL Relational
Horizontal scaling Vertical scaling
Serverless Managed service (but with servers)
Flexible schema Fixed schema

11.2 DynamoDB vs MongoDB

  • DynamoDB is serverless; MongoDB requires cluster management
  • DynamoDB integrates with AWS services more tightly

12. DynamoDB

12.1 Use High-Cardinality Partition Keys

This avoids hot partitions and improves performance.

12.2 Prefer Queries over Scans

Scans read the entire table and are slow and expensive.

12.3 Use GSIs for Flexible Queries

Design item access patterns using GSIs instead of scanning the full table.

12.4 Enable Auto Scaling

Ensures that read/write capacity meets demand.

12.5 Enable PITR (Point-in-Time Recovery)

Protects against accidental deletions or corruption.

12.6 Use DAX for Read-Heavy Workloads

Improves performance drastically.

Amazon DynamoDB is a powerful, serverless NoSQL database that delivers extremely high scalability, performance, and flexibility. Its features like automatic sharding, global tables, DAX caching, GSIs, LSIs, and integration with Lambda make it ideal for modern cloud-native and real-time applications. Understanding DynamoDB’s key concepts, capacity modes, partitioning strategies, and best practices helps developers design efficient, cost-effective, and highly scalable systems.

logo

AWS

Beginner 5 Hours

DynamoDB 

Amazon DynamoDB is a fully-managed, serverless, NoSQL database service offered by AWS that delivers single-digit millisecond performance at any scale. It supports document and key-value data structures and automatically handles partitioning, replication, scaling, durability, and availability. DynamoDB is widely used for mission-critical workloads, real-time applications, mobile backends, microservices, serverless architectures, and high-performance distributed systems.

This detailed guide explores DynamoDB concepts, components, API operations, partitioning logic, consistency models, indexing, security, pricing, hands-on examples, and best practices. The content is structured with SEO-optimized keywords such as “DynamoDB tutorial”, “What is DynamoDB”, “DynamoDB architecture”, “DynamoDB vs RDS”, “DynamoDB query examples”, “DynamoDB partition key”, “DynamoDB GSI”, “DynamoDB performance tuning”, and more.

1. Introduction to Amazon DynamoDB

DynamoDB is a NoSQL database designed to deliver consistent low-latency responses for applications. It automatically scales up and down based on workload demands and distributes data across partitions to maintain performance. As a serverless database, DynamoDB abstracts infrastructure management, allowing developers to focus solely on application logic.

1.1 Characteristics of DynamoDB

  • Serverless – No servers to manage
  • NoSQL – Key-value and document model
  • Highly available – Multi-AZ replication by default
  • Automatic sharding/partitioning
  • High throughput and low latency
  • Event-driven integrations (via DynamoDB Streams)
  • On-demand or provisioned capacity modes
  • Supports transactions (ACID compliance)

1.2 Cases of DynamoDB

  • Real-time bidding platforms
  • E-commerce catalogs
  • Gaming leaderboards
  • IoT device metadata storage
  • Session management
  • Serverless applications (Lambda + DynamoDB)
  • Social media apps (likes, followers, messages)

2. DynamoDB Core Concepts

2.1 Tables

DynamoDB stores data in tables, similar to relational databases but without fixed schemas. Items in a table may have different attributes.

2.2 Items

An item is a record in DynamoDB, analogous to a row. Items are stored as JSON-like attribute-value pairs.

2.3 Attributes

Attributes are key-value pairs inside an item. DynamoDB supports the following data types:

  • Scalar types – String, Number, Binary, Boolean
  • Document types – Map, List
  • Set types – String Set, Number Set, Binary Set

2.4 Primary Key

Each DynamoDB table requires a primary key which uniquely identifies each item. Two types:

a) Partition Key only (Simple Primary Key)

Items are distributed based on the partition key value.

b) Partition Key + Sort Key (Composite Primary Key)

Allows multiple items with the same partition key but different sort keys.

2.5 Partitioning

DynamoDB uses a partitioning algorithm to determine where items are physically stored. The partition key is hashed to determine the storage partition. Hot partitions occur if one partition key receives too many requests, affecting performance.

2.6 Provisioned vs On-Demand Capacity

DynamoDB supports two capacity models:

On-Demand

  • Pay-per-request
  • No capacity planning needed
  • Best for unpredictable workloads

Provisioned

  • Set read and write capacity (RCU/WCU)
  • Auto scaling available
  • Cheaper for predictable workloads

3. DynamoDB Read and Write Operations

3.1 Read Consistency Modes

Eventually Consistent Reads

The default read mode. Data may take a short time to replicate across partitions.

Strongly Consistent Reads

Returns the latest data but only available in single-region tables.

3.2 Write Operations

DynamoDB provides four main write APIs:

  • PutItem
  • UpdateItem
  • DeleteItem
  • BatchWriteItem

4. Indexes in DynamoDB

4.1 Local Secondary Index (LSI)

LSI uses the same partition key as the base table but with a different sort key. It allows the creation of alternate views of data at query time.

4.2 Global Secondary Index (GSI)

GSI allows you to define an alternative partition key and sort key. GSIs support high-speed queries without scanning the entire table.

4.3 GSI vs LSI

  • GSI can have different partition keys; LSI cannot
  • GSI has separate throughput capacity
  • LSI limited to 5 per table; no limit for GSIs

5. DynamoDB Streams

DynamoDB Streams captures item-level changes and stores them for 24 hours. Streams enable event-driven architectures and seamless integrations with AWS Lambda.

Uses of DynamoDB Streams

  • Triggering AWS Lambda functions
  • Implementing real-time analytics
  • Data replication across regions
  • Change data capture (CDC)

6. DynamoDB Security

6.1 Authentication & Authorization

DynamoDB uses AWS IAM for access control. Fine-grained access control (FGAC) enables item-level permissions.

6.2 Encryption

  • Encryption at Rest (default using KMS)
  • In-transit encryption using HTTPS/TLS

6.3 Backup Options

  • Point-in-Time Recovery (PITR)
  • On-demand backup & restore

7. DynamoDB Pricing

DynamoDB pricing depends on various components:

  • Read Capacity Units (RCU)
  • Write Capacity Units (WCU)
  • Data storage
  • On-Demand mode pricing
  • Streams
  • DAX caching

8. Hands-On DynamoDB Examples

8.1 Create a DynamoDB Table (CLI)

aws dynamodb create-table \ --table-name Students \ --attribute-definitions \ AttributeName=StudentID,AttributeType=S \ AttributeName=CourseID,AttributeType=S \ --key-schema \ AttributeName=StudentID,KeyType=HASH \ AttributeName=CourseID,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

8.2 Insert an Item

aws dynamodb put-item \ --table-name Students \ --item '{ "StudentID": {"S": "101"}, "CourseID": {"S": "AWS101"}, "Name": {"S": "Rahul"}, "Score": {"N": "95"} }'

8.3 Query Items

aws dynamodb query \ --table-name Students \ --key-condition-expression "StudentID = :id" \ --expression-attribute-values '{":id":{"S":"101"}}'

8.4 Scan Table

aws dynamodb scan --table-name Students

8.5 Update an Item

aws dynamodb update-item \ --table-name Students \ --key '{ "StudentID": {"S": "101"}, "CourseID": {"S": "AWS101"} }' \ --update-expression "SET Score = :newScore" \ --expression-attribute-values '{":newScore":{"N":"98"}}'

8.6 Delete an Item

aws dynamodb delete-item \ --table-name Students \ --key '{"StudentID": {"S":"101"}, "CourseID": {"S":"AWS101"}}'

9. DynamoDB Accelerator (DAX)

DAX is a fully managed, in-memory caching layer for DynamoDB, improving read performance by up to 10x and reducing read latency to microseconds.

DAX Benefits

  • Microsecond read latency
  • Reduces DynamoDB read costs
  • Fully managed, fault-tolerant

10. DynamoDB Global Tables

Global tables enable multi-region, fully replicated DynamoDB tables for global applications. They allow low-latency reads and writes across regions.

Benefits

  • High availability
  • Disaster recovery
  • Low-latency global access

11. DynamoDB vs Other Databases

11.1 DynamoDB vs RDS

DynamoDB RDS
NoSQL Relational
Horizontal scaling Vertical scaling
Serverless Managed service (but with servers)
Flexible schema Fixed schema

11.2 DynamoDB vs MongoDB

  • DynamoDB is serverless; MongoDB requires cluster management
  • DynamoDB integrates with AWS services more tightly

12. DynamoDB

12.1 Use High-Cardinality Partition Keys

This avoids hot partitions and improves performance.

12.2 Prefer Queries over Scans

Scans read the entire table and are slow and expensive.

12.3 Use GSIs for Flexible Queries

Design item access patterns using GSIs instead of scanning the full table.

12.4 Enable Auto Scaling

Ensures that read/write capacity meets demand.

12.5 Enable PITR (Point-in-Time Recovery)

Protects against accidental deletions or corruption.

12.6 Use DAX for Read-Heavy Workloads

Improves performance drastically.

Amazon DynamoDB is a powerful, serverless NoSQL database that delivers extremely high scalability, performance, and flexibility. Its features like automatic sharding, global tables, DAX caching, GSIs, LSIs, and integration with Lambda make it ideal for modern cloud-native and real-time applications. Understanding DynamoDB’s key concepts, capacity modes, partitioning strategies, and best practices helps developers design efficient, cost-effective, and highly scalable systems.

Related Tutorials

Frequently Asked Questions for AWS

An AWS Region is a geographical area with multiple isolated availability zones. Regions ensure high availability, fault tolerance, and data redundancy.

AWS EBS (Elastic Block Store) provides block-level storage for use with EC2 instances. It's ideal for databases and other performance-intensive applications.



  • S3: Object storage for unstructured data.
  • EBS: Block storage for structured data like databases.

  • Regions are geographic areas.
  • Availability Zones are isolated data centers within a region, providing high availability for your applications.

AWS pricing follows a pay-as-you-go model. You pay only for the resources you use, with options like on-demand instances, reserved instances, and spot instances to optimize costs.



AWS S3 (Simple Storage Service) is an object storage service used to store and retrieve any amount of data from anywhere. It's ideal for backup, data archiving, and big data analytics.



Amazon RDS (Relational Database Service) is a managed database service supporting engines like MySQL, PostgreSQL, Oracle, and SQL Server. It automates tasks like backups and updates.



  • Scalability: Resources scale based on demand.
  • Cost-efficiency: Pay-as-you-go pricing.
  • Global Reach: Availability in multiple regions.
  • Security: Advanced encryption and compliance.
  • Flexibility: Supports various workloads and integrations.

AWS Auto Scaling automatically adjusts the number of compute resources based on demand, ensuring optimal performance and cost-efficiency.

The key AWS services include:


  • EC2 (Elastic Compute Cloud) for scalable computing.
  • S3 (Simple Storage Service) for storage.
  • RDS (Relational Database Service) for databases.
  • Lambda for serverless computing.
  • CloudFront for content delivery.

AWS CLI (Command Line Interface) is a tool for managing AWS services via commands. It provides scripting capabilities for automation.

Amazon EC2 is a web service that provides resizable compute capacity in the cloud. It enables you to launch virtual servers and manage your computing resources efficiently.

AWS Snowball is a physical device used for data migration. It allows organizations to transfer large amounts of data into AWS quickly and securely.

AWS CloudWatch is a monitoring service that collects and tracks metrics, logs, and events, helping you gain insights into your AWS infrastructure and applications.



AWS (Amazon Web Services) is a comprehensive cloud computing platform provided by Amazon. It offers on-demand cloud services such as compute power, storage, databases, networking, and more.



Elastic Load Balancer (ELB) automatically distributes incoming traffic across multiple targets (e.g., EC2 instances) to ensure high availability and fault tolerance.

Amazon VPC (Virtual Private Cloud) allows you to create a secure, isolated network within the AWS cloud, enabling you to control IP ranges, subnets, and route tables.



Route 53 is a scalable DNS (Domain Name System) web service by AWS. It connects user requests to your applications hosted on AWS resources.

AWS CloudFormation is a service that enables you to manage and provision AWS resources using infrastructure as code. It automates resource deployment through JSON or YAML templates.



AWS IAM (Identity and Access Management) allows you to control access to AWS resources securely. You can define user roles, permissions, and policies to ensure security and compliance.



  • EC2: Provides virtual servers for full control of your applications.
  • Lambda: Offers serverless computing, automatically running your code in response to events without managing servers.

Elastic Beanstalk is a PaaS (Platform as a Service) offering by AWS. It simplifies deploying and managing applications by automatically handling infrastructure provisioning and scaling.



Amazon SQS (Simple Queue Service) is a fully managed message queuing service that decouples and scales distributed systems.

AWS ensures data security through encryption (both at rest and in transit), compliance with standards (e.g., ISO, SOC, GDPR), and access controls using IAM.

AWS Lambda is a serverless computing service that lets you run code in response to events without provisioning or managing servers. You pay only for the compute time consumed.



AWS Identity and Access Management controls user access and permissions securely.

A serverless compute service running code automatically in response to events.

A Virtual Private Cloud for isolated AWS network configuration and control.

Automates resource provisioning using infrastructure as code in AWS.

A monitoring tool for AWS resources and applications, providing logs and metrics.

A virtual server for running applications on AWS with scalable compute capacity.

Distributes incoming traffic across multiple targets to ensure fault tolerance.

A scalable object storage service for backups, data archiving, and big data.

EC2, S3, RDS, Lambda, VPC, IAM, CloudWatch, DynamoDB, CloudFront, and ECS.

Tracks user activity and API usage across AWS infrastructure for auditing.

A managed relational database service supporting multiple engines like MySQL, PostgreSQL, and Oracle.

An isolated data center within a region, offering high availability and fault tolerance.

A scalable Domain Name System (DNS) web service for domain management.

Simple Notification Service sends messages or notifications to subscribers or other applications.

Brings native AWS services to on-premises locations for hybrid cloud deployments.

Automatically adjusts compute capacity to maintain performance and reduce costs.

Amazon Machine Image contains configuration information to launch EC2 instances.

Elastic Block Store provides block-level storage for use with EC2 instances.

Simple Queue Service enables decoupling and message queuing between microservices.

A serverless compute engine for containers running on ECS or EKS.

Manages and groups multiple AWS accounts centrally for billing and access control.

Distributes incoming traffic across multiple EC2 instances for better performance.

A tool for visualizing, understanding, and managing AWS costs and usage over time.

line

Copyrights © 2024 letsupdateskills All rights reserved