Sunday, August 2, 2026

Apache Kafka Interview Questions & Answers


Apache Kafka Interview Questions & Answers (Lead/Architect Level)

1. What is Apache Kafka?

Interview Answer

Apache Kafka is a distributed event streaming platform designed for high-throughput, fault-tolerant, scalable, and real-time data streaming. It allows applications to publish, store, and consume streams of events asynchronously.

Unlike traditional messaging systems that remove messages after they are consumed, Kafka stores messages for a configurable retention period, enabling multiple consumers to read the same events independently.

Kafka is widely used in:

  • Microservices

  • Event-Driven Architecture (EDA)

  • Real-time analytics

  • Log aggregation

  • IoT applications

  • Financial systems

  • E-commerce platforms


Real-Time Example

Amazon Order Processing

When a customer places an order:

Customer

↓

Order Service

↓

Kafka

↓

Payment Service

↓

Inventory Service

↓

Email Service

↓

Analytics Service

↓

Shipping Service

Every service receives the event independently.


Key Features

  • High Throughput

  • Fault Tolerance

  • Horizontal Scalability

  • Message Persistence

  • Event Replay

  • Distributed Architecture


Interview Tip

Kafka is an Event Streaming Platform, not just a Message Queue.


2. Explain Kafka Architecture

Kafka follows a distributed architecture.

                Producer

                    │

                    ▼

             Kafka Cluster

      ----------------------------

      Broker1

      Broker2

      Broker3

      ----------------------------

                    │

               Orders Topic

      ----------------------------

      Partition0

      Partition1

      Partition2

      ----------------------------

                    │

          Consumer Group

       Inventory Service

       Email Service

       Analytics Service

Components

Producer

Creates messages.

Topic

Stores messages logically.

Partition

Splits topic into multiple logs.

Broker

Stores partitions.

Consumer

Reads messages.


Flow

Angular

↓

.NET API

↓

Producer

↓

Topic

↓

Broker

↓

Consumer

↓

Database

Why Distributed?

If one broker crashes,

Other brokers continue serving requests.


3. What is a Broker?

A Broker is a Kafka server responsible for storing topic partitions and serving producer and consumer requests.

Example:

Kafka Cluster

Broker1

Broker2

Broker3

Each broker stores part of the data.


Responsibilities

  • Store messages

  • Handle producer requests

  • Serve consumers

  • Replicate data

  • Leader election

  • Offset management


Real Example

Topic has 6 partitions

Broker1

P0

P1

Broker2

P2

P3

Broker3

P4

P5

Interview Tip

Kafka Cluster = Collection of Brokers.


4. What is a Topic?

Topic is a logical category where messages are stored.

Example

Orders

Payments

Customers

Notifications

Producer writes

Orders Topic

Consumer reads

Orders Topic

Real Example

OrderCreated

↓

Orders Topic

Consumers

  • Inventory

  • Billing

  • Email

  • Analytics

All subscribe to the same topic.


Important

A Topic contains multiple partitions.


5. What is a Partition?

A partition is a physical subdivision of a topic.

Instead of

Orders

Kafka stores

Orders

Partition0

Partition1

Partition2

Why?

Allows parallel processing.

Suppose

1 Million Orders.

One partition

One Consumer

Slow.

Ten partitions

10 Consumers

Much faster.


Real Example

Partition0

Order1

Order4

Order7

Partition1

Order2

Order5

Order8

Partition2

Order3

Order6

Order9

Benefits

  • Scalability

  • Parallelism

  • Load balancing


6. What is an Offset?

Offset is the unique position of a message inside a partition.

Example

Partition0

Offset0

Offset1

Offset2

Offset3

Offset4

Consumer stores

Current Offset = 4

After restart,

Reads from Offset5.


Why Important?

  • Resume processing

  • Replay events

  • Fault recovery


Interview Tip

Offset is unique only within a partition, not across the entire topic.


7. Explain Consumer Groups

