ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
RDS (Intermediate chapter) က relational database (table, schema, SQL query) ဖြစ်ပါတယ် — DynamoDB ကတော့ NoSQL database ပါ, schema fixed မလိုအပ်ပါ (item တစ်ခုချင်းစီက attribute ကွဲပြားနိုင်ပါတယ်)။ Primary Key (Partition Key, optional Sort Key) ကို ကြိုတင်ဒီဇိုင်းလုပ်ရပေမယ့်, attribute အခြားတွေကို flexible ထားလို့ရပါတယ်။ DynamoDB က auto-scaling ဖြစ်ပြီး, Lambda function ကနေ millisecond-level latency နဲ့ access လို့ရပါတယ် — serverless application (Lambda + API Gateway + DynamoDB) ရဲ့ database layer အဖြစ် အသုံးအများဆုံးပါ.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
'Users' DynamoDB table ကို `userId` (Partition Key) နဲ့ create လုပ်ပြီး, user တစ်ယောက်ချင်းစီရဲ့ attribute (name, email, ဒါမှမဟုတ် custom field) ကို flexible ထည့်နိုင်ပါတယ် — Lambda function (Advanced lesson 2) က DynamoDB SDK ကို သုံးပြီး `PutItem`/`GetItem` operation တွေကို millisecond-level latency နဲ့ လုပ်နိုင်ပါတယ်.
အတူတူ ကြည့်မယ်
# Create a DynamoDB table with userId as the partition key
aws dynamodb create-table \
--table-name Users \
--attribute-definitions AttributeName=userId,AttributeType=S \
--key-schema AttributeName=userId,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
# Insert an item
aws dynamodb put-item \
--table-name Users \
--item '{"userId": {"S": "user-1"}, "name": {"S": "Aye Aye"}}'$ aws dynamodb get-item --table-name Users --key '{"userId": {"S": "user-1"}}'
{"Item": {"userId": {"S": "user-1"}, "name": {"S": "Aye Aye"}}}၅ မိနစ် စမ်းကြည့်
'Users' DynamoDB table တစ်ခု create လုပ်ကြည့်ပြီး, item ၂-၃ ခု put/get ကြည့်ပါ — RDS lesson (Intermediate) နဲ့ ဘယ်လို concept ကွာခြားလဲ ၂ ကြောင်း ရေးကြည့်ပါ။
သတိလေးတစ်ချက်
DynamoDB table ကို design လုပ်တဲ့အခါ access pattern (ဘယ်လို query တွေ လုပ်မလဲ) ကို အရင်ဆုံးဆုံးဖြတ်ပြီးမှ Primary Key ကို ရွေးချယ်ရပါတယ် — RDS လို 'ပြီးမှ index ထပ်ထည့်' ဆိုတာ NoSQL မှာ လွယ်ကူချေ နည်းပါတယ်။