SaaS迁移模式

Posted on Thu 08 April 2010 in it

原文: http://horicky.blogspot.com/2010/01/roadmap-to-saas.html

托GFW的福,我们看不到Richy Ho写的博客,更看不到Roadmap to SaaS里面的示意图。但这篇文章真的很不错,文字很简单,翻译出来和大家分享。

以下进入正文:

我发现了如何从传统Web应用一步一步迁移到SaaS的迁移模式。我会用一个J2EE的web应用架构做示例进行讲解,但对于其他技术平台来说,也是一样的。

1. 初始的web应用

At the very beginning, we have an web application that works well. We analyze the function of the web application and group the implementation classes accordingly.

在最开始的时候,程序还是一体的,我们要开始按照功能进行分组。

2. 拆分成多个应用

把一组功能拆分成独立的应用,通过Facade模式把服务接口暴露出来。应用间的通讯可以考虑Http Invoke/XML over HTTP/Restful等等

3. 部署到不同的主机上

To scale out beyond a single server"s capacity, we move the process to a separate machine. Notice that the machine can be a physical machine, or a virtual machine running on top of hypervisor.

把应用挪到不同的主机上。此时需要考虑网络方面的问题,例如带宽、健壮性等。

4. 做应用集群

If the service itself is stateless, we can easily scale out the service capacity by putting multiple machines (running the same service) into a server pool. A network load balancer will be used to spread the workload evenly to the member servers. When the workload increase, more machines can be added to the pool to boost up the overall capacity of the service. Elastic scalability provided by Cloud computing provider make growing and shrinking the pool even more rapid, and can hence dynamic workload more effectively.

就是做集群。

5. 持久层拆分

After we scale out the processing tier, we found the data tier becomes the bottleneck. So we also need to distribute the data access workload by partition the database according to the data key. Here are some classical techniques how we can build a distributed database.

然后开始做持久层的拆分。数据库分区或者其他什么方式。

6. 通过缓存降低系统负载

If the application is has a high read/write ratio, or has some tolerance of data staleness, we can add a cache layer to reduce the hit of the actual services. Clients will check the cache before sending the request to the service.

通过添加缓存降低服务访问。

We need to make sure the cached items to remain fresh.

There are various schemes to achieve this. e.g. cached items can be expired after certain timeout, or an explicit invalidation request can be make to specific cached items when the corresponding backend data has been changed.

保持数据同步的两种方式:1. 定期超时;2. 当后端数据刷新后清空当前缓存。

We can use local cache (reside in the same machine as the client) or a distributed cache engine such as Memcached or Oracle Coherence.

缓存应用可以是本地化的或分布式的。

7. 提供公共服务接口

At this point, we want to expose some of the services to the public either because this can bring revenue to our company or can facilitate a better B2B integration with our business partners. There are a lot of considerations to decide what to be expose, such as security consideration, scalability, service level agreement, utilization tracking ... etc.

为公共服务提供开放API接口

8. 部署服务入口网关

Once we decide what services to be exposed, we decide to use a specialized ingress service gateway to handle the concern that we outline above. Most of the XML service gateway is equipped with message validation, security checking, message transformation, routing logic.

为公共服务设置一个服务网关,进行:消息验证、安全检查、消息转换、设置路由逻辑等功能。

9. 设置服务出口网关

We not only providing service to the public, but may also consume other public services. In this case we deploy an egress service gateway which can help to lookup the service provider endpoints, extract the service policy of the public service providers ... etc.

做为服务的消费者,需要访问其他服务。提供出口网关可以进行服务定位、选取可用的服务提供者等功能。

One important function of the egress service gateway is to manage my dependencies to external service providers. It typically keeps a list of equivalent service providers together with their availability and response time, and routing my request to the one according to my selection criteria (e.g. cheapest, most-reliable, lowest-latency ... etc.)

10. 实现服务版本控制

My service will evolve after exposing to the public. In the ideal case, only the service implementation change but not the service interface so there is no need to change the client code. But mostly likely it is not that ideal. There are chances that I need to change the service interface or the message format. In this case, I may need to run multiple versions of the services simultaneously to make sure I am not breaking an existing clients. This means I need the ingress service gateway to be intelligent about routing the client request to the right version of the service implementation.

由于业务升级,我们会跑不同版本的服务来保证对老应用的兼容。这意味着服务入口网关需要智能的把客户端请求交给正确版本的服务实现。

A typical way is to maintain a matrix of version and keep track of their compatibilities. For example, we can use a release convention such that all minor releases is required to be backward compatible but major release is not required for that. Having this compatibility matrix information, the ingress gateway can determine the client version from its incoming request and route it to the server which has the latest compatible version.

一个典型的做法十维护一个版本功能矩阵。例如,小版本变化必须保证接口的一致性,而一个大发布版本没有这种要求。服务入口网关能够根据这个原则,把客户请求路由到最新的兼容版本下。

11. 把应用放到云平台中去

Purchase necessary hardware equipment and maintaining them can be very costly, especially when there are idle time in the usage of computing resources. Idle time is usually unavoidable because we need to budget the resource at the peak workload scenarios so there are idle time at non-peak hours. For a more efficient use of computing resources, we can consider some public cloud provider such as Amazon AWS or Microsoft Azure. But it is important that running an application in the cloud may need to redesign the application to cope with some unique characteristics of the cloud environment, such as how to deal with high network latency and bandwidth cost, as well as how to design application to live with an eventually consistent DB. https://blogger.googleusercontent.com/tracker/7994087232040033267-1021984589750791684?l=horicky.blogspot.com