Skip to main content
PreparationZone Logo
PrepZone

Send API: Sync, Async, and Callbacks

RecordMetadata, CompletableFuture callbacks, and when VaultCommerce blocks on publish vs fires-and-forgets.

Pass checkpoint below

Why this matters

  • VaultCommerce uses async send with callbacks for order events; sync .get() only in the outbox relay where failure must be immediate.
  • Callbacks run on the producer's I/O thread — keep them fast or offload heavy work.
  • RecordMetadata carries partition, offset, and timestamp for tracing.
  • Understanding sync vs async send prevents thread pool exhaustion under load.
ApplicationVaultCommerce OrderService
Serializer
Record batch
Broker leader
Serializer → partitioner → record batch → broker leader. Callback fires with RecordMetadata or error.

Async send with callbacks

The happy path: producer.send(record, (metadata, exception) -> { ... }). On success, log metadata.partition() and metadata.offset() for correlation with consumer processing. VaultCommerce attaches traceId in headers and logs it alongside broker metadata.

Key points

  • Future<RecordMetadata> — handle to in-flight send; completes on broker ack
  • Callback — invoked on success or failure; must not block
  • RecordMetadata — partition, offset, timestamp, serialized sizes
  • flush() — force send of all buffered records before shutdown
  • max.block.ms — how long send() blocks when metadata or buffer is unavailable

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 2 sections

  • Blocking send for critical paths
  • VaultCommerce rollout checklist

Test yourself

Answer these before moving on — recall is what makes it stick.