Is Exactly Once Delivery a pipe dream? Recent versions of Kafka have claimed they have made it a reality. In this talk I will go over the different message delivery guarantees and the protocols that implement them. I will focus on Kafka's transaction based messaging protocol, It’s trade-offs and shortcomings. And how it can power Wix's event-driven Infra for its highly distributed environment.
Is Exactly Once Delivery a pipe dream? Recent versions of Kafka have claimed they have made it a reality.
In this talk I will go over the basic theory of messaging in distributed systems, the different message delivery guarantees and the protocols that implement them.
I will focus on exactly once delivery guarantees and the way Kafka implements it with transaction based messaging protocol between the producer and the consumer.
Including a discussion of the latency/throughput trade-offs, resource utilisation and its overall shortcomings.
Finally, I will show how it has helped power Wix's event-driven data-streaming and data-storage Infrastructure we hope to open source soon.
This infrastructure greatly simplifies building and maintaining services in a highly distributed production environment.
It lets developers focus on business logic instead of keep making sure their code is idempotent and fault-tolerant.
Exactly Once Delivery is a Harsh Mistress - Natan Silnitsky
1. natans@wix.com twitter @NSilnitsky linkedin/natansilnitsky github.com/natansil
Exactly Once Delivery
is a harsh mistress
Natan Silnitsky
Backend Infra Developer, Wix.com
2. As it happens,
we have a distributed system at Wix.
~1400 micro-services
@NSilnitsky
3. As it happens,
we have a distributed system at Wix.
Edit MySite
~1400 micro-services
~850M messages every day
@NSilnitsky
5. 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...
13. The options for
message delivery
Why Exactly-Once
is difficult
Kafka’s solution for
Exactly-Once
delivery
14. 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
15. 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
16. Kafka Broker
0 1 2 3 4 5
😕 Messages may be lost
Consumer commits
before processing
consumerRecords = Consumer.poll
Consumer.commit
process(consumerRecords)
at-most-onceat-least-once exactly-once
Kafka
Consumer
17. 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
18. The options for
message delivery
Why Exactly-Once
is difficult
Kafka’s solution for
Exactly-Once
delivery
39. 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
@NSilnitsky
45. Resources
EoS in Kafka talk by Jason Gustafson
Exactly-once Semantics are Possible by Neha Narkhede
Transactions in Apache Kafka
Revisiting Exactly One Semantics by Jason Gustafson, Confluent
Proposal to improve EOS Produce scalability
How akka works with exactly once message delivery by Hugh McKee