DynamoDB Introduction
1️⃣ DynamoDB কি?
DynamoDB হলো fully managed NoSQL database service, যা Amazon Web Services (AWS) প্রদান করে।
Main characteristics:
NoSQL: Key-Value & Document store
Fully Managed: Server maintenance, patching, scaling দরকার নেই
Ultra Fast: Millisecond latency
Scalable: Auto-scaling support, high throughput
Secure: Data encryption, IAM policies, fine-grained access control
প্রসিদ্ধ উদাহরণ:
Gaming leaderboards
IoT event storage
High-traffic websites
Mobile banking apps
2️⃣ SQL vs DynamoDB (Mindset)
DynamoDB SQL database এর মতো নয়।
| Feature | SQL | DynamoDB |
|---|---|---|
| Table | Yes | Yes |
| Row | Record | Item |
| Column | Fixed | Attribute (Flexible) |
| Schema | Fixed | Flexible |
| Join | Yes | No (denormalization) |
| Query | Complex | Access pattern based |
Key insight:
DynamoDB এ “Query pattern first, schema later”।
SQL এ তুমি schema design করে query adjust করো, DynamoDB তে query dictate schema।
3️⃣ DynamoDB Structure
3.1 Table
Main container for data
প্রতিটি table একটি primary key দিয়ে uniquely identify হয়
3.2 Item
Row equivalent
JSON-like structure
Flexible attributes
Example:
{
"user_id": "1",
"name": "Ali",
"age": 24,
"hobbies": ["coding", "football"]
}
3.3 Attribute
Column equivalent
Type can be:
S → String
N → Number
BOOL → Boolean
L → List
M → Map (JSON object)
3.4 Primary Key
Two types:
1️⃣ Partition Key (HASH) — Unique identifier
2️⃣ Sort Key (RANGE) — Optional, to create composite key
Example:
| user_id | timestamp | action |
|---|---|---|
| 1 | 1685001 | login |
| 1 | 1685005 | logout |
user_id = partition key
timestamp = sort key
4️⃣ Secondary Indexes
DynamoDB supports alternate query patterns using:
1️⃣ Global Secondary Index (GSI)
2️⃣ Local Secondary Index (LSI)
Purpose: Query on attributes other than primary key
5️⃣ Query vs Scan
Query: Efficient, uses primary key or index → O(1) or O(log n)
Scan: Reads entire table → Expensive → O(n)
Pro tip: Always design table for query first, minimize scans
6️⃣ Consistency
Eventually Consistent: Default, faster, cheaper
Strongly Consistent: Reads latest data, slightly slower
7️⃣ Capacity Modes
1️⃣ On-Demand: Pay per request, auto scaling
2️⃣ Provisioned: Specify read/write capacity, cheaper for stable load
8️⃣ Real-World Best Practices
Denormalization is normal: Embed related data, don’t rely on joins
Access Pattern Driven: Table design based on queries
Use Indexes wisely: GSI/LSI for alternate queries
Keep items small: DynamoDB bills per KB read/write
Use TTL for temporary data: Automatic deletion
🔥 Key Takeaways
DynamoDB = NoSQL + AWS managed + Key-Value + Document store
Design schema based on query patterns
Partition Key & Sort Key are most important
GUI only for visualization; real operations via CLI/SDK
Secondary Indexes enable alternate queries
Query ≠ Scan → Always optimize queries