
Swift.org’s November 11 roundup highlighted Swift Kafka Client 1.0.0, a server-side Swift client built on librdkafka. It works with Swift structured concurrency, integrates with swift-metrics and supports static Linux builds. Before adopting it for a service, try one experiment that tests more than a successful connection. Stop the consumer immediately after it writes a record, restart it and see whether the same business change happens twice. Swift.org’s November package roundup.
Separate a business event from a Kafka offset
Imagine a warehouse service processing StockReceived. Event shipment-418 adds six units of one part. Kafka places a record at an offset in a particular partition, and a consumer group tracks how far it has progressed. The database write that adds the units takes place in another system. A deployment or crash can separate that database transaction from the consumer’s progress update. Apache Kafka’s delivery semantics.
If the consumer records progress first and then fails before saving the inventory, the six units may never reach the database. If the service saves first and fails before progress is recorded, it can receive the record again. The choice matters even if processing every message takes only a few milliseconds. A quick success-path demo rarely exercises either failure window.
Make a second delivery harmless
Give each business event an identifier that the producer preserves across retries. In one database transaction, insert that identifier into a table with a unique constraint and apply the inventory change only if the insert succeeds. Finish the database transaction before allowing the consumer to record this work as complete. On replay, the existing identifier tells the handler that the six units have already been counted.
Two design details change the outcome. The deduplication record and inventory update must commit together. Also, if several records from a partition run concurrently, avoid marking progress beyond work that is still unfinished. For a first deployment, processing each partition in order can make the recovery story much easier to reason about. Swift Kafka Client 1.0 release.
Collect evidence on restart
In a test system, send two unique events, replay one and inspect the final quantity. Then interrupt a run in the gap after the database commit. Record the event IDs, partition, offsets, observed retries and final stock level. Track consumer lag as well as processed events and duplicates. A lagging consumer that preserves correctness can catch up. A dashboard showing zero lag cannot tell you that a shipment was counted twice.
