Scrivio Interview library
ConceptFoundations7 min read · updated 13 November 2026

Deduplication mechanisms differ in what they compare and how long they remember. A producer-level dedup, a broker-level deduplication window and an application idempotency table each cover a different part of the path.

Compare the Kafka idempotent producer, SQS FIFO deduplication and an application idempotency-key table: which duplicates each removes, over what scope and time window, and what each leaves to you.

The Kafka idempotent producer removes duplicates caused by its own retries within one producer session, using a producer id and per-partition sequence numbers. SQS FIFO drops a message with the same deduplication id sent within a fixed 5-minute window. An application idempotency-key table remembers keys and results for as long as we choose and covers client retries end to end, across restarts. None of them stops a consumer from processing a redelivered message twice, so consumers still need idempotent processing, and every window must be longer than the slowest realistic retry or replay.

Why this question is asked

"We have deduplication" is a sentence that often hides a gap. Each deduplication mechanism compares something specific and remembers it for a specific time, and a duplicate created outside that scope slips straight through. Interviewers ask this comparison because it shows whether we understand what each layer actually guarantees. In this answer, we will look at the different places duplicates are born, then go through the Kafka idempotent producer, SQS FIFO deduplication and an application idempotency table, and finish with what is left to us and how to choose windows.

1Where Duplicates Are Born

A duplicate can appear at several points on the path from a client to the final effect. The client may retry a request after a timeout, even though the first attempt succeeded. A service may restart and send the same event again. A producer may retry a write to the broker because the acknowledgement was lost. A consumer may crash after doing the work but before acknowledging, and receive the message again. And an operator may replay messages from a dead-letter queue days later.

Each mechanism we compare covers some of these points and not others. The useful way to compare them is to ask three questions of each: what does it compare, how long does it remember, and which duplicates does it leave to us.

2The Kafka Idempotent Producer

When idempotence is enabled, which is the default for the Java producer since Kafka 3.0, the broker assigns the producer a producer id, and the producer numbers each batch it sends to a partition with an increasing sequence number. If a send times out and the producer retries, the broker sees a sequence number it has already written for that producer id and partition, and acknowledges without writing it again.

Java
props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true); // default since Kafka 3.0
props.put(ProducerConfig.ACKS_CONFIG, "all"); // required for idempotence
producer.send(new ProducerRecord<>("payments", "order-77", json)); // network retry: no duplicate
producer.send(new ProducerRecord<>("payments", "order-77", json)); // our code sent it twice: 2 records

Notice the second call. The broker only removes duplicates of the same batch caused by the producer's own retries. If our application calls send() twice with the same event, those are two different sends with two sequence numbers, and both are written. And if the producer process restarts, it gets a new producer id, so it cannot be recognised as the same producer, unless it uses transactions with a stable transactional.id. So the scope is one producer session, and the window is that session's in-flight retries.

3SQS FIFO Deduplication

An SQS FIFO queue deduplicates at the broker. Each message carries a deduplication id, either set explicitly or, with content-based deduplication enabled, computed as a SHA-256 hash of the message body. If another message with the same deduplication id arrives within the 5-minute deduplication interval, SQS accepts the send but does not deliver the message again.

Java
SendMessageRequest req = SendMessageRequest.builder()
.queueUrl(queueUrl)
.messageGroupId("order-77")
.messageDeduplicationId("evt-81f2")
.messageBody(json)
.build();
sqs.sendMessage(req); // 10:00:00 delivered
sqs.sendMessage(req); // 10:03:00 accepted, not delivered again (within 5 minutes)
sqs.sendMessage(req); // 10:06:00 delivered again: the interval has passed

This covers a different scope from Kafka's: any sender, even after a restart, as long as it uses the same deduplication id. But the window is fixed at 5 minutes, and we cannot change it. A sender that retries 10 minutes later, or a replay the next day, produces a message SQS treats as new.

4An Application Idempotency-Key Table

The third mechanism is our own. The client sends an Idempotency-Key with each operation, and the service stores the key, a hash of the request and the result in a table. When the same key arrives again, the service returns the stored result instead of repeating the work. If the same key arrives with a different request hash, it rejects the request, because that is a client bug.

