单体架构
单一代码库负责多种业务功能的传统软件开发模型。
结构与工作原理
按步骤查看箭头所示的流程。
单一部署单元中的所有功能一起扩缩容。数据库可以是独立资源。
预期收益
开发、测试和部署较简单,通过在负载均衡器后添加副本可方便地水平扩容。
权衡
小改动也可能影响代码库的广泛区域,增加变更和维护成本。
应用范围与性能要求上升后,维护和扩展会更困难。
运维与应用指南
综合说明,与有原文摘录支持的条目分开。实际应用前请先验证。
何时使用
适合优先快速推出产品、简化开发与部署的早期产品或小团队,也适用于要求简单的中小型应用与原型。
应用场景
某地方零售连锁企业有 50 名员工、8 名开发者,计划在 3 个月内推出一个 Web 应用,涵盖网上订购、库存及会员功能。预计每天数千次请求,各功能的独立扩容需求不大。采用一个代码库和一个关系数据库简化开发、测试与部署,把若干相同实例部署在负载均衡器后实现水平扩容。
部署原则
- 将 UI、服务端逻辑及数据访问层封装为一个运行单元或制品
- 主要数据作为表存入一个关系数据库管理系统
- 静态资源放在应用包内或单个 Web 服务器路径下
- 在负载均衡器后部署相同的应用副本
- 如需会话或缓存,可使用外部共享存储,但核心数据集中在一个数据库。
本地部署
部署一个可执行文件及关系数据库,通过负载均衡器后的副本扩容。统一管理这一部署单元的版本、配置及数据库迁移。故障可能波及整个应用,因此应保持健康检查、备份和回滚流程简单。
云环境
以一个容器或虚拟机镜像作为部署单元,搭配托管负载均衡器和关系数据库。复制与自动扩缩容作用于整个实例,难以按功能独立扩容。通过蓝绿或滚动发布尽量缩短停机。
Kubernetes
将单体打包成一个容器镜像,用一个 Deployment 部署,通过 Service 和 Ingress 暴露。使用副本数和 HPA 对整个实例扩容,将单一数据库拆到 StatefulSet 或外部托管数据库。配置 ConfigMap、Secret、liveness/readiness 探针及 PDB,同时认识到各功能没有隔离。
故障应对
典型故障是有问题的端点、慢查询或下游延迟导致所有实例的延迟与负载上升。先限流或阻断流量,回滚最近部署,增加实例,并检查数据库连接与慢查询。短暂错误可重试,持续故障用断路器和超时快速失败以防级联。随后加强端点指标和发布门禁。
14 个维度的证据
反映调研时的证据收录情况,请另行判断来源是否准确、是否仍然有效。
定义与概览有证据
单一代码库负责多种业务功能的传统软件开发模型。
Monolithic architecture is a traditional software development model in which a single codebase executes multiple business functions.解决的问题有证据
通过简化开发与部署,帮助初创企业快速推进业务并节省早期资金。
Startup outfits need to make quick business moves, but also need to conserve precious start-up funds.关键组件与资源有证据
由客户端界面、服务端接口和数据库组成。
a client-side interface, a server-side interface, and a database代表性使用场景有证据
适合中小型应用、原型以及需求较简单的场景。
Best suited for small to medium-sized applications, prototypes, or applications with simple requirements.应用场景示例有证据
适合最多 20 人的小团队开发领域边界尚不清晰且重视简单部署的早期产品。
Team size is small (< 20 engineers)不适用情形与注意事项有证据
应用范围与性能要求上升后,维护和扩展会更困难。
as the application’s scope and performance demands increase, a monolith can consequently become difficult to maintain and scale.本地部署:开发、发布与运维有证据
最简单的形式是在一台服务器上运行一个可执行文件。
In its simplest form, a monolithic application is a single executable that runs on a single server.云环境:开发、发布与运维有证据
在负载均衡器后部署相同副本以水平扩容。
simple to scale horizontally by running copies behind a load balancer.Kubernetes:开发、发布与运维未确认
未记录已确认的原文证据,这不代表模式不适用。
故障应对有证据
短暂故障可重试,对持续故障使用断路器,以抑制级联影响。
Use the Circuit Breaker pattern to fail fast without making the remote call when an operation is likely to fail.优势有证据
开发、测试和部署较简单,通过在负载均衡器后添加副本可方便地水平扩容。
it is simple to develop, test and deploy, and simple to scale horizontally by running copies behind a load balancer.不足与权衡有证据
小改动也可能影响代码库的广泛区域,增加变更和维护成本。
small changes impact large areas of the code base.代表性技术与工具有证据
典型构件包括关系数据库管理系统和单一可运行单元。
A database for the enterprise-level app is usually multiple tables organized in a relational database management system.更多参考资料 (24)
- What is Monolithic Architecture? | IBM ↗
- Monolithic Architecture | Compile N Run ↗
- Decomposing monoliths into microservices ↗
- What Is a Monolithic Application? | F5 ↗
- Top 10 Software Architecture Styles You Should Know — bool.dev ↗
- Part 6: Software Architecture & Design Patterns - Wasil Zafar ↗
- How to design monolith architectures with Vaadin ↗
- Monolithic vs Microservices - Difference Between Software Development Architectures- AWS ↗
- From Monoliths to Microservices: Application Modernization With Kubernetes ↗
- References: Kubernetes and cloud projects | Cheveo GmbH ↗
- How to Run Kubernetes Across On-Premises and Public Cloud: Four Hybrid Architecture Models and the Seven Layers to Standardize ↗
- Deploy Containerized Apps with AKS Hybrid and Edge by Using GitOps - Azure Architecture Center | Microsoft Learn ↗
- Reference Architecture: GKE Enterprise hybrid environment - part 2 - Dec '24 - Google Docs ↗
- A Private Cloud "Kubernetes Service" deployable anywhere. | CNCF End User Community ↗
- TechnicalEnablement/AKS-adoption-aligned-to-cloud-adoption-framework.md ↗
- The perfect Kubernetes architecture from edge to cloud ↗
- SRE for single-tiered software applications | Google Cloud Blog ↗
- Improving Resiliency and Stability of a Large-scale Monolithic API Service ↗
- Design for Self-Healing - Azure Architecture Center | Microsoft Learn ↗
- Monolith vs microservices: fault isolation and its cost ↗
- Google SRE - Cascading Failures: Reducing System Outage ↗
- 1 Designing and running microservices ↗
- Architecture strategies for performing failure mode analysis - Microsoft Azure Well-Architected Framework | Microsoft Learn ↗
- The Distributed Monolith: Diagnosis and First Remedies | Microservices Recipes: The Architect’s Field Guide ↗