SlideShare a Scribd company logo
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
27th Jan, 2021
Kensuke Shimokawa
今日から始める
イベントドリブンアーキテクチャ
@_kensh
AWS Expert Online JAWS-UG
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Who am I?
Name
Kensuke Shimokawa
Company
Amazon Web Services Japan K.K.
Role
Serverless Specialist Solutions Architect
@_kensh
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
本セッションは
想定される聴講者
• AWSをご利用されている事業者、デベロッパー
• AWSを今後利用したビジネスを考えている方
• イベントドリブンアーキテクチャ構築に興味がある方
ゴール
• システムでのイベントドリブンアーキテクチャの使い所を理解していただく
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イノベーションループ
Listen
Idea
Experiment
イノベーション
ループ
傾聴
アイデア
実験
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
"デリバリー速度"の獲得。
マイクロサービスの最大のメリットはビジネス変化に対応する
"デリバリー速度"の獲得。
でもAPIで作ったサービスは頻繁な変更に対応するのは難しいですよね。
なぜならAPIにはインターフェース契約があるから。
そこで、アイデアとして登場したのが ”疎結合” にマイクロサービス を組み立て
る、イベントドリブンアーキテクチャ。
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Table of contents
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アーキテクチャのゴールは
"デリバリー速度"の獲得
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
モノリスからマイクロサービス へ
Monolith
全てを担当
Microservice
一つの責務の組み合わせ
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
2001年のAmazonでは、、、
monolithic application
+ teams
2001
学び: アジリティのために分散が必要
2002
microservices
+ 2 pizza teams
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
アーキテクチャの結合度
小さなピースに分けて
ゆるく結合させたい
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
小さなピースをAPIで結合してみる
API
API
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
契約による結合
API
API
インターフェース契約
APIにはインターフェースを公開し
利用者に宣言する必要がある
利用者は公開者の宣言にしたがって
送信する義務を負う
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
互いに依存する
API
API
(API利用者)
契約を守らないと呼び出せない
(API提供者)
契約を破棄できない
不自然な維持、冗長な拡張
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
仕様と実装の乖離が許されないAPI = 契約
• 契約を記述する手段の進化
• 契約の配布やスキーマレジストリ
管理のマネージド化
• ただし、契約は公開されるが、強制できる
ものではない。
• そして、APIエコノミーへ
• クローズドなAPIからオープンなAPIへ
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
多様化、複雑化、膨大化する依存関係
API
互いに依存する
互いに依存する
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
“デリバリー速度”の獲得?
達成できたか?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
同期的なAPIの課題
• 他サービスの障害に影響を受ける
• サービスのIPが変わった場合の発見が難しい
• API自体の数が増加し、クライアントへの統一した体験が提供しにくい
• HTTPリソースやメソッドごとに要件が複雑化
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
APIにおける様々な改善
• サービスメッシュ
• API ゲートウェイ
• サーキットブレーカー
• 集約ログ
• ポリグロット
• GraphQL
• サービスディスカバリ
(注意)
• 今回のセッションではイベントの理解の
ために、あえてAPIと比較をしています
が、APIとイベントは排他の関係ではな
く、通常は協調して利用します
• APIの管理方法も日々進化していますの
で、APIの課題がそのまま当てはまるわ
けではありません
※本日のセッションではAPIの管理方法の進化については割愛
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
event
[i-’vent] noun
システムの状態が変化
したことを示す信号
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントとは
• イベントは状態の変化に関する情報をサービス間で共有するためのメカニズム
• Immutable – イベントは過去に遡っての修正はできない
• イベントには意味的な意図があり、過去形の動詞として表現可能,
• e.g. “customer_created”
• コンテキスト共通のプロパティによって、システムの相関を取っている
• e.g. “customer_id”
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Eventは時系列に事実を
伝える手段
Time What
2021 01 21 08 07 06 CustomerCreated
2021 01 21 08 07 09 OrderCreated
2021 01 21 08 07 13 PaymentSuccessful
2021 01 21 08 07 17 CustomerUpdated
. . . . . .
イベントはWhatを伝える時系列データ
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントは観測するものであり、命令ではない
命令としての command 観測による event
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
サービスとイベントルーティング機能を切り離す
プロデューサ、コンシューマ
の抽象化
イベントを選択して
フィルタリング可能に
プロデューサ コンシューマ
ルーティング
送信イベント 受信イベント
フィルタリング
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
応答性とサービス間依存度の違い
API Event
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
契約時
• API設計時にサービス間の契約を締結
• 変化のためにはサービス実装の変更
API
API
同期APIと非同期イベント配信の規約設定タイミング
イベント配信時
• 非同期実行による分散
• 障害伝搬リスクの軽減
• 変化のためには配信ルールの変更
Service A Service B
Message
Message
Service A Service B
Event
API Event
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
結合度を実例で確認 (同期API)
プロデューサ
コンシューマ
😀
受注
サービス
発送
サービス
会計
サービス
• プロデューサとコンシューマ
が密結合
• 複数サービスが障害ポイント
• サービスクオリティの低いも
のが全体のサービス品質を決
定
• 外部への依存度が大きく、拡
張性が乏しい
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
結合度を実例で確認 (同期API)
プロデューサ
コンシューマ
受注
サービス
発送
サービス
会計
サービス
• プロデューサとコンシューマ
が密結合
• 複数サービスが障害ポイント
• サービスクオリティの低いも
のが全体のサービス品質を決
定
• 外部への依存度が大きく、拡
張性が乏しい
😩
ダウンストリームの
障害に影響を受ける
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
結合度を実例で確認 (同期API)
プロデューサ
コンシューマ
受注
サービス
発送
サービス
会計
サービス
在庫
サービス
• プロデューサとコンシューマ
が密結合
• 複数サービスが障害ポイント
• サービスクオリティの低いも
のが全体のサービス品質を決
定
• 外部への依存度が大きく、拡
張性が乏しい
😀
新サービス追加
コードの修正が必要
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
結合度を実例で確認 (非同期Event)
プロデューサ
コンシューマ
😀
受注
サービス
発送
サービス
会計
サービス
• プロデューサとコンシューマ
が疎結合
• 各サービスは独立
• 品質、可用性管理を独自に実
施可能
• 外部への依存度が低いため、
拡張性が高い
Event
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
結合度を実例で確認 (非同期Event)
プロデューサ
コンシューマ
😀
受注
サービス
発送
サービス
会計
サービス
• プロデューサとコンシューマ
が疎結合
• 各サービスは独立
• 品質、可用性管理を独自に実
施可能
• 外部への依存度が低いため、
拡張性が高い
Event
ダウンストリームの
障害からの分離
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
結合度を実例で確認 (非同期Event)
プロデューサ
コンシューマ
😀
受注
サービス
発送
サービス
会計
サービス
• プロデューサとコンシューマ
が疎結合
• 各サービスは独立
• 品質、可用性管理を独自に実
施可能
• 外部への依存度が低いため、
拡張性が高い
Event
在庫
サービス
コードの修正不要
新サービス追加時に
Subscribeするだけ
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンアーキテクチャを何で実装するか
プロデューサ
コンシューマ
😀
受注
サービス
発送
サービス
会計
サービス
• 実装の考慮点
• 可用性についての検討
• スケーラビリティにつ
いての検討
• サーバーの運用管理
• コスト見積もり
Event
在庫
サービス
この部分の
イベント管理をどの
ように実装するか
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
サーバーレス とは?
サーバーがない?
サーバーの存在を意識しない
• ユーザーコントロール可能なサーバーを前提としない
• AWS のフルマネージドな管理
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
サーバーレスを選択するビジネス価値
インフラのプロビジョニング不要
サーバー管理不要
自動でスケール
価値に対する支払い 高可用かつ安全
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
サーバーレスの効能
+
利用費の
適正化
作業量の
削減
+
時間の
短縮
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントの管理はサーバーレス サービスで
プロデューサ
コンシューマ
😀
受注
サービス
発送
サービス
会計
サービス
• インフラのプロビジョニング
不要、サーバー管理不要
• 自動でスケール
• 価値に対する支払い
• 高可用かつ安全
Event
在庫
サービス
サーバーレス
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンのパーツ
非同期イベント
応答性を高め、相互依存性
を低減
イベントルーター
プロデューサとコンシューマを
互いから抽象化
イベントストア
ビジネスロジックのプロセスが
稼働可能になるまでストア可能
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWSのイベント、メッセージングサービス
イベントルーター イベントストア
キュー ストリーム トピック イベントバス
サーバーレス
マネージドOSS
Amazon SQS
Amazon MQ
Amazon SNS
Amazon MQ
Amazon Kinesis
Amazon MSK
Amazon EventBridge
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SNS Topic
Data
Amazon Simple Notification Service (SNS)
• Publish / subscribe モデルメッセージング
• 高スループット, 高信頼性メッセージング
• 複数のパブリッシャーに配信
• ファンアウト
• メッセージフィルタリンを利用して配信タ
ーゲットを指定可能
• 非同期Lambda実行
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Message
SQS
Queue
SQS はLambda
サービス側で関
数から成功応答
が返った場合に
メッセージ削除
Amazon Simple Queue Service (SQS)
• 大量メッセージ
• メッセージのバッチ処理
• At least once 配信 (標準キュー)
• 複数回受信を防ぐ可視性タイムアウト
• 同期Lambda実行
• Lambdaはロングポーリング
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon Kinesis Data Streams
• リアルタイムメッセージング
• At least once 配信(Lambda統合時)
• Lambda関数はバッチ取得可能
• 1メッセージ内に論理バッチも可能
• 同期Lambda実行
Kinesis
Stream
Lambdaサービス
は、メッセージ
が期限切れで削
除されるまで、
ポーリング
Data
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
各モデルでのイベントハンドリング
イベントストアを
利用しない
(FIFOで順序)
高耐久性の
メッセージ処理
(FIFOで順序)
Amazon SNS
Amazon SQS
Amazon
Kinesis
高耐久性の
メッセージ処理
(順序の保証)
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridge
AWS Cloud
AWS Cloud
AWS Cloud
Amazon
EventBridge
異なるチーム、組織の間でも、Push型での情報連携(イベント通知)を
可能にするイベントバス
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Lambdaの非同期実行
Amazon S3
Amazon SNS
Amazon SES
Amazon
EventBridge
Amazon
CloudWatch Logs
AWS Config
Amazon
CloudFormation
AWS CodeCommit
AWS Lambda
Amazon SNS
Amazon SQS
Amazon
EventBridge
Lambda
Function
onSuccess
onFailure
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブン・ユースケース
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ファイルアップロード処理
1. Amazon S3 バケットにファイ
ルをアップロード
2. Lambda関数の非同期実行
• イベントペイロード:
» Bucket name
» Object key
1
2
Lambda + Amazon S3
Amazon S3
Upload
Event
file
Lambda
Function
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ファイルアップロード処理
3. Amazon Rekognitionを使用し
た画像解析
4. 画像解析の結果を保存
1
2
イメージ解析、データ永続化
Amazon
Rekognition
Amazon
DynamoDB
3
4
file
Upload
Event
Amazon S3
Lambda
Function
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ストリームデータの取り込みと保存
1. LambdaがKinesis Data Streamからメッセージポーリング
2. 関数が同期的にLambdaサービスから呼び出される
3. 関数によるメッセージの保存
1 2
取得、処理、保存
Amazon
Redshift
Amazon
Elasticsearch
Service
3
Kinesis Data Stream Lambda Lambda
Function
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ダウンストリームの保護
1. API Gatewayに到達したメッセージをSQSにバッファリング
2. 関数が同期的にLambdaサービスから呼び出される
• 同時実行数設定によるスループット調整
3. オンプレミスデータベースに対する、Lambda関数によるメッセージ
の保存
1 2
スループットの調整
3
Lambda Lambda
Function
Amazon SQS
Amazon API Gateway
オンプレミス
データベース
物理サーバー
低スループット
高スループット
202
accepted
低可用性、ローパフォーマンス
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
SaaSとのイベント連携
1. API Gatewayでの Webhookや、定期起動Lambdaによるポーリ
ングではなく、EventBridgeのイベントバス経由でイベント連携
2. イベントの種類に応じて各種マイクロサービスを実行
モニタリングアラームの受信
AWS Cloud
Amazon
EventBridge
アラーム
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンアーキテクチャ
導入への流れ
Journey to event-driven architectures
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンアーキテクチャ導入への流れ
STEP 1
ドメインに対する考慮
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
システムではなく、ビジネスのイベントを考えてみる
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントをビジネスドメインに紐付ける
販売 配送センター サポート
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ビジネスプロセスを一旦オーケストレーションで考えてみる
販売
オーケストレーター
決済管理
1
4
6
注文イベント
2
在庫管理
3
5
7
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ドメイン境界を越える処理をSubscriptionに置き換える
販売 発送センター
注文入ったよ
注文が入ったら教えてね
Subscription
Notification
1
2
非同期Event
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンのモデリング
EventStorming
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンアーキテクチャ導入への流れ
STEP 2
イベントルータの選定
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ルーターが必要になるかどうか?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
まだ、必要じゃない?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
本当に、まだ必要ない?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
設計時にルーターを入れて非同期にできるかはまず確認!
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンアーキテクチャ導入への流れ
STEP 3
イベントストアの選定
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントストアで復元力とスケーラビリティを向上
ビジネスロジックサービスが処理可能に
なるまでメッセージをバッファリング
Event store
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンアーキテクチャ導入への流れ
STEP 4
イベントスキーマの考慮
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントはそのままの生の情報ではない
注文123は、顧客456に
よって午前10時47分に
作成されました。
注文123は、顧客456によっ
て午前10時47分に作成されま
した。現在のステータスは
オープンで、合計は$ 237.51
で、商品は…
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
必要となる属性を考える
123
456
注文123はどの
ユーザの注文?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridgeイベントスキーマの例
{
"version": "0",
"id": "adeacade-c34c-ce58-c4a0-74f106398c4e",
"account": "123456789012",
"region": "us-east-1",
"time": "2019-12-02T21:46:19Z",
"source": "order-service",
"detail-type": "New Order",
"resources": [],
"detail": {
"orderId": "cfb2ae566f9b",
"customerId": "C12345",
...
}
}
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
"version": "0",
"id": "adeacade-c34c-ce58-c4a0-74f106398c4e",
"account": "123456789012",
"region": "us-east-1",
"time": "2019-12-02T21:46:19Z",
"source": "order-service",
"detail-type": "New Order",
"resources": [],
"detail": {
"orderId": "cfb2ae566f9b",
"customerId": "C12345",
...
}
}
Amazon EventBridgeイベントスキーマの例
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
"version": "0",
"id": "adeacade-c34c-ce58-c4a0-74f106398c4e",
"account": "123456789012",
"region": "us-east-1",
"time": "2019-12-02T21:46:19Z",
"source": "order-service",
"detail-type": "New Order",
"resources": [],
"detail": {
"orderId": "cfb2ae566f9b",
"customerId": "C12345",
...
}
}
Amazon EventBridgeイベントスキーマの例
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{
"version": "0",
"id": "adeacade-c34c-ce58-c4a0-74f106398c4e",
"account": "123456789012",
"region": "us-east-1",
"time": "2019-12-02T21:46:19Z",
"source": "order-service",
"detail-type": "New Order",
"resources": [],
"detail": {
"orderId": "cfb2ae566f9b",
"customerId": "C12345",
...
}
}
Amazon EventBridgeイベントスキーマの例
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon EventBridgeイベントスキーマの例
{
"version": "0",
"id": "adeacade-c34c-ce58-c4a0-74f106398c4e",
"account": "123456789012",
"region": "us-east-1",
"time": "2019-12-02T21:46:19Z",
"source": "order-service",
"detail-type": "New Order",
"resources": [],
"detail": {
"orderId": "cfb2ae566f9b",
"customerId": "C12345",
...
}
}
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブン・デザインパターン
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブン・デザインパターン
• コレオグラフィ
• 全体の作業を制御する指揮者は存在せず、個々のサービスに予め与
えられた動作条件に従ってサービスを実行
• コマンドクエリ責務分離
• データ ストアの読み取り操作と更新操作を分離
• イベント ソーシングパターン
• データに対して実行された一連のすべてのアクションを記録
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コレオグラフィ - Choreography
Streams, Topics, Queues
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
マイクロサービスの依存関係グラフ
https://www.thoughtworks.com/insights/blog/scaling-microservices-event-stream
Event
APIで結合 コレオグラフィー
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コレオグラフィーパターンとは
• 必要なすべての情報を含んだ最初のイベントを 1 つのメッセージに保存し
て、最初のトランザクションを完了
• 他のサービスがそのメッセージを非同期的に取得し、それぞれのタスクを
完了させる
• サービスが疎結合になり、直接互いに影響を与えない
• メッセージの保存と取得が非同期の関係になり、スケーラビリティと信頼
性が向上
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コレオグラフィーパターン
ユーザー
リクエストサービス リクエストキュー
サービスA
サービスB
サービスC
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
実装例1: SNS、 SQS、 Lambdaの利用
ユーザー
リクエストサービス Amazon
SNS
Amazon SQS
Amazon SQS
Amazon SQS
AWS Lambda
AWS Lambda
AWS Lambda
ファンアウト
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
実装例2: Amazon EventBridgeの利用 配送
ポイント
プレミアム会員
カート
支払
支払い方法
認証
注文
1分毎に実行
Events
会員
ステータス
支払認証
カートに
入れる
注文完了
Amazon
EventBridge
リクエストサービス イベントバス
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コマンドクエリ責務分離
CQRSパターン
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コマンドクエリ責務分離パターンとは
• コマンドクエリ責務分離(Command-Query Responsibility Segregation:
CQRS)パターンはデータを更新するコマンドと参照するクエリを分離するこ
とで、ユースケースに応じて個別にスケールすることを可能とするパターン
• データソースを分離することで異なるデータ構造を取ることも可能となり、ク
エリ側はクエリで返すデータ転送オブジェクト(Data Transfer Object : DTO)
に合わせた形のスキーマとすることでオブジェクト関係マッピング(Object
Relational Mapping : ORM)のオーバーヘッドを軽減することも可能になる
• コマンド側とクエリ側が結果整合性を許容する必要がある
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コマンドクエリ責務共有パターン
ユーザー
サービス
ドメインモデル ドメインモデル
ORM ORM
データ転送
オブジェクト
クエリ
更新
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コマンドクエリ責務分離(CQRS)パターン
ユーザー
コマンドサービス
ドメインモデル
データ転送
オブジェクト
クエリ
更新
クエリサービス
データ転送
オブジェクト
非同期
結果整合
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
実装例1: Kinesis Data StreamsとLambdaを利用
フロントサービス Amazon Kinesis
Data Streams
AWS Lambda
AWS Lambda Amazon Aurora
正規化テーブル
ユーザー
Amazon DynamoDB
非正規化テーブル
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
実装例2: DynamoDB StreamsとLambdaを利用
ユーザー Amazon DynamoDB
Streams
非正規化テーブル
AWS Lambda Amazon Aurora
正規化テーブル
フロントサービス
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベント ソーシング
Event Sourcing
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントソーシングパターンとは
• データストアを直接更新する代わりに、注文の発注、クレジット照会、出荷中
の注文など、ビジネスロジックに重要なイベントを耐久性のあるイベントログ
に追加
• イベントレコードは個別に保存されるため、すべての更新はアトミック (分割
不可かつ削減不可)
• 保存されたイベントを再度処理するだけで、アプリケーションのいかなる時点
の状態でも再構築 可能
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベント ソーシングパターン
ユーザー
プロセス
イベントログ
イベント
プロセス プロセス
状態
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Kinesis Data Streams (or SQS FIFO)とLambdaによる実装例
ユーザー
Amazon Kinesis
Data Streams
AWS Lambda
イベント
メッセージ
状態
Amazon SQS
FIFO
or
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
イベントドリブンアーキテクチャ
選択における観点
Design Considerations
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
At-least once 配信
イベントは、ターゲットに複数回配信
されることも。処理されたイベントの
状態を追跡することによって重複イベ
ントを検出するロジックを含める
(冪等性)
配信セマンティクス
Exactly-once 配信*
AWSサービスに重複排除に使用す
る識別子を渡すことで重複排除
* Lambdaでリトライ設定している場合は、At-least
once
• Amazon EventBridge
• Amazon SNS 標準トピック
• Amazon SQS 標準 キュー
• Amazon Kinesis
• Amazon SNS FIFO トピック
• Amazon SQS FIFO キュー
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
順序保証なし
イベント/メッセージが順序保証なしで
配信
順序セマンティクス*
順序保証
イベントは、パーティション、
メッセージグループなどの中で順
番に配信
(グローバルな順序保証はありません)
• Amazon EventBridge
• Amazon SNS 標準トピック
• Amazon SQS 標準 キュー
• Amazon Kinesis
• Amazon SNS FIFO トピック
• Amazon SQS FIFO キュー
* 順不同のイベント処理ロジックが受入可能かは、ビジネス要件次第となります。順不動なイベントを処理する
ようにアプリケーションを設計できない場合は、代わりにオーケストレーションも検討
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
まとめ
マイクロサービスの最大のメリットはビジネス変化に対応する
"デリバリー速度"の獲得
• イベントドリブンアーキテクチャで疎結合にすることでデリバリー速度を高
める。
• AWSのサーバーレス サービスを利用することで、イベントドリブンアーキテ
クチャを素早く導入できる。
• アーキテクチャパターンや導入の道筋を知ることで、システム設計に活かす
ことができる。
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank you!
@_kensh
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Appendix
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EventBridgeサービスクオータ(抜粋)
• PutEvents: Depends on region (2400-400), regional
• Invocations: Depends on region (4500-750), regional
• Buses per account/region: 100, hard limit
• Rules per bus: 300
• Targets per rule: 5, hard limit
• Event pattern size: 2048 characters, hard limit
https://docs.aws.amazon.com/eventbridge/latest/userguide/cloudwatch-limits-eventbridge.html

