本章路線圖 / Learning path
- 1. Build the three-tier picture|建立三層架構圖
- 2. Thin and smart clients|薄客戶端和智能客戶端
- 3. Proxy functions|代理功能
- 4. Push, pull and hybrid access|推送、拉取及混合存取
- 5. Work across disconnection|跨斷線運作
- 6. Cache freshness and invalidation|快取新鮮度及失效通知
開啟補充筆記、計算與自測 / Open additional notes, calculations and quiz →
1. Build the three-tier picture|建立三層架構圖
The client tier is the mobile device and its application. A proxy or gateway tier sits between the client and back-end when the architecture includes it. The server tier supplies application logic, data, synchronization or messaging. Not every deployment has every component.
客戶端層是流動裝置及應用程式。若架構包含代理或閘道層,它位於客戶端和後端之間。伺服器層提供應用邏輯、資料、同步或訊息服務。不是每個部署都需要所有組件。
A phone asks a proxy for a large image; the proxy obtains and resizes it; the phone receives a smaller version. / 手機向代理要求大圖片;代理取得並縮小圖片;手機收到較小版本。
2. Thin and smart clients|薄客戶端和智能客戶端
A thin client relies heavily on a server and may require little installation. A smart client performs more processing and stores data locally. The smart client can work through short outages, but must protect local data and resolve differences between copies when connectivity returns.
薄客戶端高度依賴伺服器,可能只需少量安裝。智能客戶端在本地執行較多處理及儲存資料;它可應付短暫斷線,但必須保護本地資料,並在重連時處理副本差異。
For offline editing, save the change locally, label it pending, then synchronize once connected. If another user edited the same item, apply a conflict policy. / 離線編輯時先本地保存並標示待同步,重連後同步;若其他用戶修改同一項目,便依衝突政策處理。
3. Proxy functions|代理功能
A proxy can transcode, compress or cache data. Transcoding changes the representation to suit the device; caching stores a copy for reuse. A proxy can reduce latency or bandwidth, but its cache can be stale and an intermediary that processes plaintext adds a trust boundary.
代理可轉碼、壓縮或快取資料。轉碼改變表示方式以適應裝置;快取保存副本供重用。代理可降低延遲或流量,但快取可能過時,而處理明文的中間人亦增加信任邊界。
A 5 MB image transcoded to 1 MB saves 4 MB on that transfer, though image quality may decrease. / 5 MB 圖片轉成 1 MB,該次傳送節省 4 MB,但圖片品質可能下降。
4. Push, pull and hybrid access|推送、拉取及混合存取
In pull, a client requests data when needed. In push, the server transmits data without an individual request for every item; a broadcast can serve many receivers. A hybrid system may broadcast popular items and let users request rare ones. Compare traffic, relevance and waiting time.
Pull 是客戶端需要時才請求資料。Push 是伺服器毋須每個項目都收到個別請求便發送資料;廣播可服務多個接收者。混合系統可廣播熱門資料,並讓用戶請求冷門資料。比較時要考慮流量、相關性及等待時間。
An emergency announcement desired by everyone is a possible push use; a personal account balance is normally requested for the specific user. / 所有人都需要的緊急公告可用 push;個人帳戶結餘則通常由指定用戶請求。
5. Work across disconnection|跨斷線運作
Before disconnection, prefetch likely-needed items. While offline, use cached data and log local updates. After reconnection, check versions, upload/download changes and resolve conflicts. The system must distinguish locally saved from server-confirmed updates.
斷線前預取可能需要的項目;離線時使用快取並記錄本地更新;重連後檢查版本、上傳/下載變更及處理衝突。系統須區分「本地已儲存」與「伺服器已確認」。
If two clients edit the same version while offline, automatic last-write-wins can discard one change; user-assisted merging is another policy. / 若兩個客戶端離線編輯同一版本,最後寫入覆蓋政策可能丟失一方的變更;用戶協助合併是另一種政策。
6. Cache freshness and invalidation|快取新鮮度及失效通知
TTL sets how long a cached entry is accepted without a new check. A longer TTL reduces validation traffic but can increase staleness. Invalidation reports identify changes; a client that misses reports while disconnected may need to revalidate before trusting its cache. Stateful schemes track client state; stateless schemes do not keep per-client cache state.
TTL 設定快取項目毋須重新檢查而可接受的時間。TTL 較長可減少驗證流量,但可能增加過時程度。失效報告指出變更;斷線期間錯過報告的客戶端,可能需重新驗證才可信任快取。Stateful 追蹤客戶狀態;stateless 不保留每個客戶的快取狀態。
The best TTL depends on how often data changes and the cost of stale data; there is no universally best number. / 最佳 TTL 取決於資料更新頻率和過時資料的代價,沒有適用所有情況的固定數值。