Keeping One Source Of Truth

作者 riekelte67b7af9ac74無授權條款5 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫3 週前更新

Use when adding data, config, state, constants, an enum-like string, a cache, or anything that could exist in two places - or when two sources already disagree. Encodes the one-fact-one-source doctrine for code and data: derive rather than store, extend the owner, absorb duplicates. Use at the moment copying a value feels faster than referencing it.

AI 產生的概覽

為程式碼與資料建立「一事一源」原則,涵蓋衍生、合併重複項與衝突處理。

功能
這是一個僅含說明的技能,主張系統中每個事實只應存在於一個地方,其他部分都從那裡讀取。它提出規則:新增資料前先找出既有的歸屬者,讀取時衍生而非儲存副本,在工作中順帶合併重複項,並標明產物是產生還是手動編輯。它也要求以型別化詞彙取代重複的自由字串,並說明當兩個來源已經不一致時該如何處理,包括揭露矛盾並收斂為單一來源。
適用情境
適用於新增可能出現在兩處的資料、設定、狀態、常數、類列舉字串或快取時,或兩個來源已經不一致時。它針對的是複製某個值感覺比引用它更快的時刻,以及程式碼硬編碼了檔案已知內容的情境。
執行需求
不需要指令碼或工具,僅為說明性內容。它把 principal-engineering 技能列為必備背景,並提到 handling-failures 以及已安裝情況下的 technical-writing 技能。

Keeping one source of truth

REQUIRED BACKGROUND: the principal-engineering skill.

Overview

Every fact about the system lives in exactly one place, and every other part of the system reads it from there. This outranks convenience.

The doctrine

  1. Before adding data, find who already owns it. Extend that owner; do not start a rival.
  2. Derive rather than store. If the platform or an existing source can answer it at read time, read it there; do not copy the answer into a second source where it can go stale.
  3. Absorb duplicates you find on the way. When you touch code that hardcodes what a file already knows (or the reverse), fold the two together as part of the work instead of leaving a third variant behind.
  4. A missing entry fails loud (see handling-failures): the single source is only authoritative if absence from it is an error, never a silent default.
  5. Mark generated versus hand-edited, and never edit generated output. Every artifact states which it is.
  6. Vocabulary is typed, not stringly. Identifiers, kinds, states, and names that code branches on are constants, enums, sealed types, or registry entries; a free string spelled twice is two sources of truth with a typo between them.
  7. When two sources disagree, say so. Surfacing the contradiction is the first fix. The full fix determines which value is live, collapses to one source, and deletes the loser. Never silently follow either one; that launders the disagreement into whichever answer you happened to read first. On a declared critical path, a live disagreement earns a direct message to the owner, not only a tracked item; an unread ticket surfaces nothing.

Boundaries

  • Caches and read models are legitimate derived copies when their derivation is automatic and their staleness is bounded and observable. The rule bans copies a person keeps in sync by hand.
  • Test fixtures may freeze a copy of reality on purpose; the word fixture is the label that says so.
  • Documentation follows the same rule (an index routes, never decides); the technical-writer plugin's technical-writing skill carries that side where installed.

Common mistakes

  • Copying a threshold, URL, or mapping "temporarily". Temporary copies have the same lifetime as the TODO above them.
  • Creating thing-v2 beside thing instead of editing in place.
  • A default value in code that shadows the config file's value. When someone changes the config and nothing happens, this is why.
  • Two enums in two services spelling the same states. The day one gains a state, the boundary between them becomes a silent filter.

來源與署名

來源:riekelt/principal-engineer位於plugins/principal-engineer/skills/keeping-one-source-of-truth提交e67b7af

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架