Files
interview/questions/system-design-general.md
yasinshaw fe2e6dc2f2 feat: add 50 backend interview questions and answers
Generated comprehensive interview preparation materials covering:
- Distributed systems (transactions, locks, ID generation, consistency)
- Database (indexing, sharding, replication, transactions)
- Caching (Redis, cache problems, distributed lock)
- Message queues (RocketMQ, Kafka)
- Concurrency (ThreadLocal, ConcurrentHashMap, thread pools)
- JVM (GC, memory, tuning)
- System design (seckill, short URL, IM, feed, LBS)
- Algorithms (B+ tree, LRU, Red-Black tree, Skip list, Timing wheel)
- Network (TCP/IP, HTTP/HTTPS)
- Security (encryption, SQL injection, XSS)
- Performance tuning
- Design patterns
- Microservices (Spring Boot, Gateway, Service Mesh)
- Container orchestration (Kubernetes, Docker)
- CI/CD, observability

Each file includes:
- Detailed questions
- Comprehensive answers
- Code examples
- Real project experience
- Alibaba P7 level requirements

Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-03-01 00:09:50 +08:00

3.7 KiB
Raw Blame History

系统设计方法论

问题

  1. 系统设计的核心原则是什么?
  2. 如何进行需求分析?
  3. 如何估算系统容量?
  4. 数据模型设计有哪些最佳实践?
  5. 如何设计高可用架构?

标准答案

1. 系统设计原则

核心原则

  1. 简单性KISSKeep It Simple, Stupid
  2. 模块化(高内聚、低耦合)
  3. 可扩展性(水平扩展、垂直扩展)
  4. 高可用性(冗余、故障隔离)
  5. 一致性CAP 理论权衡)

2. 需求分析

功能需求

  • 系统做什么?
  • 用户角色有哪些?
  • 核心流程是什么?

非功能需求

  • 性能QPS、响应时间
  • 可用性99.9%、99.99%、99.999%
  • 扩展性:支持多少用户
  • 安全性:认证、授权、加密
  • 一致性:强一致、最终一致

3. 容量估算

QPS 估算

日活用户DAU100 万
平均每人每天请求20 次
总 QPS = 100 万 × 20 / 86400 ≈ 231 QPS
峰值 QPS = 231 × 5 ≈ 1155 QPS假设峰值是平均的 5 倍)

存储估算

用户数100 万
每人平均数据1 KB
总存储 = 100 万 × 1 KB ≈ 1 GB
每年增长 = 1 GB × 12 = 12 GB

带宽估算

平均响应大小10 KB
QPS1000
带宽 = 1000 × 10 KB × 8 = 80 Mbps

4. 数据模型设计

原则

  1. 范式化(减少冗余)
  2. 反范式化(提高性能)
  3. 分区(水平、垂直)
  4. 索引(加速查询)

示例

-- 范式化3NF
CREATE TABLE users (
  id BIGINT PRIMARY KEY,
  name VARCHAR(50),
  email VARCHAR(100)
);

CREATE TABLE orders (
  id BIGINT PRIMARY KEY,
  user_id BIGINT,
  amount DECIMAL(10,2),
  created_at DATETIME,
  FOREIGN KEY (user_id) REFERENCES users(id)
);

-- 反范式化(冗余用户名,避免 JOIN
CREATE TABLE orders_denormalized (
  id BIGINT PRIMARY KEY,
  user_id BIGINT,
  user_name VARCHAR(50),  -- 冗余
  amount DECIMAL(10,2),
  created_at DATETIME
);

5. 高可用架构

冗余设计

          ┌─────────────┐
          │   负载均衡   │ (Nginx、HAProxy)
          └──────┬──────┘
                 │
       ┌─────────┼─────────┐
       │         │         │
    ┌──▼──┐  ┌──▼──┐  ┌──▼──┐
    │App 1│  │App 2│  │App 3│
    └──┬──┘  └──┬──┘  └──┬──┘
       │         │         │
       └─────────┼─────────┘
                 │
          ┌──────▼──────┐
          │  主从数据库   │
          │  Master     │
          │  Slave      │
          └─────────────┘

故障隔离

  • 熔断器Circuit Breaker
  • 限流Rate Limiter
  • 降级Fallback
  • 舱舱模式Bulkhead

6. 扩展性设计

垂直扩展Scale Up

  • 升级硬件CPU、内存、磁盘
  • 简单、快速
  • 有上限(硬件限制)

水平扩展Scale Out

  • 增加机器数量
  • 无限扩展
  • 需要架构支持(无状态、数据分片)

7. 阿里 P7 加分项

架构思维

  • 能进行技术选型(权衡各种方案)
  • 能进行容量规划(预估资源需求)
  • 能进行成本控制(性价比优化)

设计能力

  • 能设计高并发架构
  • 能设计高可用架构
  • 能设计可扩展架构

沟通能力

  • 能清晰地表达设计方案
  • 能进行技术方案评审
  • 能推动方案落地