Kafka
Visibility Timeout
Message Queuing
Distributed Systems
Software Architecture

Does Kafka have a visibility timeout?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Apache Kafka, a popular distributed streaming platform, fundamentally differs from traditional message queuing systems in several ways, including how it handles message visibility and processing. Unlike systems such as Amazon SQS that have a concept of "visibility timeout," Kafka operates based on a different model which focuses on log retention.

Understanding Kafka's Message Model

Kafka stores messages in topics which are divided into partitions. Each partition is an ordered, immutable sequence of messages that is continually appended to. Producers write messages to these partitions and consumers read messages from them. Importantly, the messages are not deleted after consumption. Instead, they are retained according to a configurable retention policy, which could be based on time or size.

Consumer Offsets and Message Processing

In Kafka, each consumer in a consumer group tracks its position in each partition via something called an offset. This offset marks the location of the consumer in the log. Consumers have the control to manage their offsets and may even reprocess messages by resetting the offset. This mechanism does not hide messages from other consumers while one consumer is processing it; rather, it allows multiple consumers to read the same message independently if they so choose.

Comparison with Visibility Timeout Concept

In queue systems like Amazon SQS, the visibility timeout is a crucial feature. This timeout hides a message from other workers once a worker has picked it up for processing. If the processing is completed within the timeout, the message is deleted. If not, the message becomes visible again so that other workers can pick it up.

This concept does not exist in Kafka because Kafka relies on the concept that messages are not "picked up" or "locked" but are read. Since Kafka allows storing large volumes of messages and processing them at different speeds depending on consumer capability, it aligns more with a high-throughput use case where the same message might need to be consumed multiple times independently.

Implications for Kafka Users

For Kafka users, this model means understanding that once a message is committed to a Kafka topic, it is potentially visible to all consumers who have access to the topic, depending on their offset. This architectural decision simplifies Kafka's design but puts more responsibility on the consumers to handle message processing correctly, particularly in multi-consumer environments.

Technical Example

Imagine a scenario where two consumers, ConsumerA and ConsumerB, are reading from the same Kafka topic. If ConsumerA reads a message but fails to process it correctly, it will still move its offset forward. In contrast, ConsumerB might process the same message successfully. If ConsumerA has issues, it can reset its offset back to reprocess the message — without affecting ConsumerB.

Summary Table

FeatureKafkaSystems with Visibility Timeout like SQS
Message Consumption ModelRead based, with independent offsetsMessage locking during processing
Multiple ReadsAllowed and independentTypically not without re-queuing
Message VisibilityControlled by retention policyControlled by visibility timeout
Consumer Failure HandlingOffset reset for reprocessingVisibility timeout expiration
Use Case FitHigh throughput, re-readabilityDiscrete handling, less reprocessing

Conclusion

Kafka’s design does not include a visibility timeout feature because it employs a fundamentally different model of message consumption. While this results in high flexibility and scalability, it also requires developers and system architects to carefully design their consumers’ offset management and error handling strategies. Understanding these differences is crucial for leveraging Kafka effectively in a distributed system.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.