← 2026-07-14 📂 All Days 2026-07-16 →

系统设计 / System Design — Day 91 (Synthesis)

**Date:** 2026-07-15 | **Phase:** Expert | **Mode:** Synthesis

🏗️ 系统设计 / System Design

综合对比: 分布式系统一致性模型全景 / Consistency Models Landscape


想象这个场景 / Imagine This

你已经覆盖了 60 个系统设计主题。现在面试官问:"给我讲讲各种一致性模型,以及在真实系统中如何选择。"

You've covered 60 system design topics. Now the interviewer asks: "Walk me through consistency models and how you choose between them in real systems."


一致性模型谱 / The Consistency Spectrum

强一致性 最终一致性 Strong ◄────────────────────────────────────► Eventual Linearizability Sequential Causal Read-Your- Eventual (线性化) (顺序化) (因果) Writes (最终) │ │ │ │ │ 最慢/最贵 较慢 适中 较快/廉价 最快 Slowest Slower Moderate Faster Fastest │ │ │ │ │ ZooKeeper RDBMS DynamoDB DynamoDB Cassandra etcd Spanner (option) (eventual) (W+R<N) Redis w/AOF CockroachDB Cosmos DB

你学过的系统 → 一致性选择 / Systems You've Covered → Choices

系统一致性级别为什么?
Redis (Caching)Eventual (replica lag)性能 > 一致性,cache miss 可重建
Distributed CacheStrong (via locking)防止 thundering herd
URL ShortenerEventual is OK短链"刚创建后读不到"可接受
Payment SystemLinearizable钱不能双花,必须强一致
Chat (WhatsApp)Causal消息顺序必须因果一致(A→B→C)
Rate LimiterApproximate OK偶尔多放一个请求没关系
Stock ExchangeLinearizable撮合引擎必须全局有序
Distributed LockLinearizable锁语义要求线性化
Search AutocompleteEventual稍旧的索引完全可接受
RecommendationEventual推荐延迟更新无所谓

CAP 回顾 + PACELC 升级 / CAP Revisited + PACELC Upgrade

你在 Day 12 学了 CAP。真实工程师用 PACELC:

You covered CAP on Day 12. Real engineers use PACELC:

CAP: 分区时选 C 或 A PACELC: 分区时选 C 或 A,无分区时选 Latency 或 Consistency CAP: During partition, choose C or A PACELC: During Partition → C or A; Else → Latency or Consistency

例子:DynamoDB = PA/EL(分区时选可用,正常时选低延迟)

Spanner = PC/EC(两者都选一致性,靠原子钟)


关键设计选择 / Key Design Choices

Write path 决定一致性:

# Strong consistency: sync replication
def write(data):
    primary.write(data)
    for replica in replicas:
        replica.write(data)  # 同步等待
    return "ok"  # 所有副本确认后返回

# Eventual consistency: async replication  
def write(data):
    primary.write(data)
    async_replicate_to(replicas, data)  # 异步,不等待
    return "ok"  # 立即返回

Quorum 中间路线:

  • N=3 副本,W=2 写,R=2 读 → W+R > N → 强一致
  • W=1,R=1 → 最终一致
  • DynamoDB 让你在请求级别选择!

常见陷阱 / Common Mistakes

别踩这个坑 — 一致性误区:

  1. ❌ "加了缓存,数据库和缓存怎么保持一致?" → 答案:不能完全保持,只能减少窗口
  2. ❌ 为所有系统选强一致性 → 支付 OK,推荐系统杀鸡用牛刀
  3. ❌ 混淆"一致性"(CAP)和"持久性"(ACID D)→ 两个不同维度
  4. ✅ 告诉面试官:"我选最终一致性,因为 X;用 [技术] 来缓解 Y 风险"

面试答题框架 / Interview Framework

问自己 3 个问题 / Ask yourself 3 questions: 1. 数据错误的代价是什么? Cost of incorrect data? 高(支付/锁)→ 强一致 低(推荐/feed)→ 最终 2. 读写比例是多少? Read/write ratio? 读多 → 异步复制副本 写多 → 考虑分片 3. 用户能接受多少延迟? User latency tolerance? 低延迟需求 → 最终一致 + 补偿机制

综合回顾图 / Big Picture

             你设计的系统分布:
                You've designed:

Financial Layer    ████████  Linearizable
(Payment, Exchange)          (ZooKeeper, Spanner)

Infrastructure     ██████    Strong-to-Causal
(Cache, Lock, ID gen)        (Redis, etcd, Snowflake)