More Related Content

PDF
ストリーム処理を支えるキューイングシステムの選び方
Yoshiyasu SAEKI
 
PDF
DevOps with Database on AWS
Amazon Web Services Japan
 
PDF
20200826 AWS Black Belt Online Seminar AWS CloudFormation
Amazon Web Services Japan
 
PDF
[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな
Amazon Web Services Japan
 
PDF
20180425 AWS Black Belt Online Seminar Amazon Relational Database Service (Am...
Amazon Web Services Japan
 
PDF
20200303 AWS Black Belt Online Seminar AWS Cloud Development Kit (CDK)
Amazon Web Services Japan
 
PDF
Pmo
ammody
 
PDF
20191002 AWS Black Belt Online Seminar Amazon EC2 Auto Scaling and AWS Auto S...
Amazon Web Services Japan
 
ストリーム処理を支えるキューイングシステムの選び方
Yoshiyasu SAEKI
 
DevOps with Database on AWS
Amazon Web Services Japan
 
20200826 AWS Black Belt Online Seminar AWS CloudFormation
Amazon Web Services Japan
 
[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな
Amazon Web Services Japan
 
20180425 AWS Black Belt Online Seminar Amazon Relational Database Service (Am...
Amazon Web Services Japan
 
20200303 AWS Black Belt Online Seminar AWS Cloud Development Kit (CDK)
Amazon Web Services Japan
 
Pmo
ammody
 
20191002 AWS Black Belt Online Seminar Amazon EC2 Auto Scaling and AWS Auto S...
Amazon Web Services Japan
 

What's hot (20)

PDF
20190806 AWS Black Belt Online Seminar AWS Glue
Amazon Web Services Japan
 
PDF
20191016 AWS Black Belt Online Seminar Amazon Route 53 Resolver
Amazon Web Services Japan
 
PPTX
モノリスからマイクロサービスへの移行 ~ストラングラーパターンの検証~(Spring Fest 2020講演資料)
NTT DATA Technology & Innovation
 
PDF
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
Amazon Web Services Japan
 
PDF
20190604 AWS Black Belt Online Seminar Amazon Simple Notification Service (SNS)
Amazon Web Services Japan
 
PDF
20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
Amazon Web Services Japan
 
PDF
マルチテナント化で知っておきたいデータベースのこと
Amazon Web Services Japan
 
PDF
ログ管理のベストプラクティス
Akihiro Kuwano
 
PDF
20190911 AWS Black Belt Online Seminar AWS Batch
Amazon Web Services Japan
 
PDF
Infrastructure as Code (IaC) 談義 2022
Amazon Web Services Japan
 
PDF
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
Amazon Web Services Japan
 
PDF
20190828 AWS Black Belt Online Seminar Amazon Aurora with PostgreSQL Compatib...
Amazon Web Services Japan
 
PDF
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
Amazon Web Services Japan
 
PDF
AWS Black Belt Online Seminar 2017 Amazon Kinesis
Amazon Web Services Japan
 
PDF
The Twelve-Factor Appで考えるAWSのサービス開発
Amazon Web Services Japan
 
PDF
20201028 AWS Black Belt Online Seminar Amazon CloudFront deep dive
Amazon Web Services Japan
 
PDF
AWS Black Belt Online Seminar AWS Direct Connect
Amazon Web Services Japan
 
PDF
20200422 AWS Black Belt Online Seminar Amazon Elastic Container Service (Amaz...
Amazon Web Services Japan
 
PDF
20190521 AWS Black Belt Online Seminar Amazon Simple Email Service (Amazon SES)
Amazon Web Services Japan
 
PDF
AWS Black Belt Online Seminar 2016 AWS CloudFormation
Amazon Web Services Japan
 
20190806 AWS Black Belt Online Seminar AWS Glue
Amazon Web Services Japan
 
20191016 AWS Black Belt Online Seminar Amazon Route 53 Resolver
Amazon Web Services Japan
 
モノリスからマイクロサービスへの移行 ~ストラングラーパターンの検証~(Spring Fest 2020講演資料)
NTT DATA Technology & Innovation
 
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
Amazon Web Services Japan
 
20190604 AWS Black Belt Online Seminar Amazon Simple Notification Service (SNS)
Amazon Web Services Japan
 
20190129 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
Amazon Web Services Japan
 
マルチテナント化で知っておきたいデータベースのこと
Amazon Web Services Japan
 
ログ管理のベストプラクティス
Akihiro Kuwano
 
20190911 AWS Black Belt Online Seminar AWS Batch
Amazon Web Services Japan
 
Infrastructure as Code (IaC) 談義 2022
Amazon Web Services Japan
 
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
Amazon Web Services Japan
 
20190828 AWS Black Belt Online Seminar Amazon Aurora with PostgreSQL Compatib...
Amazon Web Services Japan
 
ゲームアーキテクチャパターン (Aurora Serverless / DynamoDB)
Amazon Web Services Japan
 
AWS Black Belt Online Seminar 2017 Amazon Kinesis
Amazon Web Services Japan
 
The Twelve-Factor Appで考えるAWSのサービス開発
Amazon Web Services Japan
 
20201028 AWS Black Belt Online Seminar Amazon CloudFront deep dive
Amazon Web Services Japan
 
AWS Black Belt Online Seminar AWS Direct Connect
Amazon Web Services Japan
 
20200422 AWS Black Belt Online Seminar Amazon Elastic Container Service (Amaz...
Amazon Web Services Japan
 
20190521 AWS Black Belt Online Seminar Amazon Simple Email Service (Amazon SES)
Amazon Web Services Japan
 
AWS Black Belt Online Seminar 2016 AWS CloudFormation
Amazon Web Services Japan
 
Ad

Similar to 20210127 今日から始めるイベントドリブンアーキテクチャ AWS Expert Online #13 (10)

PDF
20200721 AWS Black Belt Online Seminar AWS App Mesh
Amazon Web Services Japan
 
POTX
Serverless: State of The Union I AWS Dev Day 2018
AWS Germany
 
PPTX
awslambda-240508203904-07xsds253491.pptx
FarooqKhurshid1
 
PDF
Builders' Day- Mastering Kubernetes on AWS
Amazon Web Services LATAM
 
PDF
AWS Server Migration Service - A Quick Primer
Ali Asgar Juzer
 
PDF
Introduction to Serverless computing and AWS Lambda - Floor28
Boaz Ziniman
 
PDF
Serverless Computing
Rushi Namani
 
PDF
All the Ops you need to know to Dev Serverless
Chris Munns
 
PPTX
20210608 - Desarrollo de aplicaciones en la nube
Marcia Villalba
 
PPTX
Design, Build, and Modernize Your Web Applications with AWS
Donnie Prakoso
 
20200721 AWS Black Belt Online Seminar AWS App Mesh
Amazon Web Services Japan
 
Serverless: State of The Union I AWS Dev Day 2018
AWS Germany
 
awslambda-240508203904-07xsds253491.pptx
FarooqKhurshid1
 
Builders' Day- Mastering Kubernetes on AWS
Amazon Web Services LATAM
 
AWS Server Migration Service - A Quick Primer
Ali Asgar Juzer
 
Introduction to Serverless computing and AWS Lambda - Floor28
Boaz Ziniman
 
Serverless Computing
Rushi Namani
 
All the Ops you need to know to Dev Serverless
Chris Munns
 
20210608 - Desarrollo de aplicaciones en la nube
Marcia Villalba
 
Design, Build, and Modernize Your Web Applications with AWS
Donnie Prakoso
 
Ad

More from Amazon Web Services Japan (20)

PDF
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
Amazon Web Services Japan
 
PDF
202205 AWS Black Belt Online Seminar Amazon FSx for OpenZFS
Amazon Web Services Japan
 
PDF
202204 AWS Black Belt Online Seminar AWS IoT Device Defender
Amazon Web Services Japan
 
PDF
202204 AWS Black Belt Online Seminar Amazon Connect を活用したオンコール対応の実現
Amazon Web Services Japan
 
PDF
202204 AWS Black Belt Online Seminar Amazon Connect Salesforce連携(第1回 CTI Adap...
Amazon Web Services Japan
 
PDF
Amazon Game Tech Night #25 ゲーム業界向け機械学習最新状況アップデート
Amazon Web Services Japan
 
PPTX
20220409 AWS BLEA 開発にあたって検討したこと
Amazon Web Services Japan
 
PDF
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
Amazon Web Services Japan
 
PDF
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
Amazon Web Services Japan
 
PDF
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
Amazon Web Services Japan
 
PDF
Amazon QuickSight の組み込み方法をちょっぴりDD
Amazon Web Services Japan
 
PDF
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
Amazon Web Services Japan
 
PDF
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
Amazon Web Services Japan
 
PDF
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
Amazon Web Services Japan
 
PDF
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
Amazon Web Services Japan
 
PDF
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
Amazon Web Services Japan
 
PPTX
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
Amazon Web Services Japan
 
PDF
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
Amazon Web Services Japan
 
PDF
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
Amazon Web Services Japan
 
PDF
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
Amazon Web Services Japan
 
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
Amazon Web Services Japan
 
202205 AWS Black Belt Online Seminar Amazon FSx for OpenZFS
Amazon Web Services Japan
 
202204 AWS Black Belt Online Seminar AWS IoT Device Defender
Amazon Web Services Japan
 
202204 AWS Black Belt Online Seminar Amazon Connect を活用したオンコール対応の実現
Amazon Web Services Japan
 
202204 AWS Black Belt Online Seminar Amazon Connect Salesforce連携(第1回 CTI Adap...
Amazon Web Services Japan
 
Amazon Game Tech Night #25 ゲーム業界向け機械学習最新状況アップデート
Amazon Web Services Japan
 
20220409 AWS BLEA 開発にあたって検討したこと
Amazon Web Services Japan
 
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
Amazon Web Services Japan
 
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
Amazon Web Services Japan
 
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
Amazon Web Services Japan
 
Amazon QuickSight の組み込み方法をちょっぴりDD
Amazon Web Services Japan
 
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
Amazon Web Services Japan
 
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
Amazon Web Services Japan
 
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
Amazon Web Services Japan
 
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
Amazon Web Services Japan
 
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
Amazon Web Services Japan
 
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
Amazon Web Services Japan
 
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
Amazon Web Services Japan
 
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
Amazon Web Services Japan
 
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
Amazon Web Services Japan
 

Recently uploaded (20)

PPTX
B2B_Ecommerce_Internship_Simranpreet.pptx
LipakshiJindal
 
PPT
Transformaciones de las funciones elementales.ppt
rirosel211
 
PPTX
LESSON-2-Roles-of-ICT-in-Teaching-for-learning_123922 (1).pptx
renavieramopiquero
 
PPTX
Microsoft PowerPoint Student PPT slides.pptx
Garleys Putin
 
PDF
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
PDF
Project English Paja Jara Alejandro.jpdf
AlejandroAlonsoPajaJ
 
PPTX
AI ad its imp i military life read it ag
ShwetaBharti31
 
PDF
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
PDF
Latest Scam Shocking the USA in 2025.pdf
onlinescamreport4
 
PPTX
原版北不列颠哥伦比亚大学毕业证文凭UNBC成绩单2025年新版在线制作学位证书
e7nw4o4
 
PPTX
Google SGE SEO: 5 Critical Changes That Could Wreck Your Rankings in 2025
Reversed Out Creative
 
PPTX
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
APNIC
 
PDF
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
PDF
PDF document: World Game (s) Great Redesign.pdf
Steven McGee
 
PPT
1965 INDO PAK WAR which Pak will never forget.ppt
sanjaychief112
 
PPTX
Artificial-Intelligence-in-Daily-Life (2).pptx
nidhigoswami335
 
PPTX
办理方法西班牙假毕业证蒙德拉贡大学成绩单MULetter文凭样本
xxxihn4u
 
PPTX
How tech helps people in the modern era.
upadhyayaryan154
 
PDF
UI/UX Developer Guide: Tools, Trends, and Tips for 2025
Penguin peak
 
B2B_Ecommerce_Internship_Simranpreet.pptx
LipakshiJindal
 
Transformaciones de las funciones elementales.ppt
rirosel211
 
LESSON-2-Roles-of-ICT-in-Teaching-for-learning_123922 (1).pptx
renavieramopiquero
 
Microsoft PowerPoint Student PPT slides.pptx
Garleys Putin
 
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
Project English Paja Jara Alejandro.jpdf
AlejandroAlonsoPajaJ
 
AI ad its imp i military life read it ag
ShwetaBharti31
 
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
Latest Scam Shocking the USA in 2025.pdf
onlinescamreport4
 
原版北不列颠哥伦比亚大学毕业证文凭UNBC成绩单2025年新版在线制作学位证书
e7nw4o4
 
Google SGE SEO: 5 Critical Changes That Could Wreck Your Rankings in 2025
Reversed Out Creative
 
The Internet of Things (IoT) refers to a vast network of interconnected devic...
chethana8182
 
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
APNIC
 
KIPER4D situs Exclusive Game dari server Star Gaming Asia
hokimamad0
 
PDF document: World Game (s) Great Redesign.pdf
Steven McGee
 
1965 INDO PAK WAR which Pak will never forget.ppt
sanjaychief112
 
Artificial-Intelligence-in-Daily-Life (2).pptx
nidhigoswami335
 
办理方法西班牙假毕业证蒙德拉贡大学成绩单MULetter文凭样本
xxxihn4u
 
How tech helps people in the modern era.
upadhyayaryan154
 
UI/UX Developer Guide: Tools, Trends, and Tips for 2025
Penguin peak
 

20210127 今日から始めるイベントドリブンアーキテクチャ AWS Expert Online #13

  • 1. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 27th Jan, 2021 Kensuke Shimokawa 今日から始める イベントドリブンアーキテクチャ @_kensh AWS Expert Online JAWS-UG
  • 2. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Who am I? Name Kensuke Shimokawa Company Amazon Web Services Japan K.K. Role Serverless Specialist Solutions Architect @_kensh
  • 3. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 本セッションは 想定される聴講者 • AWSをご利用されている事業者、デベロッパー • AWSを今後利用したビジネスを考えている方 • イベントドリブンアーキテクチャ構築に興味がある方 ゴール • システムでのイベントドリブンアーキテクチャの使い所を理解していただく
  • 4. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イノベーションループ Listen Idea Experiment イノベーション ループ 傾聴 アイデア 実験
  • 5. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. "デリバリー速度"の獲得。 マイクロサービスの最大のメリットはビジネス変化に対応する "デリバリー速度"の獲得。 でもAPIで作ったサービスは頻繁な変更に対応するのは難しいですよね。 なぜならAPIにはインターフェース契約があるから。 そこで、アイデアとして登場したのが ”疎結合” にマイクロサービス を組み立て る、イベントドリブンアーキテクチャ。
  • 6. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Table of contents
  • 7. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 8. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アーキテクチャのゴールは "デリバリー速度"の獲得
  • 9. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. モノリスからマイクロサービス へ Monolith 全てを担当 Microservice 一つの責務の組み合わせ
  • 10. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2001年のAmazonでは、、、 monolithic application + teams 2001 学び: アジリティのために分散が必要 2002 microservices + 2 pizza teams
  • 11. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. アーキテクチャの結合度 小さなピースに分けて ゆるく結合させたい
  • 12. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 小さなピースをAPIで結合してみる API API
  • 13. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 契約による結合 API API インターフェース契約 APIにはインターフェースを公開し 利用者に宣言する必要がある 利用者は公開者の宣言にしたがって 送信する義務を負う
  • 14. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 互いに依存する API API (API利用者) 契約を守らないと呼び出せない (API提供者) 契約を破棄できない 不自然な維持、冗長な拡張
  • 15. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 仕様と実装の乖離が許されないAPI = 契約 • 契約を記述する手段の進化 • 契約の配布やスキーマレジストリ 管理のマネージド化 • ただし、契約は公開されるが、強制できる ものではない。 • そして、APIエコノミーへ • クローズドなAPIからオープンなAPIへ
  • 16. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 多様化、複雑化、膨大化する依存関係 API 互いに依存する 互いに依存する
  • 17. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. “デリバリー速度”の獲得? 達成できたか?
  • 18. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 同期的なAPIの課題 • 他サービスの障害に影響を受ける • サービスのIPが変わった場合の発見が難しい • API自体の数が増加し、クライアントへの統一した体験が提供しにくい • HTTPリソースやメソッドごとに要件が複雑化
  • 19. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. APIにおける様々な改善 • サービスメッシュ • API ゲートウェイ • サーキットブレーカー • 集約ログ • ポリグロット • GraphQL • サービスディスカバリ (注意) • 今回のセッションではイベントの理解の ために、あえてAPIと比較をしています が、APIとイベントは排他の関係ではな く、通常は協調して利用します • APIの管理方法も日々進化していますの で、APIの課題がそのまま当てはまるわ けではありません ※本日のセッションではAPIの管理方法の進化については割愛
  • 20. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 21. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. event [i-’vent] noun システムの状態が変化 したことを示す信号
  • 22. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントとは • イベントは状態の変化に関する情報をサービス間で共有するためのメカニズム • Immutable – イベントは過去に遡っての修正はできない • イベントには意味的な意図があり、過去形の動詞として表現可能, • e.g. “customer_created” • コンテキスト共通のプロパティによって、システムの相関を取っている • e.g. “customer_id”
  • 23. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Eventは時系列に事実を 伝える手段 Time What 2021 01 21 08 07 06 CustomerCreated 2021 01 21 08 07 09 OrderCreated 2021 01 21 08 07 13 PaymentSuccessful 2021 01 21 08 07 17 CustomerUpdated . . . . . . イベントはWhatを伝える時系列データ
  • 24. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントは観測するものであり、命令ではない 命令としての command 観測による event
  • 25. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. サービスとイベントルーティング機能を切り離す プロデューサ、コンシューマ の抽象化 イベントを選択して フィルタリング可能に プロデューサ コンシューマ ルーティング 送信イベント 受信イベント フィルタリング
  • 26. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 応答性とサービス間依存度の違い API Event
  • 27. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 契約時 • API設計時にサービス間の契約を締結 • 変化のためにはサービス実装の変更 API API 同期APIと非同期イベント配信の規約設定タイミング イベント配信時 • 非同期実行による分散 • 障害伝搬リスクの軽減 • 変化のためには配信ルールの変更 Service A Service B Message Message Service A Service B Event API Event
  • 28. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 結合度を実例で確認 (同期API) プロデューサ コンシューマ 😀 受注 サービス 発送 サービス 会計 サービス • プロデューサとコンシューマ が密結合 • 複数サービスが障害ポイント • サービスクオリティの低いも のが全体のサービス品質を決 定 • 外部への依存度が大きく、拡 張性が乏しい
  • 29. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 結合度を実例で確認 (同期API) プロデューサ コンシューマ 受注 サービス 発送 サービス 会計 サービス • プロデューサとコンシューマ が密結合 • 複数サービスが障害ポイント • サービスクオリティの低いも のが全体のサービス品質を決 定 • 外部への依存度が大きく、拡 張性が乏しい 😩 ダウンストリームの 障害に影響を受ける
  • 30. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 結合度を実例で確認 (同期API) プロデューサ コンシューマ 受注 サービス 発送 サービス 会計 サービス 在庫 サービス • プロデューサとコンシューマ が密結合 • 複数サービスが障害ポイント • サービスクオリティの低いも のが全体のサービス品質を決 定 • 外部への依存度が大きく、拡 張性が乏しい 😀 新サービス追加 コードの修正が必要
  • 31. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 結合度を実例で確認 (非同期Event) プロデューサ コンシューマ 😀 受注 サービス 発送 サービス 会計 サービス • プロデューサとコンシューマ が疎結合 • 各サービスは独立 • 品質、可用性管理を独自に実 施可能 • 外部への依存度が低いため、 拡張性が高い Event
  • 32. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 結合度を実例で確認 (非同期Event) プロデューサ コンシューマ 😀 受注 サービス 発送 サービス 会計 サービス • プロデューサとコンシューマ が疎結合 • 各サービスは独立 • 品質、可用性管理を独自に実 施可能 • 外部への依存度が低いため、 拡張性が高い Event ダウンストリームの 障害からの分離
  • 33. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 結合度を実例で確認 (非同期Event) プロデューサ コンシューマ 😀 受注 サービス 発送 サービス 会計 サービス • プロデューサとコンシューマ が疎結合 • 各サービスは独立 • 品質、可用性管理を独自に実 施可能 • 外部への依存度が低いため、 拡張性が高い Event 在庫 サービス コードの修正不要 新サービス追加時に Subscribeするだけ
  • 34. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 35. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンアーキテクチャを何で実装するか プロデューサ コンシューマ 😀 受注 サービス 発送 サービス 会計 サービス • 実装の考慮点 • 可用性についての検討 • スケーラビリティにつ いての検討 • サーバーの運用管理 • コスト見積もり Event 在庫 サービス この部分の イベント管理をどの ように実装するか
  • 36. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. サーバーレス とは? サーバーがない? サーバーの存在を意識しない • ユーザーコントロール可能なサーバーを前提としない • AWS のフルマネージドな管理
  • 37. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. サーバーレスを選択するビジネス価値 インフラのプロビジョニング不要 サーバー管理不要 自動でスケール 価値に対する支払い 高可用かつ安全
  • 38. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. サーバーレスの効能 + 利用費の 適正化 作業量の 削減 + 時間の 短縮
  • 39. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントの管理はサーバーレス サービスで プロデューサ コンシューマ 😀 受注 サービス 発送 サービス 会計 サービス • インフラのプロビジョニング 不要、サーバー管理不要 • 自動でスケール • 価値に対する支払い • 高可用かつ安全 Event 在庫 サービス サーバーレス
  • 40. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 41. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンのパーツ 非同期イベント 応答性を高め、相互依存性 を低減 イベントルーター プロデューサとコンシューマを 互いから抽象化 イベントストア ビジネスロジックのプロセスが 稼働可能になるまでストア可能
  • 42. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWSのイベント、メッセージングサービス イベントルーター イベントストア キュー ストリーム トピック イベントバス サーバーレス マネージドOSS Amazon SQS Amazon MQ Amazon SNS Amazon MQ Amazon Kinesis Amazon MSK Amazon EventBridge
  • 43. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SNS Topic Data Amazon Simple Notification Service (SNS) • Publish / subscribe モデルメッセージング • 高スループット, 高信頼性メッセージング • 複数のパブリッシャーに配信 • ファンアウト • メッセージフィルタリンを利用して配信タ ーゲットを指定可能 • 非同期Lambda実行
  • 44. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Message SQS Queue SQS はLambda サービス側で関 数から成功応答 が返った場合に メッセージ削除 Amazon Simple Queue Service (SQS) • 大量メッセージ • メッセージのバッチ処理 • At least once 配信 (標準キュー) • 複数回受信を防ぐ可視性タイムアウト • 同期Lambda実行 • Lambdaはロングポーリング
  • 45. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Kinesis Data Streams • リアルタイムメッセージング • At least once 配信(Lambda統合時) • Lambda関数はバッチ取得可能 • 1メッセージ内に論理バッチも可能 • 同期Lambda実行 Kinesis Stream Lambdaサービス は、メッセージ が期限切れで削 除されるまで、 ポーリング Data
  • 46. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 各モデルでのイベントハンドリング イベントストアを 利用しない (FIFOで順序) 高耐久性の メッセージ処理 (FIFOで順序) Amazon SNS Amazon SQS Amazon Kinesis 高耐久性の メッセージ処理 (順序の保証)
  • 47. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon EventBridge AWS Cloud AWS Cloud AWS Cloud Amazon EventBridge 異なるチーム、組織の間でも、Push型での情報連携(イベント通知)を 可能にするイベントバス
  • 48. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Lambdaの非同期実行 Amazon S3 Amazon SNS Amazon SES Amazon EventBridge Amazon CloudWatch Logs AWS Config Amazon CloudFormation AWS CodeCommit AWS Lambda Amazon SNS Amazon SQS Amazon EventBridge Lambda Function onSuccess onFailure
  • 49. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブン・ユースケース
  • 50. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ファイルアップロード処理 1. Amazon S3 バケットにファイ ルをアップロード 2. Lambda関数の非同期実行 • イベントペイロード: » Bucket name » Object key 1 2 Lambda + Amazon S3 Amazon S3 Upload Event file Lambda Function
  • 51. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ファイルアップロード処理 3. Amazon Rekognitionを使用し た画像解析 4. 画像解析の結果を保存 1 2 イメージ解析、データ永続化 Amazon Rekognition Amazon DynamoDB 3 4 file Upload Event Amazon S3 Lambda Function
  • 52. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ストリームデータの取り込みと保存 1. LambdaがKinesis Data Streamからメッセージポーリング 2. 関数が同期的にLambdaサービスから呼び出される 3. 関数によるメッセージの保存 1 2 取得、処理、保存 Amazon Redshift Amazon Elasticsearch Service 3 Kinesis Data Stream Lambda Lambda Function
  • 53. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ダウンストリームの保護 1. API Gatewayに到達したメッセージをSQSにバッファリング 2. 関数が同期的にLambdaサービスから呼び出される • 同時実行数設定によるスループット調整 3. オンプレミスデータベースに対する、Lambda関数によるメッセージ の保存 1 2 スループットの調整 3 Lambda Lambda Function Amazon SQS Amazon API Gateway オンプレミス データベース 物理サーバー 低スループット 高スループット 202 accepted 低可用性、ローパフォーマンス
  • 54. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. SaaSとのイベント連携 1. API Gatewayでの Webhookや、定期起動Lambdaによるポーリ ングではなく、EventBridgeのイベントバス経由でイベント連携 2. イベントの種類に応じて各種マイクロサービスを実行 モニタリングアラームの受信 AWS Cloud Amazon EventBridge アラーム
  • 55. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンアーキテクチャ 導入への流れ Journey to event-driven architectures
  • 56. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンアーキテクチャ導入への流れ STEP 1 ドメインに対する考慮
  • 57. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. システムではなく、ビジネスのイベントを考えてみる
  • 58. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントをビジネスドメインに紐付ける 販売 配送センター サポート
  • 59. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ビジネスプロセスを一旦オーケストレーションで考えてみる 販売 オーケストレーター 決済管理 1 4 6 注文イベント 2 在庫管理 3 5 7
  • 60. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ドメイン境界を越える処理をSubscriptionに置き換える 販売 発送センター 注文入ったよ 注文が入ったら教えてね Subscription Notification 1 2 非同期Event
  • 61. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンのモデリング EventStorming
  • 62. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンアーキテクチャ導入への流れ STEP 2 イベントルータの選定
  • 63. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ルーターが必要になるかどうか?
  • 64. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. まだ、必要じゃない?
  • 65. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 本当に、まだ必要ない?
  • 66. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 設計時にルーターを入れて非同期にできるかはまず確認!
  • 67. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンアーキテクチャ導入への流れ STEP 3 イベントストアの選定
  • 68. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントストアで復元力とスケーラビリティを向上 ビジネスロジックサービスが処理可能に なるまでメッセージをバッファリング Event store
  • 69. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンアーキテクチャ導入への流れ STEP 4 イベントスキーマの考慮
  • 70. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントはそのままの生の情報ではない 注文123は、顧客456に よって午前10時47分に 作成されました。 注文123は、顧客456によっ て午前10時47分に作成されま した。現在のステータスは オープンで、合計は$ 237.51 で、商品は…
  • 71. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 必要となる属性を考える 123 456 注文123はどの ユーザの注文?
  • 72. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon EventBridgeイベントスキーマの例 { "version": "0", "id": "adeacade-c34c-ce58-c4a0-74f106398c4e", "account": "123456789012", "region": "us-east-1", "time": "2019-12-02T21:46:19Z", "source": "order-service", "detail-type": "New Order", "resources": [], "detail": { "orderId": "cfb2ae566f9b", "customerId": "C12345", ... } }
  • 73. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { "version": "0", "id": "adeacade-c34c-ce58-c4a0-74f106398c4e", "account": "123456789012", "region": "us-east-1", "time": "2019-12-02T21:46:19Z", "source": "order-service", "detail-type": "New Order", "resources": [], "detail": { "orderId": "cfb2ae566f9b", "customerId": "C12345", ... } } Amazon EventBridgeイベントスキーマの例
  • 74. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { "version": "0", "id": "adeacade-c34c-ce58-c4a0-74f106398c4e", "account": "123456789012", "region": "us-east-1", "time": "2019-12-02T21:46:19Z", "source": "order-service", "detail-type": "New Order", "resources": [], "detail": { "orderId": "cfb2ae566f9b", "customerId": "C12345", ... } } Amazon EventBridgeイベントスキーマの例
  • 75. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. { "version": "0", "id": "adeacade-c34c-ce58-c4a0-74f106398c4e", "account": "123456789012", "region": "us-east-1", "time": "2019-12-02T21:46:19Z", "source": "order-service", "detail-type": "New Order", "resources": [], "detail": { "orderId": "cfb2ae566f9b", "customerId": "C12345", ... } } Amazon EventBridgeイベントスキーマの例
  • 76. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon EventBridgeイベントスキーマの例 { "version": "0", "id": "adeacade-c34c-ce58-c4a0-74f106398c4e", "account": "123456789012", "region": "us-east-1", "time": "2019-12-02T21:46:19Z", "source": "order-service", "detail-type": "New Order", "resources": [], "detail": { "orderId": "cfb2ae566f9b", "customerId": "C12345", ... } }
  • 77. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブン・デザインパターン
  • 78. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブン・デザインパターン • コレオグラフィ • 全体の作業を制御する指揮者は存在せず、個々のサービスに予め与 えられた動作条件に従ってサービスを実行 • コマンドクエリ責務分離 • データ ストアの読み取り操作と更新操作を分離 • イベント ソーシングパターン • データに対して実行された一連のすべてのアクションを記録
  • 79. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コレオグラフィ - Choreography Streams, Topics, Queues
  • 80. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. マイクロサービスの依存関係グラフ https://www.thoughtworks.com/insights/blog/scaling-microservices-event-stream Event APIで結合 コレオグラフィー
  • 81. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コレオグラフィーパターンとは • 必要なすべての情報を含んだ最初のイベントを 1 つのメッセージに保存し て、最初のトランザクションを完了 • 他のサービスがそのメッセージを非同期的に取得し、それぞれのタスクを 完了させる • サービスが疎結合になり、直接互いに影響を与えない • メッセージの保存と取得が非同期の関係になり、スケーラビリティと信頼 性が向上
  • 82. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コレオグラフィーパターン ユーザー リクエストサービス リクエストキュー サービスA サービスB サービスC
  • 83. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 実装例1: SNS、 SQS、 Lambdaの利用 ユーザー リクエストサービス Amazon SNS Amazon SQS Amazon SQS Amazon SQS AWS Lambda AWS Lambda AWS Lambda ファンアウト
  • 84. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 実装例2: Amazon EventBridgeの利用 配送 ポイント プレミアム会員 カート 支払 支払い方法 認証 注文 1分毎に実行 Events 会員 ステータス 支払認証 カートに 入れる 注文完了 Amazon EventBridge リクエストサービス イベントバス
  • 85. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コマンドクエリ責務分離 CQRSパターン
  • 86. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コマンドクエリ責務分離パターンとは • コマンドクエリ責務分離(Command-Query Responsibility Segregation: CQRS)パターンはデータを更新するコマンドと参照するクエリを分離するこ とで、ユースケースに応じて個別にスケールすることを可能とするパターン • データソースを分離することで異なるデータ構造を取ることも可能となり、ク エリ側はクエリで返すデータ転送オブジェクト(Data Transfer Object : DTO) に合わせた形のスキーマとすることでオブジェクト関係マッピング(Object Relational Mapping : ORM)のオーバーヘッドを軽減することも可能になる • コマンド側とクエリ側が結果整合性を許容する必要がある
  • 87. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コマンドクエリ責務共有パターン ユーザー サービス ドメインモデル ドメインモデル ORM ORM データ転送 オブジェクト クエリ 更新
  • 88. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コマンドクエリ責務分離(CQRS)パターン ユーザー コマンドサービス ドメインモデル データ転送 オブジェクト クエリ 更新 クエリサービス データ転送 オブジェクト 非同期 結果整合
  • 89. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 実装例1: Kinesis Data StreamsとLambdaを利用 フロントサービス Amazon Kinesis Data Streams AWS Lambda AWS Lambda Amazon Aurora 正規化テーブル ユーザー Amazon DynamoDB 非正規化テーブル
  • 90. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 実装例2: DynamoDB StreamsとLambdaを利用 ユーザー Amazon DynamoDB Streams 非正規化テーブル AWS Lambda Amazon Aurora 正規化テーブル フロントサービス
  • 91. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベント ソーシング Event Sourcing
  • 92. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントソーシングパターンとは • データストアを直接更新する代わりに、注文の発注、クレジット照会、出荷中 の注文など、ビジネスロジックに重要なイベントを耐久性のあるイベントログ に追加 • イベントレコードは個別に保存されるため、すべての更新はアトミック (分割 不可かつ削減不可) • 保存されたイベントを再度処理するだけで、アプリケーションのいかなる時点 の状態でも再構築 可能
  • 93. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベント ソーシングパターン ユーザー プロセス イベントログ イベント プロセス プロセス 状態
  • 94. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Kinesis Data Streams (or SQS FIFO)とLambdaによる実装例 ユーザー Amazon Kinesis Data Streams AWS Lambda イベント メッセージ 状態 Amazon SQS FIFO or
  • 95. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. イベントドリブンアーキテクチャ 選択における観点 Design Considerations
  • 96. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. At-least once 配信 イベントは、ターゲットに複数回配信 されることも。処理されたイベントの 状態を追跡することによって重複イベ ントを検出するロジックを含める (冪等性) 配信セマンティクス Exactly-once 配信* AWSサービスに重複排除に使用す る識別子を渡すことで重複排除 * Lambdaでリトライ設定している場合は、At-least once • Amazon EventBridge • Amazon SNS 標準トピック • Amazon SQS 標準 キュー • Amazon Kinesis • Amazon SNS FIFO トピック • Amazon SQS FIFO キュー
  • 97. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 順序保証なし イベント/メッセージが順序保証なしで 配信 順序セマンティクス* 順序保証 イベントは、パーティション、 メッセージグループなどの中で順 番に配信 (グローバルな順序保証はありません) • Amazon EventBridge • Amazon SNS 標準トピック • Amazon SQS 標準 キュー • Amazon Kinesis • Amazon SNS FIFO トピック • Amazon SQS FIFO キュー * 順不同のイベント処理ロジックが受入可能かは、ビジネス要件次第となります。順不動なイベントを処理する ようにアプリケーションを設計できない場合は、代わりにオーケストレーションも検討
  • 98. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 99. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. まとめ マイクロサービスの最大のメリットはビジネス変化に対応する "デリバリー速度"の獲得 • イベントドリブンアーキテクチャで疎結合にすることでデリバリー速度を高 める。 • AWSのサーバーレス サービスを利用することで、イベントドリブンアーキテ クチャを素早く導入できる。 • アーキテクチャパターンや導入の道筋を知ることで、システム設計に活かす ことができる。
  • 100. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Thank you! @_kensh
  • 101. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Appendix
  • 102. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. EventBridgeサービスクオータ(抜粋) • PutEvents: Depends on region (2400-400), regional • Invocations: Depends on region (4500-750), regional • Buses per account/region: 100, hard limit • Rules per bus: 300 • Targets per rule: 5, hard limit • Event pattern size: 2048 characters, hard limit https://docs.aws.amazon.com/eventbridge/latest/userguide/cloudwatch-limits-eventbridge.html