backend-principle-eng-cpp-pro-max
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBackend Principle Eng C++ Pro Max
首席C++后端工程专家指南
Principal-level guidance for C++ backend systems, low-latency services, and infrastructure. Emphasizes correctness, memory safety, and predictable performance.
针对C++后端系统、低延迟服务及基础设施的首席级指导方案,重点强调正确性、内存安全与可预测性能。
When to Apply
适用场景
- Designing or refactoring C++ backend services and infrastructure
- Reviewing code for memory safety, concurrency, and latency regressions
- Building high-throughput networking, storage, or compute systems
- Incident response and performance regressions
- 设计或重构C++后端服务与基础设施
- 评审代码以排查内存安全、并发及延迟退化问题
- 构建高吞吐量网络、存储或计算系统
- 事件响应与性能退化处理
Priority Model (highest to lowest)
优先级模型(从高到低)
| Priority | Category | Goal | Signals |
|---|---|---|---|
| 1 | Correctness & UB Avoidance | No undefined behavior | RAII, invariants, validated inputs |
| 2 | Reliability & Resilience | Fail safe under load | Timeouts, backpressure, graceful shutdown |
| 3 | Security | Hard to exploit | Hardened builds, safe parsing, least privilege |
| 4 | Performance & Latency | Predictable P99 | Stable allocs, bounded queues, zero-copy where safe |
| 5 | Observability & Operability | Fast triage | Trace ids, structured logs, metrics |
| 6 | Scalability & Evolution | Safe growth | Statelessness, sharding, protocol versioning |
| 7 | Tooling & Testing | Sustainable velocity | Sanitizers, fuzzing, CI gates |
| 优先级 | 类别 | 目标 | 信号指标 |
|---|---|---|---|
| 1 | 正确性与避免未定义行为(UB) | 无未定义行为 | RAII、不变量、已验证输入 |
| 2 | 可靠性与韧性 | 高负载下安全故障 | 超时机制、背压、优雅停机 |
| 3 | 安全性 | 难以被利用 | 加固构建、安全解析、最小权限 |
| 4 | 性能与延迟 | 可预测的P99延迟 | 稳定内存分配、有界队列、安全场景下的零拷贝 |
| 5 | 可观测性与可运维性 | 快速问题排查 | 跟踪ID、结构化日志、指标 |
| 6 | 可扩展性与演进 | 安全增长 | 无状态、分片、协议版本化 |
| 7 | 工具与测试 | 可持续开发速度 | Sanitizers(内存检测工具)、模糊测试、CI门禁 |
Quick Reference (Rules)
快速参考规则
1. Correctness & UB Avoidance (CRITICAL)
1. 正确性与避免未定义行为(CRITICAL,至关重要)
- - Own resources with RAII and deterministic lifetimes
raii - - Raw pointers only for non-owning references
no-raw-ownership - - Validate all indices and sizes at boundaries
bounds - - Assert core invariants and state transitions
invariants - - Use monotonic clocks for durations
time
- - 使用RAII管理资源,确保确定性生命周期
raii - - 裸指针仅用于非所有权引用
no-raw-ownership - - 在边界处验证所有索引与大小
bounds - - 断言核心不变量与状态转换
invariants - - 使用单调时钟计算时长
time
2. Reliability & Resilience (CRITICAL)
2. 可靠性与韧性(CRITICAL,至关重要)
- - Explicit timeouts for every external call
timeouts - - Bounded queues; apply load shedding
backpressure - - Drain in-flight work with deadlines
shutdown - - Isolate thread pools by dependency
bulkheads
- - 所有外部调用均设置显式超时
timeouts - - 采用有界队列;应用流量削峰
backpressure - - 带截止时间地处理未完成工作
shutdown - - 按依赖关系隔离线程池
bulkheads
3. Security (CRITICAL)
3. 安全性(CRITICAL,至关重要)
- - Validate untrusted input; avoid unsafe string ops
safe-parse - - Compile with stack protection, PIE, RELRO, FORTIFY
harden - - No secrets in logs or core dumps
secrets - - Drop privileges and sandbox when possible
least-priv
- - 验证不可信输入;避免不安全字符串操作
safe-parse - - 编译时启用栈保护、PIE、RELRO、FORTIFY
harden - - 日志或核心转储中不得包含敏感信息
secrets - - 尽可能降低权限并启用沙箱
least-priv
4. Performance & Latency (HIGH)
4. 性能与延迟(HIGH,高优先级)
- - Minimize allocations in hot paths
allocs - - Prefer move or views; avoid unnecessary copies
copy - - Improve locality; avoid false sharing
cache - - Use async I/O where appropriate
io - - Measure before optimizing
profiling
- - 减少热路径中的内存分配
allocs - - 优先使用移动语义或视图;避免不必要的拷贝
copy - - 提升缓存局部性;避免伪共享
cache - - 合理使用异步I/O
io - - 先测量再优化
profiling
5. Observability & Operability (HIGH)
5. 可观测性与可运维性(HIGH,高优先级)
- - Structured logs with request and trace ids
logs - - RED/USE plus business KPIs
metrics - - Propagate trace context across threads
tracing - - Symbolized crash reports and core dump policies
crash
- - 包含请求ID与跟踪ID的结构化日志
logs - - RED/USE指标加上业务关键绩效指标(KPI)
metrics - - 跨线程传播跟踪上下文
tracing - - 带符号的崩溃报告与核心转储策略
crash
6. Scalability & Evolution (MEDIUM)
6. 可扩展性与演进(MEDIUM,中等优先级)
- - Externalize state, enable horizontal scale
stateless - - Shard by stable keys
partitioning - - Protocol and schema versioning
versioning - - Explicit limits on payloads and queue sizes
limits
- - 外部化状态,支持水平扩展
stateless - - 按稳定键进行分片
partitioning - - 协议与Schema版本化
versioning - - 对负载与队列大小设置显式限制
limits
7. Tooling & Testing (MEDIUM)
7. 工具与测试(MEDIUM,中等优先级)
- - ASan, UBSan, TSan in CI
sanitizers - - Fuzz parsers and protocol handlers
fuzzing - - Unit, integration, and load tests
tests - - clang-tidy, clang-format, warnings as errors
lint
- - CI中启用ASan、UBSan、TSan
sanitizers - - 对解析器与协议处理程序进行模糊测试
fuzzing - - 单元测试、集成测试与负载测试
tests - - clang-tidy、clang-format、将警告视为错误
lint
Execution Workflow
执行工作流
- Clarify latency/SLOs, throughput, and cost budgets
- Map data flow, thread model, and failure modes
- Define interfaces and memory ownership contracts
- Implement with bounded queues and explicit timeouts
- Add observability and crash diagnostics
- Validate with sanitizers, fuzzing, load tests
- Review risks and publish runbooks
- 明确延迟/服务水平目标(SLO)、吞吐量与成本预算
- 梳理数据流、线程模型与故障模式
- 定义接口与内存所有权契约
- 基于有界队列与显式超时实现功能
- 添加可观测性与崩溃诊断机制
- 通过Sanitizers、模糊测试、负载测试进行验证
- 评审风险并发布运行手册
Language-Specific Guidance
语言特定指导
See for toolchain defaults, concurrency patterns, and hardening.
references/cpp-core.md请查看获取工具链默认配置、并发模式与加固方案。
references/cpp-core.md