Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

At-Most-Once Delivery

At-most-once delivery guarantees that messages are delivered zero or one time, never more. Messages may be lost but are never duplicated. This semantic provides the highest performance but lowest reliability.


At-most-once delivery guarantee and its loss scenarios

PropertyGuarantee
Delivery count0 or 1
Message lossPossible
DuplicatesNever
OrderingPreserved within partition

The producer sends messages without waiting for acknowledgment.

Fire-and-forget producer sending without acknowledgment

# At-most-once producer configuration
acks=0 # No broker acknowledgment
retries=0 # No retry on failure
buffer.memory=67108864 # 64MB buffer
linger.ms=5 # Batch for 5ms
batch.size=32768 # 32KB batch size
max.in.flight.requests.per.connection=1000 # High parallelism
ConfigurationValueRationale
acks=00Producer does not wait for broker acknowledgment
retries=00No retry; failed sends are lost
linger.ms5Small batch window for throughput
batch.size32KBReasonable batch size
max.in.flight.requests.per.connection1000Maximum parallelism
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka:9092");
props.put(ProducerConfig.ACKS_CONFIG, "0");
props.put(ProducerConfig.RETRIES_CONFIG, 0);
props.put(ProducerConfig.LINGER_MS_CONFIG, 5);
props.put(ProducerConfig.BATCH_SIZE_CONFIG, 32768);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
Producer<String, String> producer = new KafkaProducer<>(props);
// Fire and forget - no callback, no Future.get()
for (Metric metric : metrics) {
producer.send(new ProducerRecord<>("metrics", metric.key(), metric.toJson()));
}
// Buffer flush (optional, at shutdown)
producer.flush();
producer.close();

Performance Characteristics (Repository Guidance)

Section titled “Performance Characteristics (Repository Guidance)”
SettingAcknowledgmentPerformance and durability trade-off
acks=0The producer does not wait for a broker response.Can reduce latency, but delivery is unconfirmed and loss can go unnoticed.
acks=1The leader responds after writing the record locally.Waits for a response; a leader failure can still cause loss before replication.
acks=allThe leader waits for the in-sync replicas before responding.Replication adds coordination; durability also depends on min.insync.replicas.

Acknowledgment settings alone do not determine end-to-end delivery semantics. Measure latency, throughput, and CPU usage for your workload: results depend on the environment and configuration.


At-most-once consumers commit offsets before processing, ensuring no redelivery but risking message loss on failure.

Consumer committing offsets before processing records

# At-most-once consumer configuration
enable.auto.commit=false # Manual commit control
auto.offset.reset=latest # Skip old messages on new consumer
max.poll.records=500 # Batch size
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka:9092");
props.put(ConsumerConfig.GROUP_ID_CONFIG, "metrics-processor");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
props.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, 500);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Collections.singletonList("metrics"));
while (running) {
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
if (!records.isEmpty()) {
// Commit BEFORE processing (at-most-once)
consumer.commitSync();
// Process after commit - failure here loses messages
for (ConsumerRecord<String, String> record : records) {
processMetric(record.value());
}
}
}

Using auto-commit for at-most-once semantics (example only; not recommended due to timing complexity):

enable.auto.commit=true
auto.commit.interval.ms=100 # Very frequent commits

Auto-Commit Timing

Auto-commit timing does not guarantee at-most-once semantics. Manual commit-before-process provides explicit control.


Producer failure scenarios that lose messages

FailureOutcomeMitigation
Network timeoutMessage lostAccept loss
Broker unavailableMessage lostAccept loss
Serialization errorMessage droppedLog error
Buffer fullBlock or exceptionIncrease buffer
Producer crashBuffer lostAccept loss

Consumer crash after commit leaving records unprocessed

Failure PointRecords AffectedOutcome
After commit, before processAll polled recordsLost
During processingRemaining unprocessedLost
After processingNoneNo impact

IoT telemetry pipeline using at-most-once delivery Why at-most-once works:

  • High data volume means individual points are expendable
  • Aggregates (averages, percentiles) remain accurate
  • Next reading arrives within seconds
  • Throughput matters more than individual reliability
Data TypeLoss ImpactSemantic
Player position updatesOld data stale anywayAt-most-once
Kill/death eventsMust be recordedAt-least-once
Chat messagesMust not be lostAt-least-once
HeartbeatsExpendableAt-most-once
# Log forwarder configuration (at-most-once acceptable)
acks=0
retries=0
compression.type=lz4 # High compression
linger.ms=100 # Batch aggressively
batch.size=1048576 # 1MB batches

Rationale:

  • Log volume often exceeds retention capacity
  • Missing a few log lines rarely impacts debugging
  • Throughput and cost are primary concerns
  • Duplicates would complicate log analysis

MetricAlert ConditionAction
record-send-totalDropping significantlyCheck connectivity
record-error-rate> 1%Investigate errors
buffer-available-bytes< 10% of totalIncrease buffer or reduce rate
batch-size-avgVery smallIncrease linger.ms
MetricAlert ConditionAction
records-consumed-totalLower than expectedCheck producer health
commit-latency-avgHighCheck broker health
records-lagGrowingScale consumers

At-most-once systems should monitor approximate loss:

// Producer-side counter
AtomicLong sendAttempts = new AtomicLong(0);
AtomicLong sendErrors = new AtomicLong(0);
producer.send(record, (metadata, exception) -> {
sendAttempts.incrementAndGet();
if (exception != null) {
sendErrors.incrementAndGet();
}
});
// Estimated loss rate
double lossRate = (double) sendErrors.get() / sendAttempts.get();

Loss Estimation

With acks=0, the callback exception only captures local errors. Network and broker-side losses are not reported and must be estimated through consumer-side analysis.


// WRONG: Financial transactions must not be lost
producer.send(new ProducerRecord<>("payments", payment.toJson()));
// No ack, no retry - payment may be lost!

Instead: Use at-least-once with idempotent processing:

props.put(ProducerConfig.ACKS_CONFIG, "all");
props.put(ProducerConfig.RETRIES_CONFIG, Integer.MAX_VALUE);
props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);

Anti-pattern: mixed producer durability settings on one topic Instead: Separate topics by reliability requirement:

metrics-realtime → at-most-once (high volume, low value)
metrics-critical → at-least-once (auditing, billing)

AspectAt-Most-OnceAt-Least-OnceExactly-Once
Message lossPossibleNo loss when durability settings are metNever
DuplicatesNeverPossibleNever
LatencyLowestLowHigher
ThroughputHighestHighModerate
ComplexitySimpleModerateComplex
Use caseTelemetry, logsMost workloadsFinancial, billing

When requirements change, migrating from at-most-once to stronger semantics:

# Change from acks=0 to acks=1 or acks=all
acks=all
retries=2147483647
retry.backoff.ms=100
enable.idempotence=true
// Change from commit-before-process to process-before-commit
for (ConsumerRecord<String, String> record : records) {
process(record); // Process first
}
consumer.commitSync(); // Then commit