Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kafkaを利用したアプリケーションでのオフセットの制御について/Kafka Offsets
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Tomoyoshi Ogura
May 15, 2017
Programming
1
1.3k
Kafkaを利用したアプリケーションでのオフセットの制御について/Kafka Offsets
2017-05-14に行われた「Scala将軍達の後の祭り2017」で発表した時の資料です。
Tomoyoshi Ogura
May 15, 2017
Tweet
Share
More Decks by Tomoyoshi Ogura
See All by Tomoyoshi Ogura
Apache Kafkaとストリーム処理/Reactive Streams
tarugo07
4
3.4k
DDDで利用するアーキテクチャと プレゼンテーション層について/DDD Architecture
tarugo07
0
4k
Other Decks in Programming
See All in Programming
CSC307 Lecture 03
javiergs
PRO
1
490
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
190
Package Management Learnings from Homebrew
mikemcquaid
0
220
2026年 エンジニアリング自己学習法
yumechi
0
130
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
230
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
Data-Centric Kaggle
isax1015
2
770
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
3.9k
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
AgentCoreとHuman in the Loop
har1101
5
230
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
410
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
120
A Modern Web Designer's Workflow
chriscoyier
698
190k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
120
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
96
Writing Fast Ruby
sferik
630
62k
Navigating Weather and Climate Data
rabernat
0
100
How to train your dragon (web standard)
notwaldorf
97
6.5k
Designing Powerful Visuals for Engaging Learning
tmiket
0
230
Transcript
Kafkaを利用したアプリケーションで のオフセットの制御について Tomoyoshi Ogura 2017/05/14 Scala将軍達の後の祭り2017
自己紹介 Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • 小椋友芳
• ChatWork株式会社コアテクノロジー開発室所属 • Scala歴4年 • twitter: @tomoyoshi_ogura • github: tarugo07
アジェンダ Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • Kafkaのオフセットの重要性
• オフセットとコミットの基本 • アプリの処理に合わせたオフセットの制御方法
オフセットとアプリケーション Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • オフセットはアプリケーションに大きな影響を与える
◦ 同じメッセージを重複して処理 ◦ メッセージをロストする危険性 ◦ パフォーマンスの劣化
オフセットとコミット Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • オフセットとはパーティション内でメッセージを一意に識別する番号
• コンシューマはパーティションのメッセージをどこまで読み取ったかオフセット で追跡する • オフセットは特別な__consumer_offsetsトピックで管理される • コミットはパーティションの現在のオフセットを更新すること
Consumerの重要なプロパティ Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • auto.offset.reset
◦ オフセットがない場合の動作 ◦ デフォルトはlatest • enable.auto.commit ◦ コンシューマが自動的にオフセットをコミット • max.poll.records ◦ 一回のpoll()で取得するメッセージ件数
コミットの方法 Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • オフセットのコミット方法は複数ある
◦ 自動コミット ◦ commitSync() ◦ commitAsync()
自動コミット Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • コンシューマが自動でオフセットをコミットする
• enable.auto.commit = true • コミット間隔のデフォルトは5秒 ◦ auto.commit.interval.msで制御 • poll()で取得したメッセージの最大のオフセットをコミット
commitSync() Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • オフセットのコミットを明示的に制御したい場合に使用
• auto.commit.offset = false • メッセージの欠落を排除しリバランスでの重複メッセージの件数を減らす • commitSync()はpoll()で取得した最新のオフセットをコミット ◦ 明示的にオフセット値を指定することも可能 • コミットに失敗すると例外
commitAsync() Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • commitSync()の非同期版
• auto.commit.offset = false • poll()で取得した最新のオフセットをコミット • ブローカーのレスポンスを待たずにコミットのリクエストを投げて終了 • コミットのリトライをしない
アプリでAt Most Onceの処理をしたい Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved.
• At Most Once ◦ 最高1回処理するが保証がない • 自動コミットを利用する ◦ enable.auto.commit = true ◦ auto.commit.interval.msは短く設定 • consumer.commitSync()を実行しない • poll()でオフセットがコミットされる
アプリでAt Least Onceの処理をしたい Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved.
• At Least Once ◦ 最低一回処理するが重複する可能性もある • commitSync()をアプリの処理が終わった後に実行 ◦ auto.commit.offset = false
アプリでExactly Onceの処理をしたい Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. •
Exactly Once ◦ 正確に一回処理する • オフセットの管理とアプリケーションの処理を一つのアトミックなトランザク ションで処理する ◦ オフセットをRDBなどの外部ストレージに保存すると簡単 • ConsumerRebalanceListerとseek()を利用 ◦ auto.commit.offset = false
Exactly Onceの実装イメージ Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved.
Exactly Onceの実装イメージ Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved.
まとめ Scala将軍達の後の祭り2017 2017/05/14 © ChatWork All rights reserved. • Kakfaを使う場合はオフセットの管理に気をつけよう
• アプリケーションの性質に合わせて正しいオフセットの制御を ◦ At Most Once ◦ At Least Once ◦ Exactly Once