Design a Kafka-like Distributed Messaging System

Difficulty: EASYCategory: LLDFrequency: 1Asked On 2024-09-19

Problem Statement

Design a messaging system similar to Apache Kafka that supports high-throughput, distributed, fault-tolerant messaging. The system should allow producers to write messages to topics and consumers to consume messages from topics in a decoupled, reliable, and scalable way.

🎯 Core Functional Requirements

1.createTopic(String topicName)
•Creates a new topic that can accept messages from producers.
2.publish(String topicName, String message)
•Appends a message to the specified topic.
•Messages are stored in append-only fashion with an auto-incremented offset.
3.subscribe(String topicName, String consumerId)
•Registers a consumer to a topic. Each consumer will have a cursor (offset) indicating where to read from.
4.poll(String topicName, String consumerId)
•Returns the next unread message for the given consumer from the topic and advances the offset.
5.seek(String topicName, String consumerId, int offset)
•Allows the consumer to set their reading cursor to a specific offset.


Solution

Comments