mcpField
R
rfc-generator

rfc-generator

github.com/patricio0312rev开发63280 次安装41 周前更新
代码仓库

关于 rfc-generator

这项 Skill 帮助将技术提案整理为 RFC,围绕问题、架构、备选方案、权衡、风险、发布计划和评审流程组织内容。

主要功能

  1. 01提供 RFC 结构与模板
  2. 02记录架构和详细设计
  3. 03比较备选方案及其权衡
  4. 04整理风险与缓解措施
  5. 05划分起草、评审和批准阶段
  6. 06列出实施与成功标准

适用场景

  1. 01提出系统架构变更
  2. 02实施前比较不同方案
  3. 03协调技术评审与批准
  4. 04跟踪 RFC 的实施进度

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/patricio0312rev/skills --skill rfc-generator

安装后在 Claude Code 中输入/rfc-generator确认已加载。

详细介绍

RFC 生成器

通过 RFC 撰写全面的技术提案。

RFC 模板

# RFC-042: Implement Read Replicas for Analytics

**Status:** Draft | In Review | Accepted | Rejected | Implemented
**Author:** Alice ([email protected])
**Reviewers:** Bob, Charlie, David
**Created:** 2024-01-15
**Updated:** 2024-01-20
**Target Date:** Q1 2024

## Summary

Add PostgreSQL read replicas to separate analytical queries from transactional workload, improving database performance and enabling new analytics features.

## Problem Statement

### Current Situation

Our PostgreSQL database serves both transactional (OLTP) and analytical (OLAP) workloads:

- 1000 writes/min (checkout, orders, inventory)
- 5000 reads/min (user browsing, search)
- 500 analytics queries/min (dashboards, reports)

### Issues

1. **Performance degradation**: Analytics queries slow down transactions
2. **Resource contention**: Complex reports consume CPU/memory
3. **Blocking features**: Can't add more dashboards without impacting users
4. **Peak hour problems**: Analytics scheduled during business hours

### Impact

- Checkout p95 latency: 800ms (target: <300ms)
- Database CPU: 75% average, 95% peak
- Customer complaints about slow pages
- Product team blocked on analytics features

### Success Criteria

- Checkout latency <300ms p95
- Database CPU <50%
- Support 2x more analytics queries
- Zero impact on transactional performance

## Proposed Solution

### High-Level Design

┌─────────────┐ │ Primary │────────────────┐ │ (Write) │ │ └─────────────┘ │ ▼ ┌─────────────┐ │ Replica 1 │ │ (Read) │ └─────────────┘ ▼ ┌─────────────┐ │ Replica 2 │ │ (Analytics)│ └─────────────┘


### Architecture
1. **Primary database**: Handles all writes and critical reads
2. **Read Replica 1**: Serves user-facing read queries
3. **Read Replica 2**: Dedicated to analytics/reporting

