# 绞杀榕模式

绞杀榕模式是一种渐进式现代化遗留系统的软件架构模式：新功能在旧系统旁边构建，流量逐步路由到新实现，只有在所有功能都被替换后，遗留系统才会退役。这个名称由马丁·福勒（Martin Fowler）提出，源自绞杀榕——一种在宿主树上发芽、向下扎根于土壤、最终完全取代宿主的藤蔓。<sup>[1](https://martinfowler.com/bliki/StranglerFigApplication.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 起源 | 由马丁·福勒（Martin Fowler）于2004年6月29日在一篇最初题为《绞杀应用》的博客文章中提出，灵感来自2001年在昆士兰（Queensland）雨林中见到的榕树<sup>[1](https://martinfowler.com/bliki/StranglerFigApplication.html)</sup><sup> • </sup><sup>[2](https://www.martinfowler.com/bliki/OriginalStranglerFigApplication.html)</sup> |
| 核心机制 | 外观层（代理）拦截客户端请求，将其路由到遗留系统或新服务；客户端保持相同接口，对迁移的进行一无所知<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup> |
| 最终状态 | 一旦所有功能迁移完毕且不再有依赖，遗留系统即退役，外观层被移除<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup> |
| 主要优势 | 与大爆炸式重写相比风险更低：遗留系统持续运行，价值稳定交付，每项变更都小到足以诊断和回滚<sup>[2](https://www.martinfowler.com/bliki/OriginalStranglerFigApplication.html)</sup><sup> • </sup><sup>[4](https://www.thoughtworks.com/en-au/insights/articles/embracing-strangler-fig-pattern-legacy-modernization-part-one)</sup> |
| 关键配套模式 | 防腐层在遗留系统和新系统之间转换调用，使双方能够互相访问，而无需采纳对方的约定<sup>[5](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html?trk=article-ssr-frontend-pulse_little-text-block)</sup> |
| 不适用场景 | 无法拦截的请求、无法修改的遗留源代码、完全重写很简单的小型系统，以及需要快速退役的场景<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup> |

## 名称起源

马丁·福勒（Martin Fowler）是英国软件作家、Thoughtworks首席科学家，2001年在澳大利亚[昆士兰](https://www.edgepedia.org/zh/queensland)（Queensland）雨林度假时见到了绞杀榕。这种藤蔓在树杈的缝隙中发芽，生长过程中从宿主汲取养分，触及地面后形成根系和树冠，此后便能自给自足；宿主树可能死去，只留下绞杀榕作为其形状的残影。他将这种逐渐取代的过程比作同事们现代化遗留软件的方式，几年后，即2004年6月29日，他发表了一篇关于此事的简短博客文章。<sup>[1](https://martinfowler.com/bliki/StranglerFigApplication.html)</sup><sup> • </sup><sup>[2](https://www.martinfowler.com/bliki/OriginalStranglerFigApplication.html)</sup>

原帖标题为《绞杀应用》，该模式常被简称为“绞杀”。随着术语传播开来，福勒开始担心其植物学渊源被人遗忘，且这个词带有暴力色彩。他将文章改题为《绞杀榕应用》以强化这一隐喻，并打趣说新标题“绞杀”了旧标题。<sup>[1](https://martinfowler.com/bliki/StranglerFigApplication.html)</sup>

在2004年的文章中，福勒指出，关键系统的重写远比表面看起来复杂和危险：切换日期迫在眉睫，新功能仍须交付，旧行为必须保留。他的同事克里斯·史蒂文森（Chris Stevenson）曾在XP 2004大会上展示的一个项目中应用了这种方法，在旧应用被完全绞杀之前就交付了有价值的功能。福勒将事件拦截确定为基本策略，既用于逐步迁移功能，也用于实现资产捕获，并指出降低风险是选择绞杀榕模式而非切换式重写的首要原因。<sup>[2](https://www.martinfowler.com/bliki/OriginalStranglerFigApplication.html)</sup>

## 模式如何运作

迁移分阶段推进，微软Azure架构中心将其描述为四个步骤。<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup>

1. **引入外观层。** 在客户端应用、遗留系统和新系统之间放置一个代理。初始阶段，它将大部分请求路由到遗留系统。
2. **逐步迁移功能。** 每轮迭代中，更多功能在新系统中实现，外观层将越来越大的请求份额路由到新系统。遗留系统的职责缩小，新系统的范围扩大，整个过程中系统保持稳定和可用。
3. **退役遗留系统。** 所有功能迁移完毕且不再依赖遗留系统后，外观层将所有请求全部路由到新系统。
4. **移除外观层。** 重新配置客户端，使其直接与新系统通信，完成迁移。或者，外观层可以保留下来作为遗留客户端的适配器，同时更新核心系统以服务更新的客户端。<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup>

AWS规范性指导将同一生命周期描述为三个步骤：转型（与遗留应用并行构建现代化组件）、共存（用HTTP代理如Amazon API Gateway拦截外部调用并重定向流量）、消除（随着流量转移而退役旧功能）。<sup>[5](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html?trk=article-ssr-frontend-pulse_little-text-block)</sup><sup> • </sup><sup>[6](https://docs.aws.amazon.com/pdfs/prescriptive-guidance/latest/modernization-decomposing-monoliths/modernization-decomposing-monoliths.pdf)</sup>实践者指南补充了更细粒度的步骤：识别系统边界，将系统拆分为足够小以便增量替换、但又足够重要以交付业务价值的薄片，引入间接层，开发新组件，路由流量，退役旧组件，然后迭代。<sup>[4](https://www.thoughtworks.com/en-au/insights/articles/embracing-strangler-fig-pattern-legacy-modernization-part-one)</sup>

**前提条件。** 该模式要求能够访问遗留代码库，因为随着功能迁移，必须拦截调用并重定向内部调用；没有代码访问权限，拦截便无从谈起。[领域驱动设计](https://www.edgepedia.org/zh/domain-driven-design)（DDD）和事件风暴通常用于在分解之前理解领域并找到服务边界，因为过早分解且边界错误代价高昂。<sup>[5](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html?trk=article-ssr-frontend-pulse_little-text-block)</sup>伊恩·卡特赖特（Ian Cartwright）、罗布·霍恩（Rob Horn）和詹姆斯·刘易斯（James Lewis）为增量方法定义了四项高层活动：理解期望的结果，决定如何将问题拆分为更小的部分，成功交付各部分，并改变组织使这一过程能够持续进行；这些活动的排列顺序并不代表先后次序。<sup>[1](https://martinfowler.com/bliki/StranglerFigApplication.html)</sup>

## 数据、共存与过渡架构

两个系统同时运行时，必须共享资源并相互通信。微软的指南强调要处理两个系统共用的服务和数据存储，规划双向的跨系统依赖，并使用防腐层模式——一种在系统之间转换请求的适配器，保护新系统的设计不受遗留语义的侵蚀。<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup>AWS描述了在单体内部将防腐层实现为`UserServiceFacade`或`UserServiceAdapter`之类的类，这样未迁移的调用方继续调用旧接口，而不知道现在由微服务处理请求；一旦依赖它的服务全部迁移完毕，该层即退役。<sup>[5](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html?trk=article-ssr-frontend-pulse_little-text-block)</sup>

数据同步是核心难点。一种方法是在新微服务和单体数据库之间放置一个同步代理：每当微服务的数据发生变化，它就向队列发布一个事件，代理更新单体数据库，使共享数据最终保持一致。AWS建议将此类同步视为战术性方案，直到出现数据湖之类的长期方案。<sup>[5](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html?trk=article-ssr-frontend-pulse_little-text-block)</sup>对于逻辑驻留在存储过程中的、以数据库为中心的遗留应用，数据库本身可以通过触发器或变更数据捕获向新服务发送消息，后者读取事务日志而无需更改应用代码。<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup>

为迁移而构建的路由和转换代码属于过渡架构：它的存在是为了让新系统和遗留系统共存，迁移完成后将被丢弃。福勒承认团队常常不愿构建它，但认为降低的风险和更早交付的价值超过了其成本。<sup>[1](https://martinfowler.com/bliki/StranglerFigApplication.html)</sup>微软同样建议权衡这种临时基础设施在风险缓解方面的收益与其成本，并警告外观层必须跟上迁移进度，且不得成为单点故障或性能瓶颈。<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup>

## 何时使用，何时不用

该模式适用于后端应用正被逐步迁移到新架构的场景——尤其是替换大型系统、核心组件或复杂功能存在风险的情况——以及遗留系统能够在漫长的迁移期内保持运行的场景。它适用于以下情况：鉴于单体的规模和复杂性，大爆炸式迁移风险过高；业务等不及转型完成就需要添加功能；最终用户受到的影响必须最小化。<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup><sup> • </sup><sup>[5](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html?trk=article-ssr-frontend-pulse_little-text-block)</sup>

它不适用于以下情况：对后端的请求无法拦截；遗留源代码无法访问或修改；系统小到整体替换很简单；或者原始方案必须快速退役。<sup>[3](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)</sup>AWS补充说，大型单体受益最大，而对于重构复杂度低的小型应用，直接重写可能更高效；每个重构后的服务还需要一个回滚计划。<sup>[5](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html?trk=article-ssr-frontend-pulse_little-text-block)</sup><sup> • </sup><sup>[6](https://docs.aws.amazon.com/pdfs/prescriptive-guidance/latest/modernization-decomposing-monoliths/modernization-decomposing-monoliths.pdf)</sup>

## 与其他方案的比较

与完全重写相比，绞杀榕模式用多次小规模切换取代一次大规模切换。福勒的论点是：替换方案似乎很容易说明，但现有行为的细节很难厘清，其中许多其实并不需要，因此重建它们是浪费；渐进式方法能尽早交付价值，并让组织在推进过程中学习。<sup>[1](https://martinfowler.com/bliki/StranglerFigApplication.html)</sup>但成本是实实在在的：过渡期拉长，必须同时运维两个系统，人员和资源必须在支持遗留系统和构建新系统之间取得平衡。<sup>[4](https://www.thoughtworks.com/en-au/insights/articles/embracing-strangler-fig-pattern-legacy-modernization-part-one)</sup>

AWS的一个相关模式——保留叠加模式——采取了不同的方法：现有应用完全保持不变，同时通过松耦合的、事件驱动的集成在其旁边叠加新功能。它旨在在完全不触碰遗留系统的情况下增加能力，而绞杀榕模式则逐步替换遗留功能；绞杀榕模式需要深入了解现有代码库才能安全地提取功能，而数据库拆分和API版本管理又增加了复杂性。<sup>[7](https://aws.amazon.com/blogs/migration-and-modernization/modernizing-legacy-applications-with-event-driven-architecture-the-leave-and-layer-pattern/)</sup>

## 应用

该模式被用于各种迁移场景。在微服务迁移方面，2020年IEEE的一项案例研究将绞杀榕模式与领域驱动设计相结合，将[Green Button](https://www.edgepedia.org/zh/green-button)项目的DataCustodian系统从单体中迁移出来，识别并建立了适当的微服务，并对新微服务和未迁移模块的性能进行了定量实验。<sup>[8](https://doi.org/10.1109/ICS51289.2020.00107)</sup>2023年一项关于无服务器迁移的实证研究基于11个组织的15次访谈，发现各组织采用领域驱动设计方法识别用例，并使用绞杀榕模式逐步迁移到无服务器架构，面临的挑战包括测试事件驱动架构以及与遗留系统集成。<sup>[9](https://arxiv.org/abs/2311.13249)</sup>云厂商提供了直接的工具：AWS Migration Hub Refactor Spaces对该模式进行建模，并编排API Gateway、网络负载均衡和IAM策略，在现有HTTP端点背后透明地添加新服务。<sup>[10](https://docs.aws.amazon.com/pdfs/migrationhub-refactor-spaces/latest/userguide/migrationhub-refactor-spaces-ug.pdf)</sup>

这一理念也已传播到服务端系统之外。2026年的一篇arXiv论文描述了一种“双启动”机制，在单个二进制文件中承载iOS应用的两个变体，并在启动时选择变体，并将从嵌入、实验到弃用遗留变体的完整生命周期，描述为绞杀榕模式在原生移动平台上的首次应用；相关的重写经过了为期10个月的评估，未流失用户。<sup>[11](https://arxiv.org/abs/2608.15135)</sup>

## References

1. [Martin Fowler (2024). Strangler Fig. martinfowler.com](https://martinfowler.com/bliki/StranglerFigApplication.html)
2. [Martin Fowler (2004). Original Strangler Fig Application. martinfowler.com](https://www.martinfowler.com/bliki/OriginalStranglerFigApplication.html)
3. [Strangler Fig pattern. Azure Architecture Center, Microsoft Learn](https://learn.microsoft.com/en-us/azure/architecture/patterns/strangler-fig?trk=public_post_comment-text)
4. [Premanand Chandrasekaran (2023). Embracing the Strangler Fig pattern for legacy modernization, part one. Thoughtworks](https://www.thoughtworks.com/en-au/insights/articles/embracing-strangler-fig-pattern-legacy-modernization-part-one)
5. [Strangler fig pattern. AWS Prescriptive Guidance](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html?trk=article-ssr-frontend-pulse_little-text-block)
6. [Decomposing monoliths into microservices. AWS Prescriptive Guidance (PDF)](https://docs.aws.amazon.com/pdfs/prescriptive-guidance/latest/modernization-decomposing-monoliths/modernization-decomposing-monoliths.pdf)
7. [Jeff Escott, Jorge Alvarez (2025). Modernizing Legacy Applications with Event-Driven Architecture: The Leave-and-Layer Pattern. AWS Blog](https://aws.amazon.com/blogs/migration-and-modernization/modernizing-legacy-applications-with-event-driven-architecture-the-leave-and-layer-pattern/)
8. [Microservice Migration Using Strangler Fig Pattern: A Case Study on the Green Button System. 2020 International Computer Symposium, IEEE](https://doi.org/10.1109/ICS51289.2020.00107)
9. [The Journey to Serverless Migration: An Empirical Analysis of Intentions, Strategies, and Challenges. arXiv:2311.13249](https://arxiv.org/abs/2311.13249)
10. [AWS Migration Hub Refactor Spaces User Guide (PDF)](https://docs.aws.amazon.com/pdfs/migrationhub-refactor-spaces/latest/userguide/migrationhub-refactor-spaces-ug.pdf)
11. [Mobile App Rewrites via Dual Boot. arXiv:2608.15135](https://arxiv.org/abs/2608.15135)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 11, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Software engineering and development process › Software design and architecture › Titles Mu to Z

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/strangler-fig-pattern

English original: https://www.edgepedia.org/strangler-fig-pattern
