နားလည်ထားရမယ့် အချက်
Data ကို local သိမ်းထားတဲ့ app တိုင်းဟာ storage type, offline behavior, sync reconciliation ဆိုတဲ့ architectural decision အများကြီးကို ချမှတ်နေတာဖြစ်ပြီး framework အားလုံး underneath concept တူညီပါတယ်။
| Concept | ရှင်းလင်းချက် |
|---|---|
| Local Storage | preferences, cached data, drafts နှင့် ကိုက်ညီသည် — ဆုံးရှုံးရင်တောင် ကပျက်ကြေမဖြစ်ပါ။ |
| Secure Storage | authentication token/credential အတွက် Keystore/Keychain ကဲ့သို့ platform-provided mechanism ကို သုံးရမည်။ |
| Caching | remote data ကို local သိမ်းပြီး ချက်ချင်းပြသကာ background မှာ တိတ်တဆိတ် refresh လုပ်ခြင်း။ |
| Offline Mode | network မရှိချိန် blank error screen အစား local cache ဆီ fallback လုပ်ခြင်း (support ရှိပါက)။ |
Sync ဟာ အခက်ခဲဆုံး concept ဖြစ်သည် — data တူညီတစ်ခုကို offline ပြောင်းလဲမှုနှစ်ခုဟာ conflict ဖြစ်နိုင်ပြီး "online ရင် upload ရုံပဲ" ဆိုတာထက် ပိုရှုပ်ထွေးသည်။
- Secure Storage
- Android ရဲ့ Keystore-backed encrypted storage, iOS ရဲ့ Keychain ကဲ့သို့ sensitive data (token, credential) ကို extraction ခံနိုင်ရည်ရှိအောင် သိမ်းဆည်းပေးသည့် platform-provided mechanism။
- Conflict Resolution
- data တူညီတစ်ခုကို ပြောင်းလဲမှုနှစ်ခု ဝိရောဓိဖြစ်နေချိန် ဘယ် version နိုင်မလဲ (သို့) ဘယ်လို ပေါင်းစပ်မလဲ ဆုံးဖြတ်ပေးသည့် strategy (last-write-wins, server-authoritative, merge, manual)။
OFFLINE-FIRST DATA FLOW
-----------------------
OFFLINE-FIRST DATA FLOW
-----
Local change made (e.g. edit a note)
|
v
Add change to sync queue
|
v
Network available? ----No----> Use local cache, retry later
|
Yes
|
v
Sync queued changes to server
|
v
Conflicts found? ----No----> Local cache updated, done
|
Yes
|
v
Resolve (last-write-wins / server-authoritative / merge / manual)လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
notes app တစ်ခုမှာ note တူတူကို ဖုန်းက offline edit လုပ်ခဲ့ပြီး laptop ကလည်း edit လုပ်ခဲ့တယ်ဆိုပါစို့ — reconnect ဖြစ်လာချိန် app ဟာ real conflict နှင့် ရင်ဆိုင်ရပါလိမ့်မယ်။
| Strategy | Tradeoff |
|---|---|
| Last-Write-Wins | ရိုးရှင်းသော်လည်း timestamp အသစ်ဆုံးမဟုတ်တဲ့ real work ကို တိတ်တဆိတ် ဖျက်ချနိုင်သည်။ |
| Server-Authoritative | consistency အတွက် ဘေးကင်းသော်လည်း local edit ဆုံးရှုံးသွားတဲ့ user အတွက် စိတ်ပျက်စရာ။ |
| Merge | conflict မဖြစ်တဲ့ အပိုင်းများကို auto-combine ပြီး manual resolution ကတော့ user ကိုယ်တိုင် ရွေးချယ်ခိုင်းသည်။ |
App တိုင်းအတွက် correct strategy တစ်ခုတည်း မရှိပါဘူး — to-do app တစ်ခုဟာ last-write-wins ကို လက်ခံနိုင်ပေမယ့် collaborative document tool ကတော့ merge-based sync ပိုလိုအပ်ပါတယ်။
အတူတူ စမ်းရေးကြည့်မယ်
function chooseStorageType(data) {
const { isSensitiveCredential, isUserPreference, isCachedContent } = data;
if (isSensitiveCredential) return "secure storage (Keychain/Keystore-backed)";
if (isCachedContent) return "cache (fetched remote data, safe to lose or refetch)";
if (isUserPreference) return "normal local storage";
return "normal local storage (default for uncategorized local data)";
}
const authToken = { isSensitiveCredential: true, isUserPreference: false, isCachedContent: false };
const fetchedArticleList = { isSensitiveCredential: false, isUserPreference: false, isCachedContent: true };
const darkModeSetting = { isSensitiveCredential: false, isUserPreference: true, isCachedContent: false };
const unsavedDraftNote = { isSensitiveCredential: false, isUserPreference: false, isCachedContent: false };
console.log("Auth token:", chooseStorageType(authToken));
console.log("Fetched article list:", chooseStorageType(fetchedArticleList));
console.log("Dark mode setting:", chooseStorageType(darkModeSetting));
console.log("Unsaved draft note:", chooseStorageType(unsavedDraftNote));Auth token: secure storage (Keychain/Keystore-backed)
Fetched article list: cache (fetched remote data, safe to lose or refetch)
Dark mode setting: normal local storage
Unsaved draft note: normal local storage (default for uncategorized local data)
sensitive credential တစ်ခုတည်းက secure storage ဆီ ရောက်ပြီး၊ cached content ကတော့ cache category ဆီ ရောက်ကြောင်း ကြည့်ပါ။၅ မိနစ် စမ်းကြည့်
`chooseStorageType` ထဲ ပဉ္စမ boolean `isDraftContent` တစ်ခု ထပ်ထည့်ပြီး ကိုယ်တိုင်ဆုံးဖြတ်ပါ — draft တစ်ခုဟာ cached content အုပ်စုတည်းမှာ ရှိသင့်လား၊ (သို့) သီးခြား အဖြေတစ်ခု ထိုက်တန်ပါသလား။ ဆုံးဖြတ်ချက်ကို ကိုက်ညီအောင် function ကို ပြောင်းလဲပါ။
သတိလေးတစ်ချက်
Authentication token (သို့) credential ကို plain generic local storage ထဲမှာ သိမ်းထားခြင်း (secure storage မသုံးဘဲ)
"online ရင် upload ရုံပဲ" လို့ ယူဆပြီး conflict resolution strategy ကို လုံးဝ မစဉ်းစားထားခြင်း
Data synchronization — Wikipedia — How Mobile Apps Work