クラウドデザインパターン

AWSクラウドデザインパターン

Azure アーキテクチャ センター クラウドの設計パターン
Azure Architecture Cloud Design Patterns
Azure 体系结构 云设计模式

どちらもデザインパターンのドキュメント集ですがAzureの方がよりモダンでコンテナ寄りです。
とは言っても今までのノウハウをうまくまとめたにすぎないです。
それから、AWSの方がTips集っぽくてちょっと古臭いです。
Sidecarなど、Azureは元々GoogleのDesign patterns for container-based distributed systems論文を引用しましたね。

しかし以下で全部なめてみたところは、別にクラウドだからこそのパターンがほとんどありませんでした。

Ambassador pattern
レガシーシステムに対して外部サービスを利用する際に簡単に拡張できる設計パターン。図の中にHOSTと書かれているが、PODにしても構いません。

An ambassador service can be thought of as an out-of-process proxy that is co-located with the client.
It is often used with legacy applications, or other applications that are difficult to modify, in order to extend their networking capabilities.

Anti-Corruption Layer pattern
レガシーシステムを完全にブラックボックスにして、サービス化対応できる設計パターン

Implement a façade or adapter layer between a modern application and a legacy system that it depends on.
This layer translates communications between the two systems, allowing the legacy system to remain unchanged while the modern application can avoid compromising its design and technological approach.

Backends for Frontends pattern
全体最適化ではなく、デバイス最適化の設計パターン。

Create separate backend services to be consumed by specific frontend applications or interfaces.
Fine tune the behavior and performance of each backend to best match the needs of the frontend environment, without worrying about affecting other frontend experiences.

Bulkhead pattern
Bulkhead(隔壁)は元々船内の区画を形作る仕切り壁のこと。ここによると:

SOLAS(海上における人命の安全のための国際条約)では、船体が損傷し、その結果船内に浸水した場 合に一定の生存区画を確保するため、船舶に横置水密隔壁を設置するよう義務づけています。船首隔壁 は衝突隔壁とも呼ばれ、衝突によって船首プレートが破損し、船首区画に浸水した場合に、第二の防壁 となるものです。

この設計パターンは、通信を区画整理する形でシステム全体の安全性を向上させる。
The following diagram shows bulkheads structured around connection pools that call individual services.

The next diagram shows multiple clients calling a single service. Each client is assigned a separate service instance.

Partition service instances into different groups, based on consumer load and availability requirements.
This design helps to isolate failures, and allows you to sustain service functionality for some consumers, even during a failure.

Cache-Aside pattern
常識的な事ですが、まあ、キャッシュを使いましょう。

Load data on demand into a cache from a data store.
This can improve performance and also helps to maintain consistency between data held in the cache and data in the underlying data store.

Circuit Breaker pattern
最近一番有名なパターンです。昔こんな特許を出していたが、考え方が近いですね。(ただhalfopenまで実装できなかった。。)

A circuit breaker acts as a proxy for operations that might fail.
The proxy should monitor the number of recent failures that have occurred, and use this information to decide whether to allow the operation to proceed, or simply return an exception immediately.+

Command and Query Responsibility Segregation (CQRS) pattern
これも約20年間業務で使ってきたパターンですね。

Command and Query Responsibility Segregation (CQRS) is a pattern that segregates the operations that read data (queries) from the operations that update data (commands) by using separate interfaces.
This means that the data models used for querying and updates are different.

Compensating Transaction pattern
eventual consistency、つまり最終一貫性の方が重要です。だから途中経過を大事に保管しないと。
To avoid contention and improve performance in a distributed environment, an application shouldn't try to provide strong transactional consistency.
Rather, the application should implement eventual consistency.
In this model, a typical business operation consists of a series of separate steps.
While these steps are being performed, the overall view of the system state might be inconsistent,
but when the operation has completed and all of the steps have been executed the system should become consistent again.

The steps in a compensating transaction must undo the effects of the steps in the original operation.
A common approach is to use a workflow to implement an eventually consistent operation that requires compensation.

Competing Consumers pattern
オフライン処理はMQとマルチコンシューマーを使うことは、約20年間業務で使ってきました。

Enable multiple concurrent consumers to process messages received on the same messaging channel.
This enables a system to process multiple messages concurrently to optimize throughput, to improve scalability and availability, and to balance the workload.
The system can dynamically increase or decrease the number of instances of the consumer service as the volume of messages fluctuates.

Compute Resource Consolidation pattern
コンピューティングリソースはできるだけ集約して節約しましょう。

