Practice
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Frontend UI Machine Coding
Resources
Career Advice and Roadmaps
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Backend Development
Frontend Development
Project Ideas for Software Developers
Core Computer Science
Companies
SDE Jobs & Internships
Interview Questions
Compare Companies
IDE
Online IDE
Collaborative IDE

Design a Distributed Queue | Kafka | Machine Coding Round Questions (SDE II/III)

Gaurav Chandak
Gaurav Chandak

Machine Coding Round Complete Guide

  • What is a Machine Coding Round?
  • How to prepare for Machine Coding Round?
  • How to clear the Machine Coding Round?
  • Machine Coding Round Interview Practice Questions
  • Machine Coding Round Interview Solutions/Editorials

Problem Statement

Design an In-Memory Distributed Queue like Kafka.

Requirements

  • The queue should be in-memory and should not require access to the file system.
  • There can be multiple topics in the queue.
  • A (string) message can be published on a topic by a producer/publisher and consumers/subscribers can subscribe to the topic to receive the messages.
  • There can be multiple producers and consumers.
  • A producer can publish to multiple topics.
  • A consumer can listen to multiple topics.
  • The consumer should print "<consumer_id> received <message>" on receiving the message.
  • The queue system should be multi-threaded, i.e., messages can be produced or consumed in parallel by different producers/consumers.

Input/Output Format

  • You do not need to take input from the command-line.
  • Create 2 topics: topic1 and topic2
  • Create 2 producers: producer1, and producer2
  • Create 5 consumers: consumer1, consumer2, consumer3, consumer4, and consumer5
  • Make all 5 consumers subscribe to topic1
  • Make consumers 1, 3, and 4 subscribe to topic2
  • Make producer1 publish message "Message 1" to topic1
  • Make producer1 publish message "Message 2" to topic1
  • Make producer2 publish message "Message 3" to topic1
  • Make producer1 publish message "Message 4" to topic2
  • Make producer2 publish message "Message 5" to topic2

Expectations

  • Make sure that you have a working and demonstrable code
  • Make sure that the code is functionally correct
  • Code should be modular and readable
  • Separation of concern should be addressed
  • Please do not write everything in a single file (if not coding in C/C++)
  • Code should easily accommodate new requirements and minimal changes
  • There should be a main method from where the code could be easily testable
  • [Optional] Write unit tests, if possible
  • No need to create a GUI

Optional Requirements

  • Allow consumer groups. A consumer group can have multiple consumers and consumers mention their consumer group while subscribing to a topic. A message can be consumed by only one consumer per consumer group.
Gaurav Chandak
Gaurav Chandak
Gaurav is the co-founder of workat.tech and has previously worked at Flipkart and Microsoft. He intends to actively contribute to the future of education through workat.tech.
Related Content
Design an In-Memory Key-Value Store | Machine Coding Round Questions (SDE II/III)
Design Chess Validator | Machine Coding Round Questions (SDE I/II)
Design a Library Management System | Machine Coding Round Questions (SDE II)
SDE Bootcamp - Become a software engineer at a product-based company
Practice Machine Coding
Learning Resources
Interview Prep Resources
Blog
  • Career Advice and Roadmaps
  • Data Structures & Algorithms
  • Machine Coding Round (LLD)
  • System Design & Architecture
  • Backend Development
  • Frontend Development
  • Awesome Project Ideas
  • Core Computer Science
Practice Questions
  • Machine Coding (LLD) Questions
  • System Design (HLD) Questions
  • Topic-wise DSA Questions
  • Company-wise DSA Questions
  • DSA Sheets (Curated Lists)
  • JavaScript Interview Questions
  • Frontend UI Machine Coding Questions
Online Compilers (IDE)
  • Online Java Compiler
  • Online C++ Compiler
  • Online C Compiler
  • Online Python Compiler
  • Online JavaScript Compiler
Topic-wise Problems
  • Dynamic Programming Interview Questions
  • Linked List Interview Questions
  • Graph Interview Questions
  • Backtracking Interview Questions
  • Arrays Interview Questions
  • Trees Interview Questions
Company-wise Problems
  • Amazon Interview Questions
  • Microsoft Interview Questions
  • Google Interview Questions
  • Flipkart Interview Questions
  • Adobe Interview Questions
  • Facebook Interview Questions
DSA Sheets (Curated Lists)
  • Top Interview Questions
  • FAANG Interview Questions
  • Most Asked Interview Questions
  • 6 month DSA Practice Sheet
  • 3 month DSA Practice Sheet
  • Last minute DSA Practice Sheet