Topics Kafka Topic 1: Kafka Fundamentals & Architecture
Back Sign up to track progress
Kafka

Topic 1: Kafka Fundamentals & Architecture

Sign up free to track your views & progress

TL;DR

Apache Kafka is a distributed event streaming platform that enables applications to publish, store, process, and consume large volumes of events in real time. It was designed to solve scalability, reliability, and integration challenges that traditional synchronous architectures struggle to handle. Kafka has become one of the most important technologies in modern microservices, event-driven architectures, real-time analytics platforms, and large-scale distributed systems.


Introduction

In modern enterprise environments, thousands of business events occur every second. Customers place orders, payments are processed, inventory changes, notifications are sent, user activities are recorded, and audit logs are generated. Every one of these actions creates information that other systems may need to consume.

Traditionally, applications communicated through direct API calls or database integrations. While this approach works for small systems, it becomes increasingly difficult to manage as organizations grow and introduce more services.

Apache Kafka was created to provide a scalable and reliable way for systems to exchange information through events rather than direct dependencies. Instead of one service directly calling another service, a service can publish an event to Kafka and allow interested systems to consume that event independently.

This simple idea fundamentally changed how modern distributed systems are designed.


Why Kafka Was Created

To understand Kafka, it is important to understand the problems that existed before Kafka.

Consider an e-commerce application.

When a customer places an order, multiple systems need to react:

  • Payment Service processes payment
  • Inventory Service reserves stock
  • Shipping Service prepares delivery
  • Notification Service sends email
  • Analytics Service records business metrics
  • Audit Service stores compliance records

In a traditional architecture, the Order Service might directly call each of these services.

Order Service → Payment Service

Order Service → Inventory Service

Order Service → Shipping Service

Order Service → Notification Service

Order Service → Analytics Service

This architecture creates several challenges.

Tight Coupling

The Order Service becomes dependent on all downstream services. Any change in one service can impact the Order Service.

Reduced Reliability

If the Notification Service is unavailable, the entire order flow may fail even though the notification is not business-critical.

Scalability Problems

As more services are added, the number of service-to-service integrations grows rapidly.

Difficult Maintenance

Understanding system dependencies becomes increasingly difficult as the organization grows.

Performance Bottlenecks

The Order Service must wait for multiple downstream responses before completing its own processing.

Kafka was designed to eliminate these challenges by introducing asynchronous communication.


Event-Driven Thinking

The most important concept in Kafka is the event.

An event represents something that happened in the system.

Examples include:

  • Order Created
  • Payment Completed
  • Product Added
  • User Registered
  • Ride Requested
  • Transaction Processed
  • Customer Updated

Instead of calling another service directly, applications publish events describing what happened.

This shifts the architecture from:

"Tell another service what to do"

to

"Publish what happened and allow interested systems to react."

This approach creates significantly more flexible systems.


What Exactly Is Kafka?

Apache Kafka is a distributed event streaming platform that acts as a central event backbone for an organization.

Applications publish events to Kafka.

Kafka stores those events durably.

Consumer applications read and process those events.

Conceptually:

Producer → Kafka → Consumer

However, Kafka is far more than a messaging system.

Kafka provides:

  • Event storage
  • Event distribution
  • Event replay
  • Fault tolerance
  • High availability
  • Horizontal scalability
  • Stream processing capabilities

This is why Kafka is often described as a distributed commit log rather than a traditional message queue.


Kafka Architecture at a High Level

At a high level, Kafka consists of four major components.

Producers

Producers are applications that publish events into Kafka.

Examples:

  • Order Service
  • Payment Service
  • Mobile Application
  • Website Backend

A producer creates data and sends it to Kafka.

Kafka Cluster

The Kafka cluster is responsible for storing and managing events.

A cluster contains one or more Kafka servers called brokers.

The cluster ensures durability, replication, and fault tolerance.

Topics

Topics are logical categories where events are stored.

Examples:

  • order-events
  • payment-events
  • inventory-events
  • user-events

A topic acts like a stream of related events.

Consumers

Consumers are applications that read events from Kafka.

Examples:

  • Notification Service
  • Analytics Service
  • Fraud Detection System
  • Recommendation Engine

Consumers process events independently without affecting producers.


How Kafka Changes System Design

Without Kafka:

Order Service directly depends on Payment Service, Inventory Service, Notification Service, Shipping Service, and Analytics Service.

With Kafka:

Order Service publishes an OrderCreated event.

Interested systems subscribe to that event and process it independently.

The Order Service no longer needs to know:

  • Which consumers exist
  • How many consumers exist
  • Whether consumers are available
  • How consumers process data

This dramatically reduces system complexity.


Kafka became popular because it solves several enterprise-scale problems exceptionally well.