Java
CREATE TABLE idempotency_key (
key text PRIMARY KEY,
request_hash text NOT NULL,
response jsonb,
created_at timestamptz NOT NULL DEFAULT now()
);
-- first request: INSERT ... ON CONFLICT DO NOTHING -> INSERT 0 1, do the work, store response
-- retry: INSERT ... ON CONFLICT DO NOTHING -> INSERT 0 0, return the stored response
-- cleanup job: DELETE FROM idempotency_key WHERE created_at < now() - interval '30 days';
Comparing the three mechanisms
MechanismComparesWindowLeaves to you
Kafka idempotent producerproducer id + partition sequenceone producer sessionapp resends, restarts, consumers
SQS FIFO deduplicationdedup id or body hashfixed 5 minuteslate retries, replays, consumers
Idempotency-key tableclient key + request hashyour retentionkeys chosen well, consumers

Its scope is end to end: from the client's first attempt through gateways, restarts and deploys, because the key is chosen by the client and stored durably. Its window is whatever retention we choose, 24 hours or 30 days. The cost is that we build, store and clean it up ourselves.

5What None of Them Covers, and How to Choose Windows

All three mechanisms prevent a duplicate from being stored or delivered. None of them stops a consumer from processing the same delivered message twice: if the consumer does the work and crashes before acknowledging, the broker redelivers it, and the work runs again. So consumers still need idempotent processing, for example an upsert by event id, or a processed-ids table updated in the same transaction as the work.

The second lesson is about windows. A window is only useful if it is longer than the longest realistic gap between the original and the duplicate. That includes client retry policies, mobile apps that retry after coming back online hours later, and especially manual replays from dead-letter queues, which may happen days later after a fix. A 24-hour idempotency table that meets a replay on day three provides no protection. We choose retention from those delays, not from what feels like a reasonable number.

6Follow-up questions

Does a Kafka transactional producer extend the deduplication scope?

Partly. With a stable transactional.id, a restarted producer fences off its old instance and continues with the same identity, and its read-process-write loop within Kafka becomes exactly-once. But it still does not recognise the same business event sent twice by application logic; that needs a business key.

Should the deduplication id in SQS be a hash of the body?

Content-based deduplication is convenient, but two genuinely different messages with identical bodies would be dropped, and a retry with a slightly different body, such as a new timestamp field, would not be recognised. An explicit id derived from the business event is safer.

Where should the consumer keep its processed ids?

In the same database and transaction as the work it protects. Then the work and the record that it was done commit together, and a redelivery always finds a consistent answer.

7Conclusion

In this answer, we compared three deduplication layers. The Kafka idempotent producer removes its own retry duplicates within one producer session. SQS FIFO drops messages with the same deduplication id within a fixed 5-minute interval. An application idempotency table covers client retries end to end for as long as we keep the keys. None of them protects against a consumer processing a redelivered message twice, so consumers stay idempotent, and every window must outlast the slowest retry or replay, including dead-letter replays days later.

What to say in the interviewAbout 90 seconds aloud

Open with

They cover different parts of the path. Kafka's idempotent producer, on by default since 3.0, gives the producer an id and numbers each batch per partition, so when the producer retries after a lost acknowledgement, the broker drops the repeat.

Then, if they want more

That only covers retries inside one producer session; if my application sends the same event twice, or the producer restarts without a transactional id, I get duplicates. SQS FIFO deduplicates at the broker by deduplication id, or by a SHA-256 of the body with content-based deduplication, but only within a fixed five-minute interval.

Any sender is covered, even after a restart, but a retry or replay after five minutes counts as new. An application idempotency-key table is the end-to-end option: the client's key, a request hash and the stored result, kept for as long as I decide, twenty-four hours or thirty days, so it covers client retries across gateways, restarts and deploys.

The catch with all three is that none stops a consumer from processing a delivered message twice after crashing before its acknowledgement, so consumers still need idempotent processing, like an upsert by event id or a processed-ids table in the same transaction.

And I'd choose windows from the longest realistic delay, including manual dead-letter replays that can happen days later; a twenty-four-hour window is useless against a replay on day three.

About this answer

Last updated
13 November 2026
Versions it names
Kafka 3.0
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Compare the Kafka idempotent producer, SQS FIFO deduplication and an application...": https://scrivio-interview-library.netlify.app/architecture/distributed-systems/d2e8a43d9e/