Share
Embed
Apache Kafka and the World of Streams
イベント駆動というアプローチに対し、ストリームという文脈を持たせた上で処理をする概念とApache Kafkaのアプローチについてご紹介します。今回は特にExactly Once Semantics (全てのイベントを重複なく1度だけ処理する) というストリーム処理のゴールに対して、Kafkaがトランザクションの概念をどう導入したかについて 踏み込んでご説明します。
hashi
May 12, 2023
Transcript
25 slides
-
Event Driven Meetup #1 Apache Kafka and the World of
Streams Shinichi Hashitani, Manager, Solutions Engineering, Korea/Japan May 2023. #eventdriven -
@ShinHashitani | developer.confluent.io #1 Durable Event Driven Architecture Kafkaによる高耐性イベント駆動 一般的なメッセージブローカーと異な
り、Kafkaを利用したイベント駆動では 本格的な運用では大きなメリットがあ る。 • 極めて高いスケーラビリティ • バックプレッシャーが不要 • イベントの長期保全 • Order Guarantee • Exactly Once Semantics • Fan-out • ストレージ/OLAPドメインとの接続 Service 2 Service 5 Service 6 Service 1 Service 4 Service 3 -
@ShinHashitani | developer.confluent.io #2 Flafka (Flume + Kafka) Hadoop Pipeline
データレイクへの大規模マイクロ バッチ パイプライン • 保全対象の拡大に伴う大規模デー タを移動する必要性。 • Flumeを使ったログのマイクロ バッチ抽出&Kafkaによるリアルタ イム連携。 • Kafkaの特性 - 拡張性、柔軟性、 効率的なデータ共有。 • Kafka Connect - Kafkaネイティ ブなデータ差分抽出/分散処理。 Flume Cluster Hadoop HDFS HBase Kafka Connect -
@ShinHashitani | developer.confluent.io #3 Streaming ETL Databases RDBMS/NoSQL Files CSV/JSON/XML…
Application Events Webhook SaaS Applications REST APIs Data Warehouse Analytics Continuous Data Processing Stream Processing Databases OLTPとOLAPを繋ぐリアル タイムパイプライン • バッチ前提であるデータ の流れをリアルタイム化 • これまで必要であった中 間的なデータストアや 様々な処理ロジックをス トリーム処理化 • データは必要なストアに 必要な形態まで一次処理 をリアルタイムで実施し た後に連携。 -
@ShinHashitani | developer.confluent.io #4 Real Time Actions Data Warehouse Analytics
Stream Processing Databases 今起こったイベントに反応 ストリームがシンクに到達するま でにアクショナブルなリアルタイ ムイベントに変換 • 不正検知 • 数百件の捜査対象を数億件の イベントから抽出 • リアルタイムな状況アップ デート(Daily/Hourlyステー タス) Backend Service Alert Immediate Action Needed -
@ShinHashitani | developer.confluent.io Stream = A Series of Continuous Events
customer login: abc order confirmed: #001 order updated: #002 customer login: efg order canceled: #003 package received: #a01 at dist center: #b02 left dist center: #a02 delivered: #a01 customer C: 0001 order U: 0003 payment U: 0002 payment C: 0003 customer U: 0002 store-order order confirmed: #001 order updated: #002 order canceled: #003 store-customer customer login: abc customer login: efg logistic package received: #a01 left dist center: #a02 delivered: #a01 at dist center: #b02 orderdb-c customer C: 0001 customer U: 0002 orderdb-o order U: 0003 orderdb-p payment C: 0003 payment U: 0002 -
@ShinHashitani | developer.confluent.io Why Kafka? - Kafka Keeps Data Consistent
イベントはトランザクションログとして保存 イベントはログとして永続化され、同じイベン トを何度でも読み込み処理する事が可能。Pullモ デルでもある為、イベントを漏れなく順序通り 高速に連携出来る仕組みとなっている。 customer login order confirmed order updated customer logout order canceled Append-Only Immutable 1 2 3 4 5 6 8 7 10 9 11 12 1 2 3 4 5 6 8 7 Old New -
@ShinHashitani | developer.confluent.io Event, Total Order, and Data Consistency “Streams
and Tables in Apache Kafka: A Primer”, Michael Noll, Confluent Blog. チェスの一手一手とチェス盤の状態は 同じデータの異なる表現方法。 • チェス盤はある特定時点での完全な状 態 (State) を表現できる。 • チェスの一手一手を漏れなく、順序通 り適用すればチェス盤の状態を再現で きる。 -
@ShinHashitani | developer.confluent.io Kafka is a Durable Storage Broker 1
Broker 2 Broker 3 Broker 4 Topic1 partition1 Topic1 partition2 Topic1 partition3 Topic1 partition4 Topic1 partition1 Topic1 partition1 Topic1 partition2 Topic1 partition2 Topic1 partition3 Topic1 partition3 Topic1 partition4 Topic1 partition4 Concurrent Access Data Replication -
@ShinHashitani | developer.confluent.io Consumers Need to Be Idempotent 1 2
3 4 5 6 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 3 4 5 Order Guarantee is lost Duplicate events are sent 3/4/5 didn’t make it. Ack for 3/4/5 didn’t make it. The process failed and lost state. -
@ShinHashitani | developer.confluent.io Idempotent Producer 1 2 3 4 5
6 Sequence #: 1 Sequence #: 2 Sequence #: 3 enable.idempotence = true acks = all ブローカー側で常にProducerのIDと シーケンス番号をトラッキング。 想定しているシーケンス番号と異なる 番号が到達した場合には OutOfOrder SequenceException 例外を返す。 -
@ShinHashitani | developer.confluent.io Log • Continuous • Logical • Infinite
• Continuous • Physical • Finite Stream -
Challenge ヨーロッパ複数ヵ国の市場取引を支える新た なプラットフォーム - 高スループット、低レ イテンシのリアルタイム取引を多くのクライ アントに提供。 Solution Confluentをスケーラブルかつ堅固なメッ セージングレイヤーとして数十億件/日のトラ
ンザクションを低レイテンシで処理。 https://www.euronext.com/en/technology/optiq-tech-solutions-for- exchanges-and-venue-operators -
既存の構成から部分的にマイクロサービスに移行。 これまで時間のかかっていた新規カード申し込みの 審査時間を劇的に短縮。 アプリ=DBのフロントシステムから抽出した申し込 み情報をKafkaを軸とした非同期処理に変換: - CDC経由で申し込み情報を抽出。 - 同一イベントの複数Consumerからの同時 (並列)
処理。 - 非同期処理によるストリームパイプライン。 Driving innovation in financial systems using Confluent - Kafka Summit San Francisco 2019 Rakuten Card -
@ShinHashitani | developer.confluent.io Stream Processing - Transform in Transit Filter
Enrich Aggregate Validate -
@ShinHashitani | developer.confluent.io Processing a Stream - Ins and Outs
Filter Enrich Aggregate Validate Sink Sink raw validated Validate aggregated enriched Aggregate Enrich Filter filtered -
@ShinHashitani | developer.confluent.io Transaction raw aggregated Aggregate Filter filtered 1.
トピック “raw” からConsume 2. Filtering処理 3. トピック “filtered” にProduce 4. トピック “raw” のOffsetを更新 isolation.level = read_committed