Exactly-once in Apache Kafka is achieved through the use of idempotent producers and transactions. The producer must be configured with enable.idempotence=true, and transactional sessions (transactional.id) are required to coordinate message writing and processing. On the consumer side, it is recommended to use the read-process-write pattern with transaction support to guarantee atomicity of processing and offset commit within a single transaction. This approach prevents both duplication and loss of messages in case of failures.