နားလည်ထားရမယ့် အချက်
Relational database (SQL) များသည် data များကို schema အသေအချာဖြင့် table များအဖြစ် သိမ်းဆည်းပြီး foreign key များနှင့် JOIN operation များသုံးကာ ဆက်စပ်နေသော table များကို query time မှာ ချိတ်ဆက်ပေးပါတယ်။ ဒါကြောင့် data တွေကြားက relationship (user → order → product) များများရှိပြီး ACID transaction လိုအပ်တဲ့ situation တွေမှာ အထူးကောင်းပါတယ် — ACID ဆိုတာ multi-step write တစ်ခုဟာ concurrent access ဒါမှမဟုတ် crash ဖြစ်ရင်တောင် အပြည့်အဝ success ဖြစ်ခြင်း ဒါမှမဟုတ် လုံးဝ rollback ဖြစ်ခြင်းသာ ရှိစေပြီး half-finished state ဘယ်တော့မှ မကျန်ရစ်စေတဲ့ အာမခံချက်ပါ။ NoSQL database (document store MongoDB၊ key-value store Redis၊ wide-column store Cassandra) များကတော့ fixed schema ကို ချန်ထားခဲ့ပြီး JOIN ကိုပါ လုံးဝမသုံးတာများပါတယ် — record တစ်ခုစီက ကိုယ်ပိုင် shape ရှိနိုင်ပြီး machine အများကြီးပေါ်မှာ write throughput ကို horizontal scale လုပ်နိုင်ပါတယ် — Trade-off ကတော့ CAP theorem အရ network partition ဖြစ်တဲ့အခါ consistency အချို့ကို availability ရဖို့ စွန့်လွှတ်ရတတ်ပါတယ်။ အမှန်တကယ် ဆုံးဖြတ်ရမယ့် အချက်ကတော့ 'NoSQL က web-scale ဖြစ်လို့၊ SQL က ခေတ်ဟောင်းလို့' မဟုတ်ဘဲ သင့် access pattern က ဘာလိုအပ်လဲဆိုတာပါ — join များများနဲ့ consistency ပြင်းပြင်းလိုရင် SQL၊ schema flexible ဖြစ်ဖို့ ဒါမှမဟုတ် write throughput အလွန်များဖို့ လိုရင် NoSQL ကို ရွေးရပါမယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Tutorial Platform ရဲ့ core relational data — user, course, lesson, enrollment တွေမှာ user တစ်ယောက် course အများကြီးထဲ enroll ဝင်တာလို relationship တွေ ပြင်းပြင်းရှိပြီး payment နဲ့ enrollment record နှစ်ခုစလုံး success ဖြစ်ဖို့ ACID guarantee လိုအပ်တဲ့အတွက် SQL database မှာ သိမ်းထားပါတယ်။ ဒါပေမဲ့ learner activity event တွေ — video watch progress၊ quiz attempt၊ analytics အတွက် page view တွေကတော့ volume အလွန်များပြီး shape ကလည်း အမြဲပြောင်းနေတတ်ကာ record အချင်းချင်း join လိုအပ်မှုမရှိတဲ့အတွက် NoSQL document ဒါမှမဟုတ် wide-column store နဲ့ ပိုသင့်ပါတယ်။ Platform တစ်ခုလုံးအတွက် တစ်မျိုးတည်းရွေးမယ့်အစား workload တစ်ခုချင်းစီအလိုက် ရွေးတတ်ဖို့ဟာ အရေးကြီးတဲ့ skill ဖြစ်ပါတယ်။
အတူတူ စမ်းရေးကြည့်မယ်
SQL (Relational) NoSQL (Document Store)
+------------------+ +--------------------------+
| users | | { "_id": "u1", |
| id | name | | "name": "Aye", |
+----+-------------+ | "courses": [ |
| 1 | Aye | | { "title": "Rust", |
+------------------+ | "progress": 40 }, |
| FK | { "title": "Go", |
v | "progress": 10 } |
+------------------+ | ] |
| enrollments | | } |
| user_id | course | <-- JOIN needed +--------------------------+
+---------+---------+ Naturally good at:
| 1 | Rust | - flexible/evolving shape
+------------------+ - horizontal write scale
Naturally good at: - fast writes at huge volume
- multi-table relationships Weaker at:
- strong consistency (ACID) - cross-record joins
- complex queries across entities - strict schema enforcementSQL က ချိတ်ဆက်ထားတဲ့ data ကို JOIN နဲ့ consistency ပြင်းပြင်းရအောင် managed လုပ်ပေးပြီး၊ NoSQL ကတော့ schema flexible ဖြစ်ပြီး scale ဖြစ်အောင် join ကို စွန့်လွှတ်ထားတာကို ပြပါတယ်။၅ မိနစ် စမ်းကြည့်
Tutorial Platform ရဲ့ 'comment' feature တစ်ခု အသစ်ထည့်မယ်ဆိုပါစို့ — comment တွေဟာ lesson တစ်ခုနဲ့ချိတ်ဆက်ပြီး reply thread တွေပါနိုင်ပါတယ်။ ဒါကို SQL နဲ့ ဒါမှမဟုတ် NoSQL နဲ့ ဘယ်လိုမော်ဒယ်ဖန်တီးမလဲ စဉ်းစားကြည့်ပြီး ရွေးချက်ရဲ့ အကြောင်းရင်းရေးပါ။
သတိလေးတစ်ချက်
'NoSQL က ပိုမြန်တယ်' လို့ထင်ပြီး relationship များစွာရှိတဲ့ data ကို document store ထဲ ထည့်လိုက်ရင် application code ထဲမှာ join logic ကို manual ပြန်ရေးရတာနဲ့ ဆုံပါတယ်။
SQL database မှာ schema migration ကို ကြောက်ပြီး column အများကြီးကို JSON blob အဖြစ် စုပုံသိမ်းလိုက်ရင် relational database ရဲ့ query optimization အားလုံးကို ဆုံးရှုံးသွားစေပါတယ်။
Wikipedia — NoSQL — System Design