Consumer Group is a collection of consumers working together.

Example

Inventory Group

Consumer1

Consumer2

Consumer3

Topic

Partition0

Partition1

Partition2

Assignment

Consumer1 → Partition0

Consumer2 → Partition1

Consumer3 → Partition2

No duplicate processing occurs within the same group.


Multiple Groups

Orders Topic

↓

Inventory Group

↓

Email Group

↓

Analytics Group

Every group receives the same event independently.


Benefits

  • Scalability

  • Load balancing

  • Fault tolerance


8. Difference between Queue and Topic

QueueKafka Topic
Point-to-PointPublish-Subscribe
One consumer receives a messageMultiple consumer groups receive the same message
Message is typically removed after processingMessage is retained for a configured period
Limited replayReplay supported
Suitable for task distributionSuitable for event streaming

Queue Example

Producer

↓

Queue

↓

Consumer A

Consumer B never receives the message.


Kafka Topic Example

Producer

↓

Orders Topic

↓

Inventory Group

↓

Email Group

↓

Analytics Group

Every group processes the event.


9. Kafka vs RabbitMQ

KafkaRabbitMQ
Distributed Event StreamingTraditional Message Broker
Stores messages in logsStores messages in queues
Very high throughputModerate throughput
Supports replayReplay is limited
Excellent for analytics and streamingExcellent for task queues and request/response
Partition-based scalingQueue-based scaling

Real Use Cases

Kafka

  • Banking events

  • IoT

  • Real-time analytics

  • Clickstream processing

RabbitMQ

  • Email queues

  • Background jobs

  • Order processing tasks

  • RPC-style messaging


10. Why are partitions needed?

Partitions allow Kafka to scale horizontally.

Without partitions

1 Topic

↓

1 Consumer

With partitions

Partition0

Partition1

Partition2

↓

Consumer1

Consumer2

Consumer3

Benefits

  • Higher throughput

  • Better CPU utilization

  • Parallel processing

  • Horizontal scaling


11. How does Kafka guarantee ordering?

Kafka guarantees ordering only within a single partition.

Example

Partition0

Offset0 OrderCreated

Offset1 PaymentCompleted

Offset2 OrderShipped

Consumers read in offset order.

Across multiple partitions, there is no global ordering guarantee.

Best practice: If ordering is important for a business entity (for example, an order), use the same message key (OrderId) so Kafka routes all events for that key to the same partition.


12. What happens when a broker fails?

Kafka uses replication to maintain availability.

Broker1

Leader

↓

Broker2

Follower

↓

Broker3

Follower

If Broker1 fails:

  • Kafka elects a new leader from the in-sync replicas (ISR).

  • Producers and consumers continue working with the new leader.

  • When the failed broker comes back, it catches up and rejoins as a follower.

This minimizes downtime and prevents data loss when configured correctly.


13. What is replication factor?

The replication factor defines how many copies of each partition Kafka maintains.

Example:

Replication Factor = 3

Partition0

Leader → Broker1

Replica → Broker2

Replica → Broker3

If one broker fails, the replicas are available for leader election.

Trade-off:

  • Higher replication = better availability and durability.

  • Higher replication also requires more storage and network bandwidth.


14. What are producer acknowledgements (acks)?

The acks setting determines how many brokers must acknowledge a write before the producer considers it successful.

acks = 0

  • Producer does not wait.

  • Fastest.

  • Messages may be lost.

acks = 1

  • Waits for the leader broker only.

  • Good balance of speed and reliability.

  • Most common configuration.

acks = all (or -1)

  • Waits for all in-sync replicas.

  • Highest durability.

  • Slightly higher latency.


15. What is consumer lag?

Consumer lag is the difference between:

  • the latest offset written to a partition, and

  • the last offset processed by a consumer.

Example

Latest Offset = 1000

Consumer Offset = 900

Lag = 100

High lag may indicate:

  • Slow consumers

  • Insufficient consumer instances

  • Long-running processing

  • Resource bottlenecks

