Cloudflare Worldedge community field guide

回顧版月刊 / 2024-12

Durable Objects:讓每個 invariant 有唯一住所

當 state changes 必須圍繞某個 identity 序列化時,具名 coordinator 才有價值。

期號
12 / 32
首次發布
來源查核
檔案誠信

月份代表課程編排位置;本文首次發布於 2026-08-10,不冒充歷史發布紀錄或過往活動。

01 / DECISION

何時值得加入這個 primitive

當 per-room、per-user、per-resource 或 per-workflow coordination 需要 strongly consistent ownership 時使用 Durable Object。

02 / ARCHITECTURE

建立最小且站得住腳的路徑

先寫 invariant、推導 stable object ID、限制 method 範圍、只保存必要 state,並定義 alarm 或 cleanup。

  1. 01先命名 contract

    當 per-room、per-user、per-resource 或 per-workflow coordination 需要 strongly consistent ownership 時使用 Durable Object。

  2. 02只加入一個 primitive

    先寫 invariant、推導 stable object ID、限制 method 範圍、只保存必要 state,並定義 alarm 或 cleanup。

  3. 03保留 failure evidence

    對同一 object 發出 concurrent requests、在操作間重啟,並證明 invariant、persistence 與 cleanup 行為。

03 / REPRODUCE

有證據,再有信心

對同一 object 發出 concurrent requests、在操作間重啟,並證明 invariant、persistence 與 cleanup 行為。

npx wrangler types

04 / BOUNDARY

Production boundary

單一 object 可能成為 hot key。Durable Objects 負責協調 state,不會讓無界 workload 免費或無限平行。

05 / FIRST-PARTY SOURCES

讓第一方來源保持權威

產品行為、限制、價格與供應狀態會改變;採取行動前請重新核對這些來源。

01 / SOURCECloudflare Durable Objectshttps://developers.cloudflare.com/durable-objects/