AWS Dynamodb

0

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

aws dynamodb put-item \
--table-name StudentData \
--item '{"StudentID": {"S": "S001"}, "Name": {"S": "Alice"}, "CourseName": {"S": "AI"}, "Marks": {"N": "90"}}'

Read Item

aws dynamodb get-item \
--table-name StudentData \
--key '{"StudentID": {"S": "S001"}}'

Query by Partition Key

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

๐ŸŒ 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

  1. Go to AWS Console โ†’ DynamoDB โ†’ Create Table

  2. Create a table named GlobalUserData

  3. Partition Key: UserID

  4. Choose On-Demand Capacity

  5. Click Create


Step 2 โ€“ Enable Global Table

  1. Open your created table โ†’ go to Global Tables tab.

  2. Click Add Region.

  3. Select another region (for example, ap-south-1).

  4. AWS will create a replicated table in that region automatically.

  5. 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

aws dynamodb put-item \
--region us-east-1 \
--table-name GlobalUserData \
--item '{"UserID": {"S": "U001"}, "Name": {"S": "Ravi"}, "Country": {"S": "India"}}'

Step 2 โ€“ Read from India Region

aws dynamodb get-item \
--region ap-south-1 \
--table-name GlobalUserData \
--key '{"UserID": {"S": "U001"}}'

โœ… 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top