Monitoring consumer lag is essential in production systems.


16. What is an idempotent producer?

An idempotent producer ensures that retrying a message does not create duplicates.

Without idempotence:

Send Message

↓

Network Failure

↓

Retry

↓

Duplicate Message

With idempotence enabled:

Retry

↓

Kafka recognizes the duplicate

↓

Stores only one copy

In the .NET Confluent.Kafka client, this is enabled using:

var config = new ProducerConfig
{
    BootstrapServers = "localhost:9092",
    EnableIdempotence = true
};

This is especially important in payment and financial systems.


17. What is exactly-once processing?

Exactly-once processing (EOS) ensures that each event is processed only once, even in the presence of retries or failures.

Kafka achieves this through:

  • Idempotent producers

  • Transactions

  • Transaction-aware consumers

Example:

Transfer ₹100

↓

Kafka Event

↓

Retry

↓

Still processed only once

This is critical in banking, inventory, and billing systems where duplicate processing is unacceptable.


18. What is the role of Schema Registry?

Schema Registry centrally manages event schemas, commonly using Avro, Protobuf, or JSON Schema.

Benefits:

  • Producers and consumers agree on the event structure.

  • Supports schema evolution while maintaining compatibility.

  • Reduces message size (especially with Avro).

  • Prevents incompatible changes.

Example:

OrderCreated

OrderId

CustomerId

Amount

If a new field is added later, compatibility rules determine whether older consumers can still process the event.


19. How do you scale Kafka consumers?

Consumers scale through:

  1. Increasing the number of partitions.

  2. Adding more consumer instances to the same consumer group.

Example:

Topic

6 Partitions

↓

Consumer Group

Consumer1

Consumer2

Consumer3

Consumer4

Consumer5

Consumer6

Each consumer processes one partition.

Important rules:

  • A consumer group cannot process more partitions concurrently than the number of partitions available.

  • If there are more consumers than partitions, the extra consumers remain idle.


20. How do you integrate Kafka with .NET Core?

A common architecture is:

Angular

↓

ASP.NET Core Web API

↓

Kafka Producer

↓

Orders Topic

↓

Kafka Cluster

↓

Inventory Service

↓

Payment Service

↓

Email Service

↓

Analytics Service

Step 1: Install the Kafka client

dotnet add package Confluent.Kafka

Step 2: Configure the producer

var config = new ProducerConfig
{
    BootstrapServers = "localhost:9092"
};

using var producer =
    new ProducerBuilder<string, string>(config).Build();

Step 3: Publish an event

await producer.ProduceAsync(
    "orders",
    new Message<string, string>
    {
        Key = "1001",
        Value = JsonSerializer.Serialize(order)
    });

Step 4: Create a consumer

var config = new ConsumerConfig
{
    BootstrapServers = "localhost:9092",
    GroupId = "inventory-group",
    AutoOffsetReset = AutoOffsetReset.Earliest
};

using var consumer =
    new ConsumerBuilder<string, string>(config).Build();

consumer.Subscribe("orders");

while (true)
{
    var result = consumer.Consume();
    Console.WriteLine(result.Message.Value);
}

Angular Integration

Angular should not connect directly to Kafka.

Instead:

Angular

↓

HTTP POST

↓

ASP.NET Core Web API

↓

Kafka Producer

↓

Kafka Topic

The Web API validates the request, persists business data if needed, and publishes the event to Kafka.


Interview Summary (30-Second Answer)

"Apache Kafka is a distributed event-streaming platform used to build scalable, fault-tolerant, and asynchronous systems. Producers publish events to topics, which are split into partitions for parallel processing. Brokers store these partitions and replicate them for high availability. Consumer groups process events independently, while offsets track processing progress. In .NET Core, we typically use the Confluent.Kafka library to publish and consume events, exposing HTTP APIs for Angular clients while Kafka handles communication between backend microservices. This architecture improves scalability, resiliency, and loose coupling compared to direct service-to-service communication."