### Routing Strategy
```typescript
const db = {
  primary: primaryConnection,
  read: replicaConnection,
  analytics: analyticsConnection,
};

// Write
await db.primary.users.create(data);

// Critical read (always fresh)
await db.primary.users.findById(id);

// Non-critical read (can be slightly stale)
await db.read.products.search(query);

// Analytics
await db.analytics.orders.aggregate(pipeline);
复制
  • 类型: 流式复制
  • 延迟: 只读副本低于 1 秒,分析副本可接受低于 5 秒
  • 监控: 延迟超过 5 秒时发出告警

详细设计

数据库配置
# Primary
max_connections: 200
shared_buffers: 4GB
work_mem: 16MB

# Read Replica
max_connections: 100
shared_buffers: 8GB
work_mem: 32MB

# Analytics Replica
max_connections: 50
shared_buffers: 16GB
work_mem: 64MB
连接池
const pools = {
  primary: new Pool({ max: 20, min: 5 }),
  read: new Pool({ max: 50, min: 10 }),
  analytics: new Pool({ max: 10, min: 2 }),
};
查询分类
enum QueryType {
  WRITE = "primary",
  CRITICAL_READ = "primary",
  READ = "read",
  ANALYTICS = "analytics",
}

function route(queryType: QueryType) {
  return pools[queryType];
}

考虑过的替代方案

替代方案 1:垂直扩展

方案: 升级到更大的数据库实例

  • 优点: 简单,无需更改代码
  • 缺点: 成本高昂(每月 $500 → $2000),无法分离工作负载,仍会触及限制
  • 结论: 不予采用——无法解决隔离问题
替代方案 2:独立的分析数据库

方案: 将数据复制到专用分析数据库(例如 ClickHouse)

  • 优点: 针对分析进行了优化,不影响主数据库
  • 缺点: ETL 工作流复杂,最终一致性,维护成本高
  • 结论: 暂缓——如果副本不足以满足需求,未来再考虑
替代方案 3:物化视图

方案: 预先计算分析结果

  • 优点: 查询速度快,无需副本
  • 缺点: 仅适用于已知查询,维护开销大
  • 结论: 可作为副本的补充,而非替代方案

权衡

我们优先考虑的方面
  • 性能隔离
  • 成本效益
  • 快速实施
  • 运维简单
我们愿意牺牲的方面
  • 数据略有延迟(分析场景可接受)
  • 基础设施复杂度增加
  • 运维成本上升

风险与缓解措施

风险 1:复制延迟

影响: 分析数据可能过时 可能性: 中 缓解措施:

  • 持续监控延迟
  • 延迟超过 5 秒时发出告警
  • 向用户说明预期延迟
风险 2:配置复杂度

影响: 路由错误、性能问题 可能性: 低 缓解措施:

  • 全面测试
  • 逐步推出
  • 提供便捷的回滚机制
风险 3:成本超支

影响: 超出预算 可能性: 低 缓解措施:

  • 为分析副本使用较小的实例(每月 $300)
  • 监控使用情况
  • 1 个月后调整实例规格

推出计划

阶段 1:设置(第 1-2 周)
  • 配置只读副本 1
  • 配置分析副本 2
  • 配置复制
  • 确认延迟低于 1 秒
  • 负载测试
阶段 2:只读副本(第 3 周)
  • 部署路由逻辑
  • 将 10% 的搜索查询路由到副本
  • 监控错误和延迟
  • 逐步增加到 100%
阶段 3:迁移分析任务(第 4-5 周)
  • 确定分析查询
  • 将仪表盘查询更新为使用分析副本
  • 测试报告
  • 迁移所有分析任务
阶段 4:验证(第 6 周)
  • 衡量结账延迟的改善情况
  • 确认 CPU 使用率下降
  • 用户验收测试
  • 标记为已完成

成功指标

主要目标
  • ✅ 结账延迟低于 300ms p95(当前为 800ms)
  • ✅ 主数据库 CPU 使用率低于 50%(当前为 75%)
  • ✅ 复制延迟导致的错误为零
次要目标
  • 支持 2 倍的分析查询量
  • 支持新的仪表盘功能
  • 团队满意度调查评分高于 8/10

成本分析

组件当前提议差额
主数据库$500/mo$500/mo$0
只读副本-$500/mo+$500
分析副本-$300/mo+$300
总计$500/mo$1,300/mo+$800/mo

投资回报: 性能提升有助于收入增长;分析能力可带来产品洞察

开放问题

  1. 分析场景可接受的复制延迟是多少?(提议:<5 sec)
  2. 如何处理副本故障?(提议:回退到主库)
  3. 之后是否应该增加更多副本?(提议:持续监控,并在 Q2 决定)

时间安排

  • 第 1-2 周:资源配置和设置
  • 第 3 周:迁移到只读副本
  • 第 4-5 周:分析迁移
  • 第 6 周:验证
  • 总计:6 周

附录

参考资料
审阅历史
  • 2024-01-15:初始草稿(Alice)
  • 2024-01-17:添加成本分析(Bob)
  • 2024-01-20:处理审阅意见

## RFC Process

### 1. Draft (1 week)
- Author writes RFC
- Include problem, solution, alternatives
- Share with team for early feedback

### 2. Review (1-2 weeks)
- Distribute to reviewers
- Collect comments
- Address feedback
- Iterate on design

### 3. Approval (1 week)
- Present to architecture review
- Resolve remaining concerns
- Vote: Accept/Reject
- Update status

### 4. Implementation
- Track progress
- Update RFC with learnings
- Mark as implemented

## Best Practices

1. **Clear problem**: Start with why
2. **Concrete solution**: Be specific
3. **Consider alternatives**: Show you explored options
4. **Honest tradeoffs**: Every choice has costs
5. **Measurable success**: Define done
6. **Risk mitigation**: Plan for failure
7. **Iterative**: Update based on feedback

## Output Checklist

- [ ] Problem statement
- [ ] Proposed solution with architecture
- [ ] 2+ alternatives considered
- [ ] Tradeoffs documented
- [ ] Risks with mitigations
- [ ] Rollout plan with phases
- [ ] Success metrics defined
- [ ] Cost analysis
- [ ] Timeline estimated
- [ ] Reviewers assigned

评论

支持 Markdown