1
OpenDoc Series'
架构风格与基于网络的软件架构设计
(博士论文)
作者:Roy Thomas Fielding 博士
译者:李锟、廖志刚、刘丹、杨光
2
原文链接:Architectural Styles and the Design of Network-based Software Architectures
作者简介:
Roy Thomas Fielding 博士是 HTTP 和 URI 等 Web 架构标准的主要设计者,Apache HTTP
服务器的主要开发者。他为 Web 架构的设计作出极其杰出的贡献,他的工作为 Web 架构奠
定了坚实的基础。
译者简介:
李锟(ajaxcn.org
网站 站长)、廖志刚(91yee
翻译社区 负责人)、刘丹(Matrix
技术社
区负责人)、杨光(《重构与模式》的译者)
版权声明:
本论文是有版权的著作,英文原文的版权属于 Roy Thomas Fielding 博士所有,中文译
文的版权属于全体译者共同所有。译者在得到了 Fielding 博士的许可之后翻译了这篇论文。
本译文的发布权属于 Fielding 博士和全体译者共同所有。未经许可,其他网站不得全部或部
分转载本译文的内容。
致谢:
本论文是 Web 发展史上一篇非常重要的技术文献。出于社会责任感,译者认为极其有
必要将它介绍给国人,使国人得以一窥 HTTP 和 URI 等 Web 架构标准背后的基本原理。基
于相同的基本原理,Web 开发者能够设计并建造出最为高效的 Web 应用。因此译者发起了
这一公益性的翻译项目。除了四位主要的译者以外,来自新浪公司的田乐、丁舜佳和梁晓星
也参与了第 3 章的部分翻译工作,对他们的辛勤工作表示感谢。此外,国内一些专家认真地
审阅了论文的译文,提出了很多中肯的评论,使得译文的质量得以保证。在此向他们表示诚
挚的感谢,他们是:庄表伟、李琳骁、金尹、孟岩、骆古道、范凯、刘新生、刘江。
3
内容目录
论文摘要..............................................................................................................................................7
绪论......................................................................................................................................................8
第 1 章 软件架构...............................................................................................................................10
1.1 运行时抽象.............................................................................................................................10
1.2 元素 .......................................................................................................................................10
1.2.1 组件..................................................................................................................................11
1.2.2 连接器..............................................................................................................................12
1.2.3 数据 ................................................................................................................................12
1.3 配置.........................................................................................................................................12
1.4 属性 .......................................................................................................................................13
1.5 风格.........................................................................................................................................13
1.6 模式和模式语言.....................................................................................................................14
1.7 视图.........................................................................................................................................15
1.8 相关工作 ...............................................................................................................................15
1.8.1 设计方法学......................................................................................................................15
1.8.2 设计、设计模式、模式语言手册..................................................................................15
1.8.3 参考模型和特定于领域的软件架构..............................................................................16
1.8.4 架构描述语言..................................................................................................................16
1.8.5 形式化的架构模型..........................................................................................................17
1.9 小结 .......................................................................................................................................17
第 2 章 基于网络的应用的架构.......................................................................................................18
2.1 范围.........................................................................................................................................18
2.1.1 基于网络 vs. 分布式......................................................................................................18
2.1.2 应用软件 vs. 网络软件..................................................................................................18
2.2 评估应用软件架构的设计.....................................................................................................18
2.3 关键关注点的架构属性.........................................................................................................19
2.3.1 性能(Performance).....................................................................................................19
2.3.1.1 网络性能(Network Performance).......................................................................20
2.3.1.2 用户可觉察的性能(User-perceived Performance)............................................20
2.3.1.3 网络效率(Network Efficiency)..........................................................................21
2.3.2 可伸缩性(Scalability).................................................................................................21
2.3.3 简单性(Simplicity).....................................................................................................21
2.3.4 可修改性(Modifiability)............................................................................................21
2.3.4.1 可进化性(Evolvability)......................................................................................22
2.3.4.2 可扩展性(Extensibility)......................................................................................22
2.3.4.3 可定制性(Customizability)................................................................................22
2.3.4.4 可配置性(Configurability).................................................................................22
2.3.4.5 可重用性(Reusability)........................................................................................22
2.3.5 可见性(Visibility).......................................................................................................22
2.3.6 可移植性(Portability).................................................................................................23
2.3.7 可靠性(Reliability).....................................................................................................23
2.4 小结.........................................................................................................................................23
4
第 3 章 基于网络的架构风格...........................................................................................................24
3.1 分类方法学.............................................................................................................................24
3.1.1 选择哪些架构风格来进行分类......................................................................................24
3.1.2 风格所导致的架构属性..................................................................................................24
3.1.3 可视化..............................................................................................................................24
3.2 数据流风格(Data-flow Styles)..........................................................................................25
3.2.1 管道和过滤器(Pipe and Filter,PF)..........................................................................25
3.2.2 统一管道和过滤器(Uniform Pipe and Filter,UPF)................................................26
3.3 复制风格(Replication Styles)............................................................................................26
3.3.1 复制仓库(Replicated Repository,RR).....................................................................26
3.3.2 缓存(Cache,$)..........................................................................................................26
3.4 分层风格(Hierarchical Styles)...........................................................................................27
3.4.1 客户-服务器(Client-Server,CS)..............................................................................27
3.4.2 分层系统(Layered System,LS)和分层-客户-服务器(Layered-Client-
Server,LCS).........................................................................................................................28
3.4.3 客户-无状态-服务器(Client-Stateless-Server,CSS)...............................................28
3.4.4 客户-缓存-无状态-服务器(Client-Cache-Stateless-Server,C$SS)........................28
3.4.5 分层-客户-缓存-无状态-服务器(Layered-Client-Cache-Stateless-Server,LC$SS)
...................................................................................................................................................29
3.4.6 远程会话(Remote Session,RS)...............................................................................29
3.4.7 远程数据访问(Remote Data Access,RDA)............................................................29
3.5 移动代码风格(Mobile Code Styles)..................................................................................29
3.5.1 虚拟机(Virtual Machine,VM).................................................................................30
3.5.2 远程求值(Remote Evaluation,REV).......................................................................30
3.5.3 按需代码(Code on Demand,COD) .......................................................................31
3.5.4 分层-按需代码-客户-缓存-无状态-服务器(Layered-Code-on-Demand-Client-Cache-
Stateless-Server,LCODC$SS).............................................................................................31
3.5.5 移动代理(Mobile Agent,MA).................................................................................31
3.6 点对点风格(Peer-to-Peer Styles).......................................................................................31
3.6.1 基于事件的集成(Event-based Integration,EBI).....................................................32
3.6.2 C2.....................................................................................................................................32
3.6.3 分布式对象(Distributed Objects,DO).....................................................................33
3.6.4 被代理的分布式对象(Brokered Distributed Objects,BDO)..................................33
3.7 局限.........................................................................................................................................33
3.8 相关工作.................................................................................................................................34
3.8.1 架构风格和模式的分类方法..........................................................................................34
3.8.2 分布式系统和编程范例..................................................................................................35
3.8.3 中间件..............................................................................................................................35
3.9 小结.........................................................................................................................................35
第 4 章 设计 Web 架构:问题与洞察力..........................................................................................37
4.1 万维网应用领域的需求.........................................................................................................37
4.1.1 低门槛..............................................................................................................................37
4.1.2 可扩展性..........................................................................................................................37
4.1.3 分布式超媒体..................................................................................................................38
5
4.1.4 Internet 规模....................................................................................................................38
4.1.4.1 无法控制的可伸缩性..............................................................................................38
4.1.4.2 独立部署..................................................................................................................38
4.2 问题.........................................................................................................................................39
4.3 推导方法(Approach)..........................................................................................................39
4.4 小结.........................................................................................................................................40
第 5 章 表述性状态转移(REST).................................................................................................41
5.1 推导 REST...............................................................................................................................41
5.1.1 从“空”风格开始..........................................................................................................41
5.1.2 客户-服务器....................................................................................................................41
5.1.3 无状态..............................................................................................................................42
5.1.4 缓存..................................................................................................................................42
5.1.5 统一接口..........................................................................................................................44
5.1.6 分层系统..........................................................................................................................44
5.1.7 按需代码..........................................................................................................................45
5.1.8 风格推导小结..................................................................................................................46
5.2 REST 架构的元素...................................................................................................................46
5.2.1 数据元素(Data Elements)..........................................................................................46
5.2.1.1 资源和资源标识符(Resources and Resource Identifiers).................................47
5.2.1.2 表述(Representations)........................................................................................48
5.2.2 连接器(Connectors)...................................................................................................49
5.2.3 组件(Components).....................................................................................................50
5.3 REST 架构的视图...................................................................................................................51
5.3.1 过程视图(Process View)............................................................................................51
5.3.2 连接器视图(Connector View)....................................................................................52
5.3.3 数据视图(Data View).................................................................................................53
5.4 相关工作.................................................................................................................................54
5.5 小结.........................................................................................................................................55
第 6 章 经验与评估...........................................................................................................................56
6.1 Web 标准化.............................................................................................................................56
6.2 将 REST 应用于 URI..............................................................................................................57
6.2.1 重新定义资源..................................................................................................................57
6.2.2 操作影子(Manipulating Shadows).............................................................................57
6.2.3 远程创作(Remote Authoring)....................................................................................58
6.2.4 将语义绑定到 URI..........................................................................................................58
6.2.5 REST 在 URI 中的不匹配...............................................................................................59
6.3 将 REST 应用于 HTTP...........................................................................................................59
6.3.1 可扩展性..........................................................................................................................59
6.3.1.1 协议版本控制..........................................................................................................60
6.3.1.2 可扩展的协议元素..................................................................................................60
6.3.1.3 升级..........................................................................................................................61
6.3.2 自描述的消息..................................................................................................................61
6.3.2.1 主机..........................................................................................................................61
6.3.2.2 分层的编码..............................................................................................................61