SlideShare a Scribd company logo
natans@wix.com twitter @NSilnitsky linkedin/natansilnitsky github.com/natansil
Exactly Once Delivery
is a harsh mistress
Natan Silnitsky
Backend Infra Developer, Wix.com
A Scala/Java high-level SDK for Apache Kafka.
Greyhound
As it happens,
we have a distributed system at Wix.
~1400 micro-services
@NSilnitsky
As it happens,
we have a distributed system at Wix.
Edit MySite
~1400 micro-services
~1015M messages every day
@NSilnitsky
PurchaseCompleted
Classic ecommerce flow
UpdateInventory(ItemN)
updates
UpdateInventory(Item1)
UpdateInventory(Item2)
@NSilnitsky
Payments Checkout Inventory
Classic ecommerce flow - hard to achieve
PurchaseCompleted
UpdateInventory(ItemN)
updates
UpdateInventory(Item1)
UpdateInventory(Item2)
😳 But... how do we update all items exactly once? on failures/restarts too...
Payments Checkout Inventory
PurchaseCompleted
updates
UpdateInventory(Item1)
UpdateInventory(Item2)
Classic ecommerce flow - hard to achieve
Inventory:
Item1 9 → 8
Item2 5 → 4
@NSilnitsky
PurchaseCompleted
updates
UpdateInventory(Item1)
UpdateInventory(Item2)
Classic ecommerce flow - hard to achieve
Inventory:
Item1 9 → 7
Item2 5 → 3
Payments
* use DB
Achieving Exactly-Once delivery in
distributed systems is NOT easy.
Message delivery over the network
is unreliable.
@NSilnitsky
Message delivery over the network
is unreliable.
Message
Consumer
Message
Producer
Broker
@NSilnitsky
Kafka Broker
Topic-1
0 1 2 3 45
0 1 2 3 45
0 1 2 3 45
0 1 2 3 45
0 1 2 3 4
Topic-2
0 1 2 3 45
0 1 2 3 45
0 1 2 3 45
0 1 2 3 45
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
(append-only logs)
Partitions
@NSilnitsky
Kafka
Consumer
Kafka
Producer
Kafka Broker
Topic-1
0 1 2 3 45
0 1 2 3 45
0 1 2 3 45
0 1 2 3 45
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
0 1 2 3 4 5
@NSilnitsky
The options for
message delivery
Why Exactly-Once
is difficult
Kafka’s solution for
Exactly-Once
delivery
Kafka Broker
Kafka
Producer
0 1 2 3 4 5
😕 Services need to address message duplicates
at-most-onceat-least-once exactly-once
Producer retries on
every failure
Kafka Broker
0 1 2 3 4 5
😕 Services need to handle messages exactly once
consumerRecords = Consumer.poll
process(consumerRecords)
consumer.commit
at-most-onceat-least-once exactly-once
Consumer retries
on every failure
Kafka
Consumer
Kafka Broker
0 1 2 3 4 5
😕 Messages may be lost
Consumer commits
before processing
(AutoCommit - Default)
consumerRecords = Consumer.poll
Consumer.commit
process(consumerRecords)
at-most-onceat-least-once exactly-once
Kafka
Consumer
Kafka Broker
0 1 2 3 4 5
Kafka
Consumer
😕 Really really really hard to do
Messages are read and processed
exactly once by the consumer
?
at-least-once exactly-onceat-most-once
The options for
message delivery
Why Exactly-Once
is difficult
Kafka’s solution for
Exactly-Once
delivery
The “Two Generals Problem"
thought experiment
Alice Bob
Tomorrow
7 AM
The “Two Generals Problem"
thought experiment
Alice Bob
The “Two Generals Problem"
thought experiment
Alice Bob
The “Two Generals Problem"
thought experiment
Alice Bob
Tomorrow
7 AM
OK!
Tomorrow
7 AM
The “Two Generals Problem"
thought experiment
Alice Bob
?
The “Two Generals Problem"
thought experiment
Alice Bob
OK!
The “Two Generals Problem"
thought experiment
AliceService BobService
The options for
message delivery
Why Exactly-Once
is difficult
Kafka’s solution for
Exactly-Once
delivery
Kafka Broker
Processor Observer
Consumer
-Producer
Consumer
Topic A Topic B
@NSilnitsky
Kafka Broker
Processor Observer
Consumer
-Producer
Consumer
Topic A Topic B
@NSilnitsky
Kafka Broker
Kafka
Idempotent
Producer
0 1 2 3 4 5
0 1
1
Attaches offset to
message
Enable.idempotence = true
@NSilnitsky
Kafka Broker
Kafka
Idempotent
Producer
0 1 2 3 4 5
0 1
1
Attaches offset to
message
Enable.idempotence = true
duplicate!
@NSilnitsky
Kafka Broker
Topic A Topic B
Processor Observer
Consumer
-Producer
Consumer
@NSilnitsky
Kafka Broker
consumer.poll
Attaches offset to message +
marks transaction
ABCDEF
Processor Observer
AB
01
Topic A Topic B
@NSilnitsky
isolation.level =
"read_committed"
Kafka Broker
consumer.poll
producer.beginTransaction
Producer.send
Attaches offset to message +
marks transaction
ABCDEF
Processor Observer
ABC
01
Topic A Topic B
@NSilnitsky
Kafka Broker
consumer.poll
producer.beginTransaction
Producer.send
producer.sendOffsets
Attaches offset to message +
marks transaction
ABCDEF
Processor Observer
ABC
012
Topic A Topic B
@NSilnitsky
Kafka Broker
consumer.poll
producer.beginTransaction
Producer.send
producer.sendOffsets
producer.commitTransaction
Attaches offset to message +
marks transaction
ABCDEF
Processor Observer
ABC
012
Topic A Topic B
@NSilnitsky
Kafka Broker
consumer.poll
producer.beginTransaction
Producer.send
producer.sendOffsets
Attaches offset to message +
marks transaction
ABCDEF
Processor Observer
ABC
01
Topic A Topic B
@NSilnitsky
Kafka Broker
Throughput impact is between 3% to 25% worse.
Processor Observer
@NSilnitsky
Kafka Broker
Throughput impact is between 2% to 25% worse.
The bigger the batch the better the throughput and longer the latency.
Processor Observer
@NSilnitsky
Kafka Broker
Processor Observer
No end-to-end exactly-once guarantees
out of the box.
@NSilnitsky
Kafka Broker
Deduplicate using offsets from Kafka Transaction
@NSilnitsky
ABC
012
Topic B
Observer
DB Table
Partition Offset Value
0 2 C
... ... ...
In reality, this is more complex
than how I describe it.
Out of scope:
▪ Two-phase-commit with transaction coordinator
▪ Transaction log
▪ Additional “fencing” data
▪ 1 processor-producer - 1 partition (up to Kafka 2.4.x)
@NSilnitsky
Exactly Once in Kafka Streams
StreamsConfig:
processing.guarantee = "exactly_once"
consumers will be configured with:
● isolation.level = "read_committed"
producers will be configured with:
● enable.idempotence = true
@NSilnitsky
Purchase
Completed
UpdateInventory(Item1)
Exactly Once (Classic ecommerce) flow at Wix
UpdateInventory(Item2)
UpdateInventory(ItemN)
ABCDEF
1
iNB
1
I3I8
I1I2I5I5
01
updates
@NSilnitsky
Kafka Broker
Exactly Once (Classic ecommerce) flow at Wix
- Dedup
@NSilnitsky
Topic B
Observer
Inventory
Partition Offset Item Value
0 0 I1 9->8
0 1 I2 5->401
I1I2
UPDATE offset 0, Item1 -1
UPDATE offset 1 Item2 - 1
Kafka Broker
Exactly Once (Classic ecommerce) flow at Wix
- Dedup
@NSilnitsky
Topic B
Observer
Inventory
Partition Offset Item Value
0 0 I1 8
0 1 I2 401
I1I2
UPDATE offset 0, Item1 -1
UPDATE offset 1 Item2 - 1
UPDATE offset 1 Item2 - 1
Exactly-Once delivery is...
like the holy grail of message delivery over the network.
It’s a tough nut to crack.
Exactly-Once delivery is...
complex to implement, to use, and it requires fine-tuning.
Exactly-Once delivery is...
crucial for achieving atomic actions in distributed systems.
Thank You
natans@wix.com twitter @NSilnitsky linkedin/natansilnitsky github.com/natansil
Resources
EoS in Kafka talk by Jason Gustafson
Exactly-once Semantics are Possible by Neha Narkhede (Performance)
Transactions in Apache Kafka
Revisiting Exactly One Semantics by Jason Gustafson, Confluent
Proposal to improve EOS Produce scalability - Kafka 2.5
How akka works with exactly once message delivery by Hugh McKee
A Scala/Java high-level SDK for Apache Kafka.
github.com/wix/greyhound
Slides & More
slideshare.net/NatanSilnitsky
medium.com/@natansil
twitter.com/NSilnitsky
natansil.com

