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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
160
AgentCoreとHuman in the Loop
har1101
5
230
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
CSC307 Lecture 02
javiergs
PRO
1
770
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.5k
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
260
組織で育むオブザーバビリティ
ryota_hnk
0
170
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
430
SourceGeneratorのススメ
htkym
0
190
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
650
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
190
Featured
See All Featured
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
0
3.4k
Everyday Curiosity
cassininazir
0
130
AI Search: Where Are We & What Can We Do About It?
aleyda
0
6.9k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
910
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
53
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
250
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
430
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
180
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
170
From π to Pie charts
rasagy
0
120
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