Apache Kafka

                                       

Apache Kafka Complete Tutorial for .NET Core & Angular Developers (Lead/Architect Level)

This tutorial is designed for Senior .NET Developers, Technical Leads, Architects, and Microservices Developers.

By the end of this guide, you'll understand:

  • What is Kafka?

  • Why Kafka was created?

  • Kafka Architecture

  • Kafka Components

  • Topics vs Queue

  • Producers & Consumers

  • Consumer Groups

  • Partitions

  • Replication

  • Offset

  • Broker

  • ZooKeeper vs KRaft

  • Event Driven Architecture

  • Integrating Kafka with .NET Core

  • Integrating Angular with Kafka using Web API

  • Real-time Microservices Example

  • Deployment in Docker

  • Azure Integration

  • Best Practices

  • Interview Questions


Chapter 1 - Why Kafka?

Imagine Amazon.

Thousands of events happen every second.

Customer places order
↓

Payment Completed
↓

Inventory Updated
↓

Invoice Generated
↓

Email Sent
↓

SMS Sent
↓

Loyalty Points Added
↓

Analytics Updated

If every service directly called another service,

Order Service
      ↓
Payment Service
      ↓
Inventory Service
      ↓
Email Service
      ↓
Notification Service

Problems

  • Tight Coupling

  • Slow

  • Difficult to Scale

  • Single Point Failure

Instead

Order Service

↓

Kafka

↓

Payment

Inventory

Shipping

Analytics

Email

Notification

Everything becomes independent.


Chapter 2 - What is Kafka?

Kafka is

A Distributed Event Streaming Platform

Think of Kafka as

Post Office

Producer

Post Office (Kafka)

Consumer

Producer doesn't know who receives.

Consumer doesn't know producer.

Everything is asynchronous.


Chapter 3 - Kafka Architecture

               Producer

                  |

                  |

           Kafka Cluster

         -----------------

         Broker 1

         Broker 2

         Broker 3

         -----------------

          Topic

      Orders

     Partition-0

     Partition-1

     Partition-2

          |

          |

 Consumer Group

Kafka Components

Producer

Produces Message.

Example

Order API

Order Created

Producer sends

OrderCreated Event

Broker

Kafka Server.

Stores all messages.

Example

Broker 1

Broker 2

Broker 3

Kafka Cluster = Collection of Brokers.


Topic

Topic is a category.

Example

Orders

Payments

Inventory

Shipping

Notification

Each topic contains messages.


Partition

A Topic is divided into multiple partitions.

Example

Orders Topic

---------------------

Partition 0

Partition 1

Partition 2

Partition 3

Partitions enable

  • Parallel Processing

  • Scalability

  • High Throughput


Offset

Each message has an ID.

Kafka calls it Offset.

Example

Offset

0

1

2

3

4

5

Consumer remembers

Last Offset = 5

If application crashes

Restart

Continue from Offset 6.


Consumer

Reads messages.

Example

Inventory Service

Email Service

Analytics Service

Notification Service

Consumer Group

Multiple consumers work together.

Example

Consumer Group

Inventory-1

Inventory-2

Inventory-3

Kafka distributes partitions.

Example

Partition0 → Consumer1

Partition1 → Consumer2

Partition2 → Consumer3

No duplication.


Queue vs Topic

This is one of the most asked interview questions.


Traditional Queue

Producer

↓

Queue

↓

Consumer

Only ONE consumer gets message.

Example

Queue

Message

↓

Consumer A

Consumer B

Consumer C

Only Consumer A receives.


Kafka Topic

Producer

↓

Topic

↓

Consumer Group A

Consumer Group B

Consumer Group C

All groups receive same message.

Inside a group,

only one consumer receives.


Example

Order Created

Orders Topic

Inventory Group

Email Group

Analytics Group

Shipping Group

Everyone gets copy.


Real Example

Customer Orders Mobile.