High Throughput

Kafka can process millions of messages per second with proper infrastructure.

This makes it suitable for:

  • Financial systems
  • E-commerce platforms
  • Telecommunication systems
  • IoT platforms
  • Social media platforms

Durability

Messages are persisted to disk.

A server restart does not cause message loss.

Scalability

Kafka scales horizontally by adding brokers.

Organizations can grow from a few thousand events per day to millions of events per second without redesigning their architecture.

Fault Tolerance

Kafka replicates data across multiple brokers.

If a broker fails, data remains available through replicas.

Event Replay

One of Kafka's most powerful capabilities is replayability.

Consumers can re-read historical events.

For example, if a bug existed in an Analytics Service, developers can fix the bug and replay past events rather than losing historical data.

Traditional messaging systems often cannot provide this capability efficiently.


Real-World Use Cases

E-Commerce

When an order is placed, Kafka distributes the event to:

  • Payment Processing
  • Inventory Management
  • Shipping
  • Notifications
  • Analytics

Banking

Every financial transaction generates events consumed by:

  • Fraud Detection Systems
  • Compliance Systems
  • Audit Systems
  • Reporting Platforms

Ride Sharing Applications

A ride request event may trigger:

  • Driver Matching
  • Pricing Engine
  • Notifications
  • Analytics

Social Media Platforms

User actions generate events processed by:

  • Recommendation Systems
  • Analytics Platforms
  • Notification Systems
  • Advertising Engines

Kafka and Microservices

Microservices and Kafka complement each other extremely well.

REST APIs provide synchronous communication.

Kafka provides asynchronous communication.

REST is useful when an immediate response is required.

For example:

Customer requests account balance.

The application must return the balance immediately.

Kafka is useful when an action needs to trigger multiple downstream processes.

For example:

Customer places an order.

Multiple services must react independently.

Modern enterprise architectures typically use both REST and Kafka together rather than choosing one over the other.


Production Support Perspective

In production environments, Kafka introduces new operational responsibilities.

Common issues include:

Consumer Lag

Consumers process events slower than producers generate them.

Broker Failure

A Kafka server becomes unavailable.

Rebalancing Problems

Consumer groups continuously redistribute partitions, impacting performance.

Message Duplication

Events may be processed multiple times.

Disk Space Issues

Large event retention can consume storage rapidly.

Throughput Bottlenecks

Traffic growth can overwhelm existing infrastructure.

Understanding Kafka architecture is essential before troubleshooting these problems.


Common Misconceptions

Kafka Is Just a Message Queue

Kafka can behave like a message queue, but it is fundamentally an event streaming platform with durable storage and replay capabilities.

Kafka Replaces Databases

Kafka stores events.

Databases store business state.

Both serve different purposes.

Kafka Guarantees Exactly Once by Default

Exactly-once processing requires specific configurations and application design.

It is not automatically guaranteed.

Kafka Eliminates REST APIs

Kafka complements REST APIs.

Most enterprise systems use both technologies together.


Best Practices

  • Design systems around business events.
  • Avoid excessive topic creation.
  • Plan partitioning strategies carefully.
  • Treat Kafka as a shared enterprise platform.
  • Monitor consumer lag continuously.
  • Design consumers to be idempotent.
  • Implement proper retention policies.
  • Use schema management for message evolution.

Interview Questions

What is Apache Kafka?

Apache Kafka is a distributed event streaming platform used for publishing, storing, processing, and consuming real-time event data at scale.

Why was Kafka created?

Kafka was created to solve scalability, reliability, and integration challenges in large distributed systems.

What is an event?

An event is a record representing something that happened in a system.

Why is Kafka important in microservices?

Kafka enables asynchronous communication and reduces service coupling.

What makes Kafka fault tolerant?

Kafka replicates data across multiple brokers, allowing the system to continue functioning even when individual brokers fail.

Why is Kafka called a distributed commit log?

Because events are stored sequentially and durably, allowing consumers to read them in order and replay historical events.


Revision Notes

Apache Kafka is a distributed event streaming platform designed for high-throughput, scalable, fault-tolerant data processing. It solves the limitations of tightly coupled architectures by enabling asynchronous communication through events. Producers publish events, Kafka stores them durably, and consumers process them independently. Kafka provides scalability, durability, replayability, and fault tolerance, making it one of the foundational technologies behind modern microservices, real-time analytics, and event-driven architectures.


Next Topic: Kafka Core Building Blocks (Broker, Topic, Partition, Offset, Producer, Consumer, Consumer Group, and Kafka Cluster) — the most important foundational topic in Kafka.

Apache Kafka

Done reading this topic? Sign up free to track your progress.
Sign Up to Track