More Related Content

PDF
Greyhound - Powerful Pure Functional Kafka Library
PDF
Greyhound - Powerful Functional Kafka Library - Devtalks reimagined
PDF
Exactly Once Delivery with Kafka - JOTB2020 Mini Session
PDF
10 Lessons Learned from using Kafka in 1000 microservices - ScalaUA
PDF
Building Out Your Kafka Developer CDC Ecosystem
PDF
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
PDF
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
PPTX
Introducing Exactly Once Semantics To Apache Kafka
Greyhound - Powerful Pure Functional Kafka Library
Greyhound - Powerful Functional Kafka Library - Devtalks reimagined
Exactly Once Delivery with Kafka - JOTB2020 Mini Session
10 Lessons Learned from using Kafka in 1000 microservices - ScalaUA
Building Out Your Kafka Developer CDC Ecosystem
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
Streaming Design Patterns Using Alpakka Kafka Connector (Sean Glover, Lightbe...
Introducing Exactly Once Semantics To Apache Kafka

What's hot (20)

PDF
Actors or Not: Async Event Architectures
PDF
Performance Analysis and Optimizations for Kafka Streams Applications
PDF
10 Lessons Learned from using Kafka with 1000 microservices - java global summit
PDF
Apache Kafka: New Features That You Might Not Know About
PDF
SFBigAnalytics_20190724: Monitor kafka like a Pro
PPTX
A Modern C++ Kafka API | Kenneth Jia, Morgan Stanley
PDF
Making Sense of Your Event-Driven Dataflows (Jorge Esteban Quilcate Otoya, SY...
PDF
Producer Performance Tuning for Apache Kafka
PDF
Migrating to Multi Cluster Managed Kafka - Conf42 - CloudNative
PDF
Consumer offset management in Kafka
PDF
Follow the (Kafka) Streams
PPTX
Building a Replicated Logging System with Apache Kafka
PDF
Let the alpakka pull your stream
PDF
Apache Kafka, and the Rise of Stream Processing
PDF
Kafka Summit SF 2017 - MultiCluster, MultiTenant and Hierarchical Kafka Messa...
PDF
Getting Started with Confluent Schema Registry
PDF
Kafka Streams: the easiest way to start with stream processing
PDF
Kafka on Kubernetes: Does it really have to be "The Hard Way"? (Viktor Gamov,...
PDF
Kafkaesque days at linked in in 2015
PDF
Real Time Streaming Data with Kafka and TensorFlow (Yong Tang, MobileIron) Ka...
Actors or Not: Async Event Architectures
Performance Analysis and Optimizations for Kafka Streams Applications
10 Lessons Learned from using Kafka with 1000 microservices - java global summit
Apache Kafka: New Features That You Might Not Know About
SFBigAnalytics_20190724: Monitor kafka like a Pro
A Modern C++ Kafka API | Kenneth Jia, Morgan Stanley
Making Sense of Your Event-Driven Dataflows (Jorge Esteban Quilcate Otoya, SY...
Producer Performance Tuning for Apache Kafka
Migrating to Multi Cluster Managed Kafka - Conf42 - CloudNative
Consumer offset management in Kafka
Follow the (Kafka) Streams
Building a Replicated Logging System with Apache Kafka
Let the alpakka pull your stream
Apache Kafka, and the Rise of Stream Processing
Kafka Summit SF 2017 - MultiCluster, MultiTenant and Hierarchical Kafka Messa...
Getting Started with Confluent Schema Registry
Kafka Streams: the easiest way to start with stream processing
Kafka on Kubernetes: Does it really have to be "The Hard Way"? (Viktor Gamov,...
Kafkaesque days at linked in in 2015
Real Time Streaming Data with Kafka and TensorFlow (Yong Tang, MobileIron) Ka...
Ad

Similar to Exactly Once Delivery with Kafka - Kafka Tel-Aviv Meetup (20)

PDF
Exactly once delivery is a harsh mistress - DevOps Days TLV
PDF
Exactly Once Delivery is a Harsh Mistress - Natan Silnitsky
PPTX
Exactly Once Delivery - Natan Silnitsky
PDF
Message reliability in kafka
PDF
Message reliability in Kafka
PDF
Scaling big with Apache Kafka
PDF
Exactly-once Semantics in Apache Kafka
PDF
TDEA 2018 Kafka EOS (Exactly-once)
PDF
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
DOCX
A Quick Guide to Refresh Kafka Skills
PDF
Building Stream Processing Applications with Apache Kafka's Exactly-Once Proc...
PDF
Kafka Overview
PPTX
Event Driven Architectures
PDF
Event Driven Architectures
PPTX
Kafka eos
PDF
Exactly-once Stream Processing Done Right with Matthias J Sax
PDF
Jax london - Battle-tested event-driven patterns for your microservices archi...
PDF
Battle-tested event-driven patterns for your microservices architecture - Sca...
PPTX
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
PDF
Battle-tested event-driven patterns for your microservices architecture - Sca...
Exactly once delivery is a harsh mistress - DevOps Days TLV
Exactly Once Delivery is a Harsh Mistress - Natan Silnitsky
Exactly Once Delivery - Natan Silnitsky
Message reliability in kafka
Message reliability in Kafka
Scaling big with Apache Kafka
Exactly-once Semantics in Apache Kafka
TDEA 2018 Kafka EOS (Exactly-once)
Exactly-Once Made Easy: Transactional Messaging Improvement for Usability and...
A Quick Guide to Refresh Kafka Skills
Building Stream Processing Applications with Apache Kafka's Exactly-Once Proc...
Kafka Overview
Event Driven Architectures
Event Driven Architectures
Kafka eos
Exactly-once Stream Processing Done Right with Matthias J Sax
Jax london - Battle-tested event-driven patterns for your microservices archi...
Battle-tested event-driven patterns for your microservices architecture - Sca...
When it Absolutely, Positively, Has to be There: Reliability Guarantees in Ka...
Battle-tested event-driven patterns for your microservices architecture - Sca...
Ad

More from Natan Silnitsky (20)

PDF
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
PDF
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
PDF
Reinventing Microservices Efficiency and Innovation with Single-Runtime
PDF
Async Excellence Unlocking Scalability with Kafka - Devoxx Greece
PDF
Wix Single-Runtime - Conquering the multi-service challenge
PDF
WeAreDevs - Supercharge Your Developer Journey with Tiny Atomic Habits
PDF
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
PDF
Effective Strategies for Wix's Scaling challenges - GeeCon
PDF
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
PDF
Workflow Engines & Event Streaming Brokers - Can they work together? [Current...
PDF
DevSum - Lessons Learned from 2000 microservices
PDF
GeeCon - Lessons Learned from 2000 microservices
PDF
Migrating to Multi Cluster Managed Kafka - ApacheKafkaIL
PDF
Wix+Confluent Meetup - Lessons Learned from 2000 Event Driven Microservices
PDF
BuildStuff - Lessons Learned from 2000 Event Driven Microservices
PDF
Lessons Learned from 2000 Event Driven Microservices - Reversim
PDF
Devoxx Ukraine - Kafka based Global Data Mesh
PDF
Devoxx UK - Migrating to Multi Cluster Managed Kafka
PDF
Dev Days Europe - Kafka based Global Data Mesh at Wix
PDF
Kafka Summit London - Kafka based Global Data Mesh at Wix
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Reinventing Microservices Efficiency and Innovation with Single-Runtime
Async Excellence Unlocking Scalability with Kafka - Devoxx Greece
Wix Single-Runtime - Conquering the multi-service challenge
WeAreDevs - Supercharge Your Developer Journey with Tiny Atomic Habits
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Effective Strategies for Wix's Scaling challenges - GeeCon
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Workflow Engines & Event Streaming Brokers - Can they work together? [Current...
DevSum - Lessons Learned from 2000 microservices
GeeCon - Lessons Learned from 2000 microservices
Migrating to Multi Cluster Managed Kafka - ApacheKafkaIL
Wix+Confluent Meetup - Lessons Learned from 2000 Event Driven Microservices
BuildStuff - Lessons Learned from 2000 Event Driven Microservices
Lessons Learned from 2000 Event Driven Microservices - Reversim
Devoxx Ukraine - Kafka based Global Data Mesh
Devoxx UK - Migrating to Multi Cluster Managed Kafka
Dev Days Europe - Kafka based Global Data Mesh at Wix
Kafka Summit London - Kafka based Global Data Mesh at Wix

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPT
Teaching material agriculture food technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
Advanced methodologies resolving dimensionality complications for autism neur...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Dropbox Q2 2025 Financial Results & Investor Presentation
Review of recent advances in non-invasive hemoglobin estimation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology

Exactly Once Delivery with Kafka - Kafka Tel-Aviv Meetup