Consolidate multiple tasks or operations into a single computational unit.
This can increase compute resource utilization, and reduce the costs and management overhead associated with performing compute processing in cloud-hosted applications.

Event Sourcing pattern
これも大きいシステムの前提で、いちいち状態を更新したら大変なので、追加だけでログを取れれば、最後に一遍に更新すればいいとの設計パターンです。
LOGファイルのstream IOみたいな感じですからパフォーマンスがいいに決まっています。


Instead of storing just the current state of the data in a domain, use an append-only store to record the full series of actions taken on that data.
This can simplify tasks in complex domains, by avoiding the need to synchronize the data model and the business domain, while improving performance, scalability, and responsiveness.
Events are simple objects that describe some action that occurred, together with any associated data required to describe the action represented by the event.
Events don't directly update a data store. They're simply recorded for handling at the appropriate time.
This can simplify implementation and management.

External Configuration Store pattern
スケールし易いステートレスはあまり前だが、コンフィグレスもいいですよね。

Changes to the configuration require the application be redeployed, often resulting in unacceptable downtime and other administrative overhead.
Store the configuration information in external storage, and provide an interface that can be used to quickly and efficiently read and update configuration settings.

Federated Identity pattern
OAuthやSSOの話ですね。

Delegate authentication to an external identity provider. This can simplify development, minimize the requirement for user administration, and improve the user experience of the application.

Gatekeeper pattern
内部データとサービスを守るために、gateway(gatekeeper門衛)を導入しましょうとのことですね。

Protect applications and services by using a dedicated host instance that acts as a broker between clients and the application or service, validates and sanitizes requests, and passes requests and data between them.
This can provide an additional layer of security, and limit the attack surface of the system.

Gateway Aggregation pattern
上に似てますが、mashupできるgatewayがあればデバイス最適化やプレゼンテーション層とビジネス層の分離も簡単にできますね。

Use a gateway to reduce chattiness between the client and the services.
The gateway receives client requests, dispatches requests to the various backend systems, and then aggregates the results and sends them back to the requesting client.
This pattern can reduce the number of requests that the application makes to backend services, and improve application performance over high-latency networks.

Gateway Offloading pattern
API Gatewayの必要性は、10年前からいろんな方に言ってきたことですが、当時理解してくれる人がほとんど居なかったです。

Offload some features into an API gateway, particularly cross-cutting concerns such as certificate management, authentication, SSL termination, monitoring, protocol translation, or throttling.

Gateway Routing pattern
またgatewayパターン。用途に応じていろんな事ができそうですね。

Route requests to multiple services using a single endpoint.
This pattern is useful when you wish to expose multiple services on a single endpoint and route to the appropriate service based on the request.
Place a gateway in front of a set of applications, services, or deployments. Use application Layer 7 routing to route the request to the appropriate instances.
This pattern can also help with deployment, by allowing you to manage how updates are rolled out to users.

Health Endpoint Monitoring pattern
外部から監視しましょう。(どうしてこんなに長い説明が必要のかな。。)

Implement functional checks in an application that external tools can access through exposed endpoints at regular intervals.
This can help to verify that applications and services are performing correctly.

Index Table pattern
たくさんの変形がありますが、要はビジネスロジックをベースにIndexを自分たちで設計しましょう。DBの中のブラックボックスにしない事。いいドキュメントですね

Create indexes over the fields in data stores that are frequently referenced by queries. This pattern can improve query performance by allowing applications to more quickly locate the data to retrieve from a data store.

Leader Election pattern
自分は使った事がないですが、リーダ選出のアルゴリズムに気になります。 Bully Algorithm or the Ring Algorithm.
oordinate the actions performed by a collection of collaborating instances in a distributed application by electing one instance as the leader that assumes responsibility for managing the others.
This can help to ensure that instances don't conflict with each other, cause contention for shared resources, or inadvertently interfere with the work that other instances are performing.

Materialized View pattern
VIEWは普通に使ってるですよね?

When storing data, the priority for developers and data administrators is often focused on how the data is stored, as opposed to how it's read.
To support efficient querying, a common solution is to generate, in advance, a view that materializes the data in a format suited to the required results set.
The Materialized View pattern describes generating prepopulated views of data in environments where the source data isn't in a suitable format for querying,
where generating a suitable query is difficult, or where query performance is poor due to the nature of the data or the data store.

Pipes and Filters pattern
pipeとfilterの概念は分かりやすいですが、実装上はほぼMQを使いますね。これも長年オフライン処理の定番ですからね。


