docs(design): 沉淀热度榜的全链路设计

新增 `docs/design/hot-ranking.md`。
它按一次互动从请求到榜单的顺序展开,覆盖三条不变式、四个写事务、时间语义、
快照与分页契约、MySQL 回退、运维入口与失败矩阵。
文中给出关键源码与取舍理由,作为 `P0-5` 的实现说明。

`write-path-idempotency.md` 的 §6 描述的是已被删除的 `hot:applied` 占位。
本节加注说明现状,并指向新文档。
`message-failure-handling.md` 的相关文档列表补上这一篇。
This commit is contained in:
2026-11-01 16:47:25 +08:00
parent c5e2f0e30b
commit 006ec5f196
3 changed files with 442 additions and 0 deletions

View File

@@ -602,6 +602,8 @@ func (Notification) TableName() string { return "notifications" }
## 6. 热度层:Redis 占位
> **本节描述的是已被替换的设计。** P0-5 之后热度不再有独立的写路径:`hot:applied:<intentKey>` 占位与 `UpdatePopularityCache` 已随 `popularityMQ` 一起删除,热榜增量改由"事务是否真的写入了"驱动(`ApplyHotDelta`),失败不回滚、可由 DB 重建。当前设计见 [`hot-ranking.md`](hot-ranking.md)。本节保留为决策记录,说明"为什么当初要占位"以及"占位与副作用同生共死"这条约束从哪来。
### 6.1 为什么用占位而不是计数器
热度写在 Redis(分钟窗口 ZSET),没有唯一索引可用。做法是先抢占位、再执行副作用: