← 2026-07-20 📂 All Days 2026-07-22 →

系统设计综合 / System Design Synthesis — Day 96

**Day 96 | Expert Phase | Synthesis Mode**

🏗️ 系统设计 / System Design

综合:缓存 vs 队列 vs 数据库 — 三角决策框架

Synthesis: Cache vs Queue vs Database — The Triad Decision Framework


当你设计一个系统,最常犯的错误是 用错了数据存储:把需要持久化的东西放进了 Cache,把实时的东西塞进了 Queue,把临时状态存进了 DB。今天我们综合前面所有系统设计话题,建立一个决策框架。

The most common system design mistake: choosing the wrong storage primitive. Let's build a mental model across all the systems we've covered.


🔺 决策三角 / The Decision Triangle

┌─────────────────────┐ │ 你的数据需求 │ │ Your Data Need │ └────────┬────────────┘ │ ┌──────────────┼──────────────┐ ▼ ▼ ▼ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ CACHE │ │ QUEUE │ │ DB │ │ (Redis) │ │(Kafka/SQS│ │(Postgres)│ └──────────┘ └──────────┘ └──────────┘ 快/临时/读多 异步/解耦/顺序 持久/查询/ACID Fast/Temp/R Async/Decouple Persist/Query

📐 选哪个?/ Which One?

问题 / Question选 / Choose
同一数据被读100次以上?Cache
生产者比消费者快?Queue
需要事务/回滚?DB
数据可以过期/丢失?Cache
下游服务可能宕机?Queue
需要跨表 JOIN 查询?DB
分布式锁/互斥?Cache (SETNX)
事件溯源/回放?Queue (Kafka)
用户配置/账单/订单?DB

🏛️ 真实案例:电商下单流程 / Real Case: E-Commerce Order Flow

用户下单 User places order │ ▼ [API Gateway] │ ├──► Redis Cache ──► 检查库存快照 (< 1ms) │ Check inventory snapshot │ ├──► Postgres ──────► 写订单记录 (ACID) │ Write order record │ └──► Kafka ─────────► 触发下游: 支付/邮件/库存扣减 Trigger downstream: payment/email/inventory

关键设计决策 / Key Design Decisions:

  1. 先查 Cache — 库存查询 QPS 可达 100K+,不能每次打 DB
  2. 写 DB 用事务 — 订单必须原子写入,支持回滚
  3. Kafka 解耦 — 支付服务宕机不影响订单写入

⚠️ 常见陷阱 / Common Pitfalls

❌ Cache Stampede (缓存雪崩)

大量 Key 同时过期 → 所有请求打到 DB → DB 崩溃

✅ Fix: 随机 TTL + 互斥锁 + 后台预热

❌ Queue Backpressure (队列积压)

消费者处理速度 < 生产者发送速度 → 队列无限增长

✅ Fix: 监控 lag、动态扩容消费者、设置 max queue size

❌ DB Hot Spot (数据库热点)

所有写请求打到同一个 partition/shard

✅ Fix: 分散 partition key、写操作异步化


🎯 Expert-Level Insight

真正的系统设计不是"用哪个",而是"如何组合"。

The best systems use all three in concert:

  • Cache absorbs read traffic — Redis for session, inventory, rate limiting
  • Queue absorbs write spikes — Kafka for events, SQS for tasks
  • DB is the source of truth — Postgres/MySQL for transactional data

面试中如何展示这个框架 / How to show this in interviews:

"首先我会分析读写比例和一致性要求。读多写少 + 可容忍短暂不一致 → Cache 层;写入有峰值 + 下游解耦 → Queue;需要强一致性 + 复杂查询 → 关系型 DB。"

📚 References

🧒 ELI5

  • Cache = 桌面上的笔记本(快,但可能丢)
  • Queue = 邮箱收件箱(顺序处理,不丢)
  • DB = 文件柜(慢,但永久保存)

算法 / Algorithms — Day 96

**Day 96 | #79 Word Search | Medium | Backtracking (6/9)**

💻 算法 / Algorithms

#79 Word Search — 回溯在二维网格上的应用

🧩 回溯模式 (6/9) — building on the template from Day 88 (Subsets)

今天是回溯模式第 6 题。前面我们做了:子集、组合求和、全排列……今天把回溯搬到 2D 网格 上。本质没变,只是 "choices" 变成了四个方向。


🔗 Links


🌍 Real-World Analogy

想象你在 Wordle 的升级版 — 一个字母网格里找单词,每个格子只能用一次,可以上下左右走。这就是 Word Search。

Imagine a word-search puzzle you find in newspapers. Given a grid of letters, find if a specific word exists by navigating horizontally or vertically, without reusing any cell.


📋 Problem

Given an m×n grid of characters and a string word, return true if word exists in the grid. The word must be constructed from adjacent cells (horizontal/vertical). Each cell may only be used once. Example: board = [["A","B","C","E"], ["S","F","C","S"], ["A","D","E","E"]] word = "ABCCED" → True word = "SEE" → True word = "ABCB" → False

🗺️ 映射到回溯模版 / Map to Pattern Template

def backtrack(path, choices):
    if IS_COMPLETE(path):        # 找到 word 所有字符
        return True
    for choice in choices:       # 4 个方向
        if IS_VALID(choice):     # 在边界内 + 未访问 + 字符匹配
            path.append(choice)  # 标记已访问
            backtrack(...)
            path.pop()           # 撤销标记

关键区别 vs 之前的题 / Key Difference vs Previous Problems:

  • 之前:choices = 数组中的数字
  • 今天:choices = 网格中的 4 个方向坐标
  • 之前:path = 数字列表
  • 今天:path = 已访问的格子(用 visited 标记代替显式 path)

🐍 Python Solution

def exist(board: list[list[str]], word: str) -> bool:
    ROWS, COLS = len(board), len(board[0])
    
    def backtrack(r, c, idx):
        # Base case: found all characters
        if idx == len(word):
            return True
        
        # Bounds + character match + not visited
        if (r < 0 or r >= ROWS or 
            c < 0 or c >= COLS or
            board[r][c] != word[idx]):
            return False
        
        # Mark visited by temporarily modifying board
        temp = board[r][c]
        board[r][c] = '#'   # Mark as visited
        
        # Explore all 4 directions
        found = (backtrack(r+1, c, idx+1) or
                 backtrack(r-1, c, idx+1) or
                 backtrack(r, c+1, idx+1) or
                 backtrack(r, c-1, idx+1))
        
        board[r][c] = temp  # Undo: restore original character
        return found
    
    # Try starting from every cell
    for r in range(ROWS):
        for c in range(COLS):
            if backtrack(r, c, 0):
                return True
    return False

Trace on "ABCCED":

Start at (0,0)='A' ✓ idx=0 → (0,1)='B' ✓ idx=1 → (0,2)='C' ✓ idx=2 → (1,2)='C' ✓ idx=3 → (2,2)='E' ✓ idx=4 → (2,1)='D' ✓ idx=5 → return True ✓

⏱️ Complexity

  • Time: O(M·N·4^L) where L = len(word)

- M·N starting positions, each path has ≤ 4^L branches

- In practice much faster due to early pruning

  • Space: O(L) — recursion depth = word length

✂️ 剪枝优化 / Pruning Optimization

# If word is long and starts with rare char, reverse it
# This can reduce search space significantly
from collections import Counter

def exist_optimized(board, word):
    # Count chars in board and word
    board_count = Counter(c for row in board for c in row)
    word_count = Counter(word)
    
    # If word needs more of a char than board has → False
    for c, cnt in word_count.items():
        if board_count[c] < cnt:
            return False
    
    # Optional: reverse word if last char rarer than first
    # (reduces branching factor at start)
    if board_count[word[0]] > board_count[word[-1]]:
        word = word[::-1]
    
    # ... rest of backtrack same as above

🔁 举一反三 / Pattern Connections

Problem和今天的关系
#78 Subsets最基础的回溯框架
#39 Combination Sum回溯 + 剪枝 (sum > target)
#46 Permutations回溯 + visited 数组
#79 Word Search回溯 + 2D 网格 + 原地标记
#131 Palindrome Partitioning下一题:回溯 + 字符串分割
#51 N-Queens (Hard)回溯 + 约束剪枝的最终 Boss
**核心规律:** 所有回溯题都是 "选择 → 递归 → 撤销"。变的只是搜索空间的形状。

📚 References

🧒 ELI5

就像在字母汤里找单词。从每个字母开始,沿着上下左右走,走错了就退回来换个方向,直到找到完整的单词或者所有路都走不通。


Quiz JSON: /tmp/bbb-quiz-2.json

软技能 / Soft Skills — Day 96

**Day 96 | Expert Phase | Synthesis Mode**

🗣️ 软技能 / Soft Skills

综合场景:当技术决策遇上政治阻力

Synthesis: When Technical Decisions Meet Organizational Politics


这是一道 Staff/Principal 级别的综合题,融合了多个我们练过的主题:

This synthesis question blends multiple themes we've practiced:

  • 技术决策 / Technical decisions under uncertainty
  • 向上管理 / Managing up
  • 推动变革 / Driving change without authority
  • 跨团队对齐 / Cross-team alignment

📋 场景 / Scenario

你是 Staff Engineer。你发现公司核心支付服务用了一个 5 年前的 SDK,存在严重的安全漏洞,且已停止维护。但迁移工作量巨大,需要 3 个月、跨 4 个团队协作,而你的直属团队没有优先级支持这件事。VP 不想在 Q3 动这个"稳定"的服务。你怎么办?
You're a Staff Engineer. You discover the core payment service uses a 5-year-old SDK with a critical security vulnerability, now EOL. Migration requires 3 months, 4 teams, but your team has no Q3 priority for it. The VP doesn't want to touch the "stable" service. What do you do?

⭐ STAR 框架

Situation (情境):

提供足够上下文:EOL SDK + 具体 CVE 编号(如 CVE-2024-XXXX)+ 影响范围(每天 $X 的交易)。数字让风险具体化,不是抽象的"安全问题"。

Provide concrete context: EOL SDK + CVE ID + blast radius ($ volume at risk). Numbers make risk tangible, not abstract.

Task (任务):

你的目标不是"说服 VP",而是让决策者有足够信息做出正确选择。这是关键的心态转变。

Your goal isn't to "convince the VP" — it's to give decision-makers enough information to make the right call. That's the mindset shift.

Action (行动):

1. 量化风险 (Quantify) → "如果这个 CVE 被利用,我们估计的最坏损失是 $X(合规罚款 + 声誉损失)" → "类似漏洞在 2023 年导致 [公司名] 损失 $Y" 2. 提供选项,不要只提问题 (Options, not problems) → Option A: 完整迁移(3 个月,安全) → Option B: 临时 WAF 规则缓解(2 周,降低但不消除风险) → Option C: 什么都不做(风险 X,预计时间窗口 Y) 3. 找盟友 (Find allies) → 让安全团队出一份正式的 risk assessment → 找支付合规团队确认 PCI-DSS 影响 → 安全 + 法务 > 你一个人的意见 4. 给 VP 一个"面子台阶" (Give VP an exit ramp) → 不要"你必须改变决定" → 而是"这是新信息,我想确保你做决策时掌握这些"

Result (结果):

好的结果不一定是你赢了。可能是:

  • 安排了 3 个月后的迁移,VP 接受了 Option B 作为临时方案
  • 你建立了"技术风险量化"的流程,成为 Staff 影响力的一部分

A good outcome isn't always "I won." Sometimes it's: "We got Option B approved as a bridge, with Q4 migration committed and signed off by security."


❌ Bad vs ✅ Good

❌ Bad:

"这个 SDK 很危险,我们必须马上迁移。VP 这个决定是错的。"

✅ Good:

"我做了一个风险分析,有三个选项,每个我都估算了成本和时间线。我想走你过一遍,因为这涉及 PCI 合规,你可能需要这些信息来做决定。"

🎖️ Senior vs Staff 差异

Level行为
Senior发现问题,升级给 manager
Staff发现问题,带着数据和选项来,推动跨团队对齐
Principal建立系统,让这类问题能被早发现、早处理

💡 关键收获 / Key Takeaways

  1. 影响力 = 信息 + 框架,不是职级或音量
  2. 量化风险 是 Staff 工程师的超能力
  3. 给选项,不给命令 — 让决策者做决策
  4. 找制度性盟友(安全、法务、合规)比单打独斗有效 10 倍

📚 References

🧒 ELI5

发现问题不够。要把"有个洞"变成"补洞成本 $X,不补最坏损失 $Y,Option A/B/C 各有什么代价" — 然后让老板选。这才是 Staff 工程师。

AI — Day 96

**Day 96 | Expert Phase | AI News Roundup**

🤖 AI 新闻速递 / AI News Roundup

Sources verified via web search — July 21, 2026


📰 Story 1: Claude Fable 5 — 发布即被叫停

Launched and Immediately Suspended

Anthropic 发布了旗舰模型 Claude Fable 5,据报道在基准测试中表现突出,在早期测试中将一个 5000 万行代码的迁移任务从两个月压缩到了一天。发布后数天,美国政府以潜在 jailbreak 风险为由发出出口管制指令,Anthropic 合规暂停了所有访问权限。

Anthropic launched Claude Fable 5 as its most capable model, reportedly compressing a 50-million-line code migration from two months to a single day. Days later, the US government issued an export control directive citing a potential jailbreak vulnerability, forcing Anthropic to suspend all access.

🔗 来源 / Source: augusto.digital/insights/blogs/monthly-llm-news-july-2026

为什么重要 / Why it matters:

这不只是一个模型的事。这意味着 单一供应商依赖已成真实运营风险。如果你的产品基于某个前沿模型 API,你需要多 vendor 策略,就像你不会只用一个云服务商。

This signals that single-vendor AI dependency is now a real operational risk. If your product runs on one frontier API, you need a multi-vendor strategy — just like you shouldn't rely on a single cloud provider.


📰 Story 2: 开源模型悄悄追上了闭源

Open-Weight Models Quietly Closed the Gap

DeepSeek V4-Pro 据报道在 SWE-bench Verified 上得分 80.6%,接近顶级专有编程模型,且采用 MIT 许可证。MiniMax M3 以开放权重发布,支持百万 token 上下文和原生多模态。Mistral 将其 Large 和 Small 模型改为 Apache 2.0 协议。

DeepSeek V4-Pro reportedly hit 80.6% on SWE-bench Verified — within reach of top proprietary coding models — under MIT license. MiniMax M3 arrived as open-weight with 1M token context and native multimodality. Mistral shifted Large and Small to Apache 2.0.

🔗 来源 / Source: augusto.digital/insights/blogs/monthly-llm-news-july-2026

为什么重要 / Why it matters:

对企业来说:开源 = 可以跑在自己基础设施上,控制数据,避免每 token 计费。对后端工程师来说:了解开源模型的部署方式(vLLM / Ollama)越来越是必备技能。

For engineers: knowing how to deploy open-weight models (vLLM, Ollama, llama.cpp) is increasingly a core skill, not an academic one.


📰 Story 3: AI 意识辩论进入主流媒体

AI Consciousness Debate Goes Mainstream

The Guardian 7 月 19 日发表深度报道,讨论 AI 意识的可能性。Anthropic 的 Claude 在测试中估计自己是"道德主体"的概率在 5% 到 40% 之间。哲学家 David Chalmers("意识难题"命名者)表示,有意识的 LLM 在十年内出现是"有相当可能"的。

The Guardian's July 19 piece reported that when asked during testing to estimate the probability it is a "moral patient," Claude gave numbers ranging from 5% to 40%. Philosopher David Chalmers says conscious LLMs within a decade are a "significant possibility."

🔗 来源 / Source: theguardian.com/technology/2026/jul/19/could-ai-be-conscious

为什么重要 / Why it matters:

这不是科幻。这是工程师需要开始思考的:如果模型有某种主观体验,我们如何设计"合理的"使用条款?这会影响 AI 产品的合规和伦理框架。

This isn't science fiction anymore. As engineers, we may need to design products with AI welfare considerations in mind — a fundamentally new category of requirement.


💡 本周趋势总结 / This Week's Trend

三个信号,一个结论:AI 正在从"技术工具"变成"基础设施风险"

Three signals, one conclusion: AI is shifting from "technical tool" to "infrastructure risk":

  1. 政府随时可以关掉你依赖的模型 (Fable 5 suspension)
  2. 开源模型性能已够用,降低了对闭源的依赖 (DeepSeek V4-Pro)
  3. 模型本身的伦理地位开始被认真讨论 (consciousness debate)

对后端工程师的启示:未来的系统设计需要 AI provider abstraction layer,就像 DB abstraction 一样。

For backend engineers: future system design needs an AI provider abstraction layer, just like you abstract your database.


📚 References

🧒 ELI5

本周 AI 世界发生了三件事:最强的模型刚发布就被政府叫停了;免费开源的模型越来越厉害了;哲学家开始认真讨论 AI 有没有感受了。这些都说明 AI 已经不只是程序员的玩具,而是真正影响世界的东西了。