Break down the processing required for each stream into a set of separate components (or filters), each performing a single task.
By standardizing the format of the data that each component receives and sends, these filters can be combined together into a pipeline.
This helps to avoid duplicating code, and makes it easy to remove, replace, or integrate additional components if the processing requirements change.

Priority Queue pattern
プライオリティキューはあったらいいなとの存在ですが、1について何かいいMQ製品があるのかな?
2の方が一般的かもね。
Prioritize requests sent to services so that requests with a higher priority are received and processed more quickly than those with a lower priority.
1 The figure illustrates a queue with priority messaging.

2 The next figure illustrates using separate message queues for each priority.

Queue-Based Load Leveling pattern
これも昔から使ってきた手法ですが、名前がカッコイイですね。


Use a queue that acts as a buffer between a task and a service it invokes in order to smooth intermittent heavy loads that can cause the service to fail or the task to time out.
This can help to minimize the impact of peaks in demand on availability and responsiveness for both the task and the service.

Retry pattern
まあ、これも常識的な手法ですよね?

Enable an application to handle transient failures when it tries to connect to a service or network resource, by transparently retrying a failed operation. This can improve the stability of the application.+

Scheduler Agent Supervisor pattern
最初はCRONの事かと思いましたが、

サンプルを見るとイベント管理と一緒に使っているから、まぁそんなもんですね。

The Scheduler arranges for the steps that make up the task to be executed and orchestrates their operation.
The Agent contains logic that encapsulates a call to a remote service, or access to a remote resource referenced by a step in a task.
The Supervisor monitors the status of the steps in the task being performed by the Scheduler.

Sharding pattern
これも20年前から使ってきた手法だから特にコメントが必要ない

Divide a data store into a set of horizontal partitions or shards. This can improve scalability when storing and accessing large volumes of data.

Sidecar pattern
これは最近よく聞くパターンですね。HOSTをPODに置き換え、コンテナ間でWebAPIやローカルファイルで連携できるから便利。

Deploy components of an application into a separate process or container to provide isolation and encapsulation.
This pattern can also enable applications to be composed of heterogeneous components and technologies.

This pattern is named Sidecar because it resembles a sidecar attached to a motorcycle.
In the pattern, the sidecar is attached to a parent application and provides supporting features for the application.
The sidecar also shares the same lifecycle as the parent application, being created and retired alongside the parent.
The sidecar pattern is sometimes referred to as the sidekick pattern and is a decomposition pattern.

Applications and services often require related functionality, such as monitoring, logging, configuration, and networking services.
These peripheral tasks can be implemented as separate components or services.

Co-locate a cohesive set of tasks with the primary application, but place them inside their own process or container, providing a homogeneous interface for platform services across languages.

Static Content Hosting pattern
また常識的な話

Deploy static content to a cloud-based storage service that can deliver them directly to the client. This can reduce the need for potentially expensive compute instances.

Strangler pattern
大規模の新システムへ切り替え時に、段階的に、strangler facadeという層を使って、徐々に以降していく事が大事ですね。

Incrementally replace specific pieces of functionality with new applications and services.
Create a façade that intercepts requests going to the backend legacy system.
The façade routes these requests either to the legacy application or the new services.
Existing features can be migrated to the new system gradually, and consumers can continue using the same interface, unaware that any migration has taken place.

Throttling pattern
重要だと思いますが、今まであまり使った事がないので何が便利がソリョーションがあるかがわからない

There're many strategies available for handling varying load in the cloud, depending on the business goals for the application.
One strategy is to use autoscaling to match the provisioned resources to the user needs at any given time.

An alternative strategy to autoscaling is to allow applications to use resources only up to a limit, and then throttle them when this limit is reached.
The system should monitor how it's using resources so that, when usage exceeds the threshold, it can throttle requests from one or more users.
This will enable the system to continue functioning and meet any service level agreements (SLAs) that are in place.

Valet Key pattern
また常識的な話

One typical solution is to restrict access to the data store's public connection and provide the client with a key or token that the data store can validate.+

This key or token is usually referred to as a valet key.
It provides time-limited access to specific resources and allows only predefined operations such as reading and writing to storage or queues, or uploading and downloading in a web browser.
Applications can create and issue valet keys to client devices and web browsers quickly and easily, allowing clients to perform the required operations without requiring the application to directly handle the data transfer.

2018/03/07 更新
コンテナ・デザイン・パターンの論文要約