Check out @MiloslavPojman presenting at #EuroPython2024, in their words: 'In this session, we will explore battle-tested techniques to enhance the maintainability of your test suite. ' https://t.co/chCJW49HJh 🐍
5.5+ years of working on Apache Kafka and I still confuse it.
So I don’t blame you either.
Exactly Once Semantics (EOS). What does it mean?
It means guaranteeing that you process a message once. 1️⃣
Not less, not more - 1 time exactly. It’s surprisingly difficult to guarantee.
Let’s get something out of the way first.
❌ Exactly Once DELIVERY is provably impossible. (look up the “Two Generals Problem”)
Long-story short? 🤨
The network is inherently unreliable. Therefore, the client can't know why it didn’t get the acknowledgment.
🤔 did the message fail to send?
🤔 did it succeed, but the acknowledgment failed to arrive?
🤔 is it in progress, and it’s just the network being slow?
There are impractical ways around it, but honestly - it doesn’t matter for this discussion. 🙅♂️ It only confuses.
Focus on Processing.
Exactly Once Processing says that a message is PROCESSED only once.
💡 Definition of Processed here == when all results of the processing are durably persisted
Kafka supports EOS out of the box in Kafka Streams through transactions and the idempotent producer. ✅
The root solution here is being able to atomically persist your progress and results at once. If you have that, you can always restart and pick it back up correctly.
Transactions allow Kafka clients to have a reliable atomic write. You write 20 messages to 10 partitions in 5 topics, and you know that either all end up there or none. (EOS relies on this)
EOS in Kafka Streams follows the pattern of read-process-write.
1. read from a Kafka topic
2. process the message
3. write to a Kafka topic
The app can fail in the middle of any of these steps, but because it both persists the results of the processing and its progress in the same transaction, it knows that it can either:
👍 - atomically have both: tx's progress and result persisted.
or
👎 - none: nothing persisted.
On failure, it restarts from a clean state - the last durably-persisted result, as indicated by its progress checkpoint. 💿
Critically, this EOS support is limited only to intra-Kafka operations.
You read from a Kafka topic and you persist to a Kafka topic.
There’s no other system in this example. The moment you add an external system, things become much more complex. ❌
Further, if you want to do this outside of Kafka Streams, you will need to do some complex coding.
The API provides the low-level building blocks to achieve this read-process-write pattern, but you need to implement the complex logic yourself.
Unfortunately, the support in Kafka is not Magical Pixie Dust you can sprinkle on any app just like that.
But any support is infinitely better than no support! 🥳
The iPhone camera uses computational photography, applying software to every snap.
This wild photo is an eery example: the subject tries on a wedding dress and each mirror shows her in a different pose.
Why? Apple insider says it’s a “mistake” in the computational photography pipeline:
➡️ “The iPhone camera doesn’t realize it was taking a photo of a mirror, so it treated the three versions of [UK actress Tessa Coates] as different people. Coates was moving when the photo was taken, so when the shutter was pressed, many differing images were captured in that instant. Apple's algorithm stitches the photos together, choosing the best versions for saturation, contrast, detail, and lack of blur.” ⬅️