Communication      █████     Causal
(Chat, Collab Docs)          (vector clocks, CRDTs)

Content/Discovery  ████████  Eventual
(Search, CDN, Rec)           (Cassandra, DynamoDB)

📚 深度参考 / References

🧒 ELI5

一致性就像多个账本记同一笔钱:

强一致 = 每个账本同时更新,写完才能读

最终一致 = 先更新主账本,其他账本"最终"会跟上

选哪个 = 取决于"读到旧数据有多糟糕"

Consistency is like multiple ledgers tracking the same money:

Strong = all ledgers update simultaneously before anyone can read

Eventual = update the main ledger, others catch up "eventually"

Which to choose = depends on "how bad is it to read stale data"

算法 / Algorithms — Day 91

**Date:** 2026-07-15 | **Phase:** Expert | **Pattern:** Backtracking (3/9)

💻 算法 / Algorithms

#46 Permutations (Medium) 🟡

🧩 回溯模式 (3/9) — building on the template from earlier in this block

上次:#78 Subsets(选不选)、#39 Combination Sum(可重复选)

今天:#46 Permutations — 有序,每个元素只用一次,顺序不同算不同结果

Previous: #78 Subsets (include/exclude), #39 Combination Sum (can reuse)

Today: #46 Permutations — ordered, each element used exactly once, order matters


🔗 链接 / Links


真实类比 / Real-World Analogy

想象 3 个人(A, B, C)坐一排座位。有多少种排法?

3! = 6 种:ABC, ACB, BAC, BCA, CAB, CBA

Permutations = 全排列,每次选一个新人坐下,再从剩余的里选。

Imagine 3 people (A, B, C) sitting in a row. How many arrangements?

3! = 6: ABC, ACB, BAC, BCA, CAB, CBA

Permutations = all orderings, pick one at a time from the remaining.


问题 / Problem

