Back to: AWS-Basics-Advanced
What is AWS DynamoDB?
Amazon DynamoDB is a fully managed NoSQL database service provided by AWS.
It is designed for applications that need fast, consistent, and scalable performance, regardless of the amount of data or traffic.
Think of DynamoDB as:
A serverless, key-value and document-based database where AWS automatically handles servers, scaling, backups, and availability.
๐ Why Use DynamoDB?
Feature | Explanation |
---|---|
โ๏ธ Fully Managed | You donโt manage servers, storage, or scaling โ AWS does it all. |
โก Fast Performance | Single-digit millisecond response times for any data size. |
๐งฑ Scalable | Automatically scales up/down as per traffic (on-demand mode). |
๐๏ธ Flexible Schema | No fixed schema like SQL โ each item can have different attributes. |
๐ Global Tables | Automatically replicate your data to multiple AWS regions. |
๐งฉ Integrations | Works seamlessly with AWS Lambda, API Gateway, and S3 for serverless apps. |
๐งฉ DynamoDB Components (Explained Clearly)
Component | Description | Analogy |
---|---|---|
๐๏ธ Table | A collection of items (like a table in SQL). Each table must have a Primary Key. | Like an Excel sheet. |
๐ Item | A single record in a table. Items are made up of attributes. | Like one row in Excel. |
๐ Attribute | A field or column of an item (e.g., name, age). | Like a cell in Excel. |
๐งฉ Primary Key | Uniquely identifies each item. Can be: โ Partition Key (Hash Key) or โ Partition + Sort Key (Composite Key). |
Like a unique ID. |
๐ง Indexes | Used to query efficiently. – GSI (Global Secondary Index) – LSI (Local Secondary Index) |
Like an alternate search key. |
โ๏ธ Read/Write Capacity Units (RCU/WCU) | Defines how much read and write throughput the table can handle. | Like speed limits for traffic. |
๐ Streams | Capture real-time changes (insert/update/delete) in DynamoDB. | Like a change log. |
๐ Global Tables | Replicate your table automatically across multiple regions. | Like having the same copy of your database in US, India, and Europe. |
Key Points:
โ
Data is automatically replicated across 3 Availability Zones.
โ
No need to provision servers.
โ
You can query data using Primary Key, GSI, or LSI.
๐งฑ Types of NoSQL Databases
Before understanding DynamoDB better, letโs recall what NoSQL means:
Type | Description | Example |
---|---|---|
Key-Value Store | Each record has a unique key and a value. | DynamoDB, Redis |
Document Store | Stores JSON-like documents. | MongoDB |
Column Store | Data stored in columns (for analytics). | Cassandra |
Graph Store | Stores data in nodes and edges. | Neo4j |
โก๏ธ DynamoDB is primarily a Key-Value and Document Store.
โ๏ธ How to Create a DynamoDB Table (Step-by-Step)
Step 1 โ Open Console
Go to AWS Management Console โ DynamoDB โ Create Table
Step 2 โ Define Table
-
Table Name:
StudentData
-
Partition Key:
StudentID
(String) -
Sort Key:
CourseName
(optional)
Step 3 โ Choose Capacity Mode
-
On-Demand Mode: AWS automatically scales reads/writes.
-
Provisioned Mode: You manually specify RCU/WCU.
โ For beginners โ choose On-Demand.
Step 4 โ Add Optional Settings
-
Add GSI (Global Secondary Index) for queries on attributes other than primary key.
-
Enable DynamoDB Streams if you want real-time change tracking.
Step 5 โ Create Table
Click Create Table and wait a few seconds.
๐ก Inserting and Reading Data
Insert Item using AWS CLI
Read Item
Query by Partition Key
๐ DynamoDB Global Tables (Multi-Region Replication)
Global Tables automatically replicate data to multiple AWS regions.
They are ideal for multi-region, active-active applications.
๐งฉ Global Table Components
Component | Description |
---|---|
๐ Global Table | A single table available in multiple AWS regions. |
๐ Replication | Real-time replication of data between regions. |
๐๏ธ Active-Active Setup | Writes can happen in any region; DynamoDB handles conflicts automatically. |
๐ฆ Consistency | Eventually consistent between all regions (very low latency). |
Use Case Example
Letโs say your users are worldwide:
-
๐บ๐ธ US Users connect to
us-east-1
-
๐ฎ๐ณ Indian Users connect to
ap-south-1
-
๐ช๐บ European Users connect to
eu-west-1
Global Tables ensure data is synchronized automatically across all these regions.
๐งฐ Steps to Create DynamoDB Global Table
Step 1 โ Create Table in One Region
-
Go to AWS Console โ DynamoDB โ Create Table
-
Create a table named
GlobalUserData
-
Partition Key:
UserID
-
Choose On-Demand Capacity
-
Click Create
Step 2 โ Enable Global Table
-
Open your created table โ go to Global Tables tab.
-
Click Add Region.
-
Select another region (for example,
ap-south-1
). -
AWS will create a replicated table in that region automatically.
-
Done โ
Replication starts instantly, and both tables stay in sync.
๐งช Testing Global Table Replication
Letโs test by writing in one region and reading in another.
Step 1 โ Write in US Region
Step 2 โ Read from India Region
โ Youโll see the same record replicated automatically โ thatโs the power of Global Tables!
๐ฅ DynamoDB Streams & Lambda Integration
DynamoDB Streams can trigger AWS Lambda whenever data changes.
Example:
When a new student record is added, a Lambda function automatically:
-
Sends a notification
-
Updates another system
-
Writes to S3 for backup
This makes real-time event-driven applications easy to build.
๐งญ Best Practices
โ
Use On-Demand mode for unpredictable workloads
โ
Use Provisioned + Auto Scaling for predictable workloads
โ
Use Global Secondary Indexes (GSI) for flexible queries
โ
Enable Streams + Lambda for real-time updates
โ
Use Global Tables for multi-region redundancy
โ
Use DAX (DynamoDB Accelerator) for microsecond response times
๐ Conclusion
DynamoDB Strength | Description |
---|---|
โ๏ธ Serverless & Managed | No need to manage servers or replication. |
โก High Performance | Millisecond response at any scale. |
๐ Global Replication | Easily deploy worldwide using Global Tables. |
๐งฉ Flexible Schema | Store any structure โ key-value or JSON documents. |
๐ Highly Secure | Integrated with IAM, KMS, and VPC endpoints. |
๐งฉ Real-World Use Cases
Industry | Example |
---|---|
๐ E-commerce | Product catalog, shopping carts, user sessions |
๐ฌ Social Apps | Storing user profiles, messages, likes |
๐งพ Finance | Real-time transaction logs |
๐ฎ Gaming | Leaderboards, player profiles |
๐ IoT | Device states, telemetry data |
โ
In summary:
DynamoDB is the go-to AWS service for scalable, serverless, NoSQL workloads โ perfect for high-performance applications requiring low latency and global reach.