DynamoDB Primary Key Concept
DynamoDB Primary Key Concept
DynamoDB এ primary key হলো table এর main identifier।
Primary key দুইভাবে হতে পারে:
Option 1 — Simple Primary Key
Partition Key only
প্রতিটি item table এ unique Partition Key দ্বারা uniquely identified হয়
Example: Users table
| Partition Key (user_id) | name | age |
|---|---|---|
| 1 | Ali | 24 |
| 2 | Sara | 22 |
এখানে primary key = Partition Key = user_id
Sort Key নেই → এক Partition Key এ শুধু ১টি item allowed
Option 2 — Composite Primary Key
Partition Key + Sort Key
এখন primary key = combination of Partition Key + Sort Key
একই Partition Key এর multiple items allowed, কিন্তু Sort Key different হতে হবে
Example: Orders table
| Partition Key (user_id) | Sort Key (order_date) | item |
|---|---|---|
| 1 | 20260101 | Laptop |
| 1 | 20260105 | Mouse |
| 2 | 20260102 | Keyboard |
Primary key uniqueness check করে (Partition Key + Sort Key) combination দিয়ে
Partition Key alone unique না → multiple items same user_id allowed
2️⃣ Key Takeaway
| Concept | DynamoDB |
|---|---|
| Partition Key | Main part of primary key, always required |
| Sort Key | Optional, second part of primary key (for composite key) |
| Primary Key | Either: |
| 1️⃣ Partition Key only (Simple) | |
| 2️⃣ Partition Key + Sort Key (Composite) |
💡 মনে রাখো: Partition Key alone defines data distribution / shard,
Sort Key defines ordering inside that partition
Example
Simple key table:
Primary Key = user_id
Partition Key only
Composite key table:
Primary Key = (user_id + order_date)
Partition Key = user_id
Sort Key = order_date
Query efficiency depends on Partition Key
Sort Key gives extra flexibility for multiple items per Partition Key
tar mane primary key er 2 ta part ache primary key = partition key + short key (composite key)
but main primary key hocche partition key