Input:  nums = [1, 2, 3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

模版对比:Permutations vs Subsets / Template Comparison

# Subsets (Day 88): choices = remaining elements after index
# 顺序不重要,[1,2] == [2,1],用 start index 避免重复

def subsets(nums):
    result, path = [], []
    def bt(start):
        result.append(path[:])
        for i in range(start, len(nums)):
            path.append(nums[i])
            bt(i + 1)  # start from NEXT index
            path.pop()
    bt(0)
    return result

# Permutations: choices = ALL unused elements
# 顺序重要,[1,2] != [2,1],用 visited set 追踪用过的

def permutations(nums):
    result, path = [], []
    used = set()
    
    def bt():
        if len(path) == len(nums):  # 用完所有元素 = 一个完整排列
            result.append(path[:])
            return
        for num in nums:            # 从所有 nums 里选
            if num in used:
                continue            # 跳过已用的
            used.add(num)
            path.append(num)
            bt()                    # 递归,不传 start(顺序重要!)
            path.pop()
            used.remove(num)        # 撤销
    
    bt()
    return result

# 测试 / Test
print(permutations([1, 2, 3]))
# [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

执行追踪 / Execution Trace

nums = [1, 2, 3] bt(), path=[], used={} ├─ choose 1: path=[1], used={1} │ ├─ choose 2: path=[1,2], used={1,2} │ │ └─ choose 3: path=[1,2,3] ✅ append → pop 3 │ ├─ choose 3: path=[1,3], used={1,3} │ │ └─ choose 2: path=[1,3,2] ✅ append → pop 2 │ └─ pop 1 ├─ choose 2: path=[2], used={2} │ ├─ choose 1: path=[2,1] → choose 3 → [2,1,3] ✅ │ └─ choose 3: path=[2,3] → choose 1 → [2,3,1] ✅ └─ choose 3: ... → [3,1,2] ✅, [3,2,1] ✅

关键洞察:Subsets vs Permutations 核心区别

SubsetsPermutations
顺序重要?❌ [1,2]==[2,1]✅ [1,2]!=[2,1]
避免重复方式start indexused set
递归参数bt(start+1)bt() (无参数)
结果数量2^nn!
终止条件每层都收集len(path)==len(nums)

复杂度 / Complexity

  • Time: O(n × n!) — n! 个排列,每个花 O(n) 复制
  • Space: O(n) 递归栈深度 + O(n × n!) 输出

举一反三 / Pattern Variations in This Block

本 block 的回溯变体 / Variations in this Backtracking block: #78 Subsets → 选/不选,bt(start+1) #39 Combination Sum → 可重复,bt(start)(不后移) #46 Permutations → 全排列,used set,bt() 无参 #90 Subsets II → 有重复,排序+跳过同层重复 (coming soon) #40 Combo Sum II → 同上,但不重复使用 (coming soon) #79 Word Search → 2D backtrack (coming soon)

📚 References

🧒 ELI5

全排列就像给 3 朋友拍合照:第一个位置有 3 人选,第二个位置剩 2 人,第三个位置剩 1 人。

3×2×1 = 6 张不同的照片。回溯就是:试一个人站第一位,拍完所有后续组合,再换下一个人试。

Permutations are like taking photos with 3 friends in a row: 3 choices for spot 1, 2 for spot 2, 1 for spot 3.

3×2×1 = 6 different photos. Backtracking: try each person in spot 1, exhaust all combos, then swap and try again.

软技能 / Soft Skills — Day 91 (Synthesis)

**Date:** 2026-07-15 | **Phase:** Expert | **Mode:** Synthesis

🗣️ 软技能 / Soft Skills

综合场景:当技术债和新项目同时紧急 / When Tech Debt and New Features Collide


场景 / Scenario

面试官问:

"你的团队有大量技术债,但产品团队刚提了一个高优先级的新功能。你作为 Staff Engineer,如何决策?"

Interviewer asks:

"Your team has significant tech debt, but product just landed a high-priority feature. As Staff Engineer, how do you navigate this?"


为什么难 / Why It's Hard

这不是技术问题——是优先级冲突 + 利益相关方管理 + 长期 vs 短期的三角难题。

错误选择:

  • 🚫 全做新功能 → 债越堆越高,最终系统崩塌
  • 🚫 全还技术债 → 产品不买账,业务受损,团队被质疑
  • ✅ 框架:量化、谈判、分摊

This isn't a technical problem—it's a priority conflict + stakeholder alignment + long vs short-term triangle.


STAR 拆解 / STAR Breakdown

Situation:

我们的支付服务有 3 年历史,每个 sprint 有 20% 时间处理 incident。产品希望我们 6 周内交付实时结算功能。

Our payment service had 3 years of tech debt; 20% of sprint capacity was incident triage. Product wanted real-time settlements in 6 weeks.

Task:

作为 Staff,平衡团队可持续性和产品交付节奏。

Balance team sustainability with product delivery cadence.

Action:

步骤 1: 量化技术债的成本 Step 1: Quantify tech debt cost → "20% sprint capacity = 每月 X 工程师周,折合 $Y 运营成本" → 把"感觉"变成数字。数字说服产品。 步骤 2: 提方案而非问题 Step 2: Bring proposals, not complaints → Option A: 6周纯功能,后续2 sprint 专门还债 → Option B: 8周,每周30%还债,70%新功能 → 让产品选,而不是你单独决定 步骤 3: 谈判"债务预算" Step 3: Negotiate a "debt budget" → 争取每季度 1 sprint 专门技术投资 → 写进团队协议,而非每次都重新谈判 步骤 4: 可视化技术债 Step 4: Make debt visible → Dashboard 显示:代码覆盖率、平均 MTTR、incident 频率 → 高层看到数据,而不只是"工程师抱怨"

Result:

选了 Option B,8周交付。债务率从 20% 降到 8%,下一季度新功能速度反而提升了 30%(因为 incident 少了)。


❌ 差回答 vs ✅ 好回答

❌ 差:

"我跟产品说技术债很重要,我们需要时间处理。"

→ 没有数字,没有方案,听起来是借口

✅ 好:

"我量化了技术债的成本:每月 40 小时 incident 响应 = 相当于 1 个工程师的产出。我带着两个方案找产品团队,数据摆在桌上,让他们参与决策——而不是强迫接受。"


Staff/Principal 级别要点 / Staff+ Insights

  1. 量化一切 — "感觉慢"不如"P50 latency 从 80ms 升到 450ms"
  2. 造选择,而非提要求 — 给 2-3 个方案,各自量化 tradeoff
  3. 让技术债可见 — 工程指标进入产品/管理层的 review cycle
  4. 建立系统,而非每次谈判 — 季度"innovation sprint"写进 charter

综合:你已学过的相关主题 / Synthesis: Related Topics You've Covered

Day主题连接
16如何处理技术债直接相关
8模糊需求需求不清时的框架
38系统设计 tradeoff同样的决策框架
21如何说 No拒绝的艺术
13传达坏消息给利益相关方呈现不好的数字

📚 References

🧒 ELI5

技术债就像家里乱掉的玩具。你可以继续玩新游戏(新功能),但总有一天找不到东西了(系统崩掉)。

聪明的做法:边玩新游戏,边每天收拾一点——而不是等到全乱了再大扫除。

Tech debt is like a messy room. You can keep playing new games (new features), but eventually you can't find anything (system fails).

The smart move: play new games AND tidy a little each day — don't wait for a big cleanup.

AI — Day 91

Date: 2026-07-15 | Mode: NEWS


🤖 AI 新闻 / AI News Roundup

Sources retrieved via web search, July 15, 2026


📰 本周 AI 三件大事 / Top 3 AI Stories This Week


#### 1. 大模型价格战激烈 / Fierce LLM Price War

多家大厂在七月相继发布新模型,推动价格大幅下降。据报道,OpenAI 推出了 GPT-5.6 系列(含 Sol、Terra、Luna),xAI 推出了 Grok 4.5,竞相降低每 token 成本。Meta 据报道推出了面向 agentic 工作流的 Muse Spark 1.1 闭源付费模型。

Multiple major vendors released new models in July, reportedly driving down per-token costs significantly. OpenAI reportedly launched the GPT-5.6 family (Sol, Terra, Luna), xAI released Grok 4.5, and Meta reportedly introduced Muse Spark 1.1, a closed paid model targeting autonomous agent workflows.

为什么重要 / Why it matters:

Frontier 模型推理成本降低意味着 enterprise AI 工作流的经济账开始跑通——之前按量计费太贵,现在 ROI 逐渐合理。

Falling inference costs mean enterprise AI workflows that were cost-prohibitive are now becoming economically viable.

🔗 来源: Medium — AI News Week of July 6-12, 2026 | kersai.com


#### 2. OpenAI × Broadcom 推出专用 AI 推理芯片 / Custom AI Inference Chip

据报道,OpenAI 与 Broadcom 于 6 月底联合推出代号 "Jalapeño" 的 LLM 专用推理加速器,目标是相比现有方案显著提升每瓦性能。DeepSeek 也据报道宣布自研推理芯片计划,降低对现有芯片商的依赖。

OpenAI and Broadcom reportedly unveiled the "Jalapeño" inference accelerator in late June, targeting substantially better performance-per-watt than existing solutions. DeepSeek reportedly announced plans to design custom inference silicon to reduce reliance on current chip suppliers.

为什么重要 / Why it matters:

垂直整合硬件 + 软件正成为大模型公司控制成本和供应链的核心策略。

Vertical integration of hardware + software is becoming the key strategy for frontier AI labs to control costs and supply chains.

🔗 来源: sesamedisk.com — LLMs 2026 Progress


#### 3. 实时对话 AI + Agentic 能力跃升 / Real-Time Conversational AI + Agentic Leap

OpenAI 据报道推出 GPT-Live,支持同时听、说、推理的实时语音 AI,具备现场翻译和任务委托功能。与此同时,agentic AI 能力持续提升——新模型据报道可以协调多个子 agent、操作计算机界面、处理长时间运行任务。

OpenAI reportedly launched GPT-Live, a real-time voice AI capable of simultaneous listening, speaking, and reasoning, with live translation and task delegation. Agentic capabilities are reportedly advancing — new models can reportedly coordinate sub-agents, interact with computer interfaces, and handle long-running tasks.

为什么重要 / Why it matters:

AI 从"问答工具"进化成"自主执行者"。对后端工程师而言:会有越来越多的系统需要暴露 API 供 AI agent 调用——这是新的设计范式。

AI is evolving from "Q&A tool" to "autonomous executor." For backend engineers: more systems will need to expose APIs for AI agents — a new design paradigm.

🔗 来源: llm-stats.com | kersai.com


💡 后端工程师视角 / Backend Engineer's Take

价格战 → 用量爆增 → 你的 API 会被 AI agent 调用 → 需要考虑 rate limiting (Day 17) → 幂等性变得更重要 (Day 38 Payment) → 可观测性 / tracing 更复杂 (Day 68) 专用芯片 → 推理延迟继续降低 → 实时 AI 嵌入产品成为标配 → 你的系统需要 streaming response 支持

📚 References

🧒 ELI5

这周 AI 行业像超市打折季:大家争着降价,推新产品,还开始自己造芯片。

结果是:AI 变得更便宜、更快、能做更多事——而且 AI "自己干活"(agent)的趋势越来越明显。

This week in AI is like a supermarket sale: everyone's cutting prices, launching new products, and building their own chips.

Result: AI is getting cheaper, faster, more capable — and the trend toward AI "doing things on its own" (agents) is accelerating.