Order API

↓

Kafka Topic

↓

Payment

↓

Inventory

↓

Email

↓

SMS

↓

Analytics

↓

Recommendation Engine

Single Event

Many Consumers.


Queue vs Topic Comparison

QueueKafka Topic
One ConsumerMultiple Consumer Groups
Message RemovedMessage Retained
Point-to-PointPublish Subscribe
Low ScalabilityVery High
Low ThroughputMillions/sec

Message Flow

Customer

↓

Angular

↓

.NET API

↓

Kafka Producer

↓

Orders Topic

↓

Broker

↓

Partition

↓

Consumer Group

↓

Inventory Service

↓

SQL

↓

Notification

↓

Email

Kafka Storage

Many developers ask

Where does Kafka save messages?

Kafka stores messages

Inside

Topic

↓

Partition

↓

Log Files

Example

orders-0.log

orders-1.log

orders-2.log

Messages are appended.

Kafka never inserts in middle.

Only append.

Offset 0

Offset 1

Offset 2

Offset 3

Kafka Message Format

Example

Key

OrderId=1001

Value

{
OrderId:1001,
Customer:"John",
Amount:2500
}

Replication

Suppose

Broker1 crashes.

Without replication

Data Lost.

With replication

Broker1

Leader

↓

Broker2

Follower

↓

Broker3

Follower

If Leader dies

Follower becomes Leader.


Producer Acknowledgement

acks=0

Fire and Forget

Fastest

Risky


acks=1

Leader confirms.

Most common.


acks=all

All replicas confirm.

Safest.


Delivery Guarantee

At Most Once

No Retry

May Lose.


At Least Once

Retry Enabled

Duplicate Possible.


Exactly Once

No Duplicate

No Loss

Used for Banking.


Kafka Ordering

Ordering guaranteed only

within a partition.

Example

Partition0

Order1

Order2

Order3

Always maintained.

Across partitions

No guarantee.


Why Partitions?

Imagine

10 Million Orders.

One partition

Single Consumer

Slow.

10 partitions

10 Consumers

10x faster.


.NET Core Integration

Architecture

Angular

↓

.NET API

↓

Kafka Producer

↓

Kafka Broker

↓

Inventory Service

↓

SQL Server

Install Package

dotnet add package Confluent.Kafka

Producer Example

using Confluent.Kafka;

var config = new ProducerConfig
{
    BootstrapServers="localhost:9092"
};

using var producer =
new ProducerBuilder<string,string>(config)
.Build();

await producer.ProduceAsync(
"orders",
new Message<string,string>
{
    Key="1001",
    Value="{OrderId:1001}"
});

Producer sends

Topic

orders

Consumer Example

var config =
new ConsumerConfig
{
BootstrapServers="localhost:9092",
GroupId="inventory-group",
AutoOffsetReset=AutoOffsetReset.Earliest
};

using var consumer =
new ConsumerBuilder<string,string>(config)
.Build();

consumer.Subscribe("orders");

while(true)
{
var result=consumer.Consume();

Console.WriteLine(result.Message.Value);
}

ASP.NET Core Web API

Angular

POST

/api/orders

Controller

[HttpPost]
public async Task<IActionResult> Create(OrderDto order)
{
await producer.Publish(order);

return Ok();
}

Producer Service

await _producer.ProduceAsync(
"orders",
message);

Angular

Order Service

createOrder(order:any){

return this.http.post(
"/api/orders",
order);

}

Component

submit(){

this.orderService
.createOrder(this.order)
.subscribe();
}

Angular never talks directly to Kafka.

Reason

Kafka is backend infrastructure.

Angular

Web API

Kafka


Complete Flow

Angular

↓

Web API

↓

Kafka Producer

↓

Orders Topic

↓

Broker

↓

Partition

↓

Consumer Group

↓

Inventory Service

↓

Database

↓

Notification

↓

Email

Kafka vs RabbitMQ

KafkaRabbitMQ
Event StreamingMessage Queue
Huge ThroughputModerate
Log BasedQueue Based
Message RetentionMessage Deleted
Replay PossibleDifficult
AnalyticsTask Processing

Kafka in Microservices

Example

Customer Created

↓

customer-created topic

↓

Billing

↓

CRM

↓

Analytics

↓

Notification

↓

Search Index

No service depends on another.


Docker

version: '3'

services:

  kafka:

    image: bitnami/kafka

Run

docker compose up

Azure Integration

Kafka can integrate with

  • Azure Event Hubs (Kafka-compatible endpoint)

  • Azure Kubernetes Service (AKS)

  • Azure Container Apps

  • Azure Virtual Machines

  • Azure Monitor

  • Azure Key Vault (Secrets)

  • Azure DevOps (CI/CD)


Best Practices

  • Use meaningful topic names (e.g., orders.created.v1)

  • Keep events immutable.

  • Prefer Avro or Protobuf with a Schema Registry over raw JSON for large systems.

  • Use keys that preserve ordering (for example, OrderId).

  • Avoid very large messages; store large files externally and publish references.

  • Configure retry, idempotent producers, and dead-letter handling where appropriate.

  • Monitor consumer lag and broker health.

  • Plan partition counts based on expected throughput and consumer parallelism.


Common Interview Questions

  1. What is Apache Kafka?

  2. Explain Kafka architecture.

  3. What is a Broker?

  4. What is a Topic?

  5. What is a Partition?

  6. What is an Offset?

  7. Explain Consumer Groups.

  8. Difference between Queue and Topic.

  9. Kafka vs RabbitMQ.

  10. Why are partitions needed?

  11. How does Kafka guarantee ordering?

  12. What happens when a broker fails?

  13. What is replication factor?

  14. What are producer acknowledgements (acks)?

  15. What is consumer lag?

  16. What is idempotent producer?

  17. What is exactly-once processing?

  18. What is the role of Schema Registry?

  19. How do you scale Kafka consumers?

  20. How do you integrate Kafka with .NET Core?

Complete E-Commerce Example

                Angular UI
                     │
                     ▼
         ASP.NET Core Web API
                     │
                     ▼
            Kafka Producer Service
                     │
                     ▼
         ┌──────────────────────────┐
         │      Orders Topic         │
         └──────────────────────────┘
            │       │        │
            ▼       ▼        ▼
     Inventory   Payment   Analytics
       Service    Service     Service
            │       │        │
            ▼       ▼        ▼
      SQL Server  Email   Data Warehouse
                     │
                     ▼
              Notification Service

A customer clicks Place Order in Angular. The Angular app calls the ASP.NET Core API. The API validates the request, stores the order (if following the Outbox pattern), and publishes an OrderCreated event to Kafka. Kafka persists the event in the orders topic, making it available to multiple consumer groups. Inventory reserves stock, Payment charges the customer, Analytics records the event, and Notification sends an email—all independently and asynchronously.

This decoupled architecture improves scalability, resilience, and maintainability because producers and consumers evolve independently.

For a production-grade implementation, the next topics to master are:

  • Kafka internals (segments, ISR, leader election, page cache)

  • KRaft architecture (ZooKeeper-free Kafka)

  • Schema Registry with Avro/Protobuf

  • Outbox Pattern with .NET and Entity Framework Core

  • Saga Pattern with Kafka

  • Retry topics and Dead Letter Topics (DLT)

  • Idempotent consumers and exactly-once semantics

  • Monitoring with Prometheus and Grafana

  • Deploying Kafka on Docker, Kubernetes, and Azure

  • End-to-end .NET 9 microservices with Angular 20 and Kafka using Clean Architecture and CQRS

These advanced topics are commonly expected in senior .NET Lead and Technical Architect interviews.

Interview Questions And Answers :

Apache Kafka Interview Questions And Answers

Don't Copy

Protected by Copyscape Online Plagiarism Checker