Getting Started with Apache Kafka: What I Learned Building Event-Driven Microservices at Ericsson
<p>When I first heard the word <em>"Kafka"</em> in a technical meeting at Ericsson, I nodded confidently while quietly Googling it under the table. A few months later, I was designing Avro schemas, building consumer groups, and debugging lag metrics in production.</p> <p>This is everything I wish someone had told me when I started.</p> <h2> 🎯 What Is Apache Kafka ? </h2> <p>Imagine a post office. Instead of letters, services send <strong>events</strong> things that happened, like <em>"user logged in"</em> or <em>"notification dispatched"</em>. Instead of delivering directly to recipients, every event goes into a <strong>central post box (Kafka)</strong>. Any service that cares about that event can pick it up whenever it's ready.</p> <p>This is event-driven architecture. And Kafka is the m
When I first heard the word "Kafka" in a technical meeting at Ericsson, I nodded confidently while quietly Googling it under the table. A few months later, I was designing Avro schemas, building consumer groups, and debugging lag metrics in production.
This is everything I wish someone had told me when I started.
🎯 What Is Apache Kafka ?
Imagine a post office. Instead of letters, services send events things that happened, like "user logged in" or "notification dispatched". Instead of delivering directly to recipients, every event goes into a central post box (Kafka). Any service that cares about that event can pick it up whenever it's ready.
This is event-driven architecture. And Kafka is the most battle-tested way to build it.
The technical version: Apache Kafka is a distributed event streaming platform that lets you:
-
Publish events from producer services
-
Store events reliably and durably
-
Subscribe to events from consumer services
-
Process streams of events in real time
At Ericsson, every customer notification: SMS, push, email, in-app is flown through a Kafka-based pipeline. Getting this right was critical. Getting it wrong meant missed messages at scale.
🏗️ Core Concepts You Must Understand
Topics
A topic is a named category for events. Think of it like a database table, but append-only.
Enter fullscreen mode
Exit fullscreen mode
Producers
A producer is any service that writes events to a topic.
private final KafkaTemplate kafkaTemplate; private static final String TOPIC = "notification-events";
public NotificationProducer(KafkaTemplate kafkaTemplate) { this.kafkaTemplate = kafkaTemplate; }
public void sendNotification(NotificationEvent event) { kafkaTemplate.send(TOPIC, event.getUserId(), event); log.info("Notification event sent for userId: {}", event.getUserId()); } }`
Enter fullscreen mode
Exit fullscreen mode
Consumers
A consumer is any service that reads events from a topic.
private final NotificationProcessor processor;
@KafkaListener(topics = "notification-events", groupId = "notification-service") public void consume(ConsumerRecord record) { log.info("Received event for userId: {}", record.key()); processor.process(record.value()); } }`
Enter fullscreen mode
Exit fullscreen mode
Consumer Groups
Multiple consumers can form a group to share the work of processing events. Kafka automatically distributes partitions across group members, this is how you scale horizontally.
Enter fullscreen mode
Exit fullscreen mode
Partitions
Topics are split into partitions, this is what enables parallelism. Events with the same key always go to the same partition, preserving order.
Enter fullscreen mode
Exit fullscreen mode
📦 Avro Schemas — Why They Matter
Raw JSON Kafka messages are flexible but dangerous at scale. One typo in a field name can break every downstream consumer silently.
Avro schemas solve this by defining the exact structure of every message, enforced at the Schema Registry level before a message is even sent.
Define your schema (notification-event.avsc):
Enter fullscreen mode
Exit fullscreen mode
⚡ Setting Up Kafka Locally
The fastest way to run Kafka locally for development:
docker-compose.yml:
version: '3.8'
Enter fullscreen mode
Exit fullscreen mode
Start everything:
docker-compose up -d
Enter fullscreen mode
Exit fullscreen mode
Verify Kafka is running:
docker ps
You should see zookeeper, kafka, and schema-registry all running`
Enter fullscreen mode
Exit fullscreen mode
🔍 Monitoring Kafka Lag
Consumer lag is the number of unprocessed messages sitting in a partition. High lag = your consumers are falling behind.
At Ericsson we monitored this constantly.
Output:
Enter fullscreen mode
Exit fullscreen mode
Partition 1 has a lag of 5 minor, but worth watching. If lag grows consistently, you need more consumer instances.
Add a second consumer instance by simply running another instance of your service, Kafka automatically rebalances partitions across the group.
🐛 Common Mistakes I Made (So You Don't Have To)
1. Not setting a partition key
// ✅ Correct — keyed by userId, preserves order per user kafkaTemplate.send(TOPIC, event.getUserId(), event);`
Enter fullscreen mode
Exit fullscreen mode
2. Creating ObjectMapper inside the consumer loop
// ✅ Correct — inject as Spring Bean @Autowired private ObjectMapper mapper;`
Enter fullscreen mode
Exit fullscreen mode
3. Not handling deserialization errors
Enter fullscreen mode
Exit fullscreen mode
4. Forgetting idempotency
Kafka guarantees at least once delivery, your consumer may receive the same message twice. Always make processing idempotent:
Enter fullscreen mode
Exit fullscreen mode
📊 What I Learned in Production
After months of running Kafka in production at Ericsson:
Lesson Detail
Partition key matters Always key by the entity that needs ordering (userId, orderId)
Monitor lag daily Lag growth is an early warning sign
Dead letter queues Always have a DLQ for failed messages
Schema evolution Add fields as nullable with defaults — never remove fields
Consumer group naming
Use descriptive group IDs — notification-service not group1
Replication factor Always 3 in production for fault tolerance
🚀 Getting Started Checklist
If you're setting up Kafka for the first time:
-
Run Kafka locally with Docker Compose (see above)
-
Create your first topic
-
Write a simple producer in Spring Boot
-
Write a simple consumer with @KafkaListener
-
Define an Avro schema for your messages
-
Add error handling and a dead letter queue
-
Monitor consumer lag
-
Test with multiple consumer instances
🔮 What's Next
Kafka is one of those technologies where the basics are approachable but the depth is enormous. Once you're comfortable with the fundamentals, explore:
-
Kafka Streams — real-time stream processing
-
KSQL — SQL-like queries over Kafka streams
-
Exactly-once semantics — guaranteeing no duplicates
-
Kafka Connect — integrating Kafka with databases and external systems
The investment in learning Kafka properly pays dividends across your entire engineering career. Event-driven architecture is how modern distributed systems are built and Kafka is at the center of it.
Thanks for reading! I'm Zaina, a Software Engineer based in Perth, Australia, working with Java microservices, Apache Kafka, and cloud-native technologies at Ericsson. Connect with me on LinkedIn or check out my portfolio.
Found this useful? Drop a ❤️ and share it with a fellow engineer who's just getting started with Kafka!
Sign in to highlight and annotate this article

Conversation starters
Daily AI Digest
Get the top 5 AI stories delivered to your inbox every morning.
More about
versionproductplatformImplementing Zero Trust Architecture for Unmanaged IoT at the Network Edge
<h2> Why Unmanaged IoT Is the Weakest Link in Your Network </h2> <p>The proliferation of Internet of Things (IoT) devices across enterprise environments has created a security paradox. Organizations deploy thousands of connected devices—IP cameras, building automation controllers, medical equipment, industrial sensors, point-of-sale terminals—to drive operational efficiency. Yet the vast majority of these devices are <strong>unmanaged</strong>: they cannot run endpoint agents, accept security patches on schedule, or participate in traditional identity frameworks. According to industry estimates, over 75% of IoT devices in production environments operate without any form of endpoint security.</p> <p>This creates a massive blind spot. Traditional perimeter-based security assumes that everyth
Transforming Raspberry Pi into an AI-Native Edge IDS for SMBs
<h2> The SMB Security Gap: Why the Edge Matters </h2> <p>Small and Medium Businesses (SMBs) are frequently described as the "soft underbelly" of the global supply chain. While large enterprises invest millions in centralized Security Operations Centers (SOCs) and high-end hardware, SMBs often operate with lean IT teams and limited budgets. However, the threats they face—ranging from sophisticated ransomware-as-a-service to targeted lateral movement—are just as potent. The traditional approach of backhauling all traffic to a central firewall is increasingly obsolete in a world of distributed work and IoT expansion. This is where <strong>how to set up IDS on raspberry pi</strong> becomes a critical question for cost-conscious security engineers.</p> <p>In the contemporary digital ecosystem,
Implementing Zero Trust Architecture in IoT-Heavy Enterprise Networks
<h2> The Paradigm Shift: From Castle-and-Moat to Zero Trust Edge </h2> <p>For decades, the standard for enterprise security was the "castle-and-moat" model. This architectural philosophy assumed that anything inside the network perimeter was inherently trustworthy, while everything outside was potentially malicious. However, the explosion of the Internet of Things (IoT) and the decentralization of the workforce have rendered this model obsolete. In a modern enterprise environment, the perimeter has dissolved. Today, a smart thermostat, an industrial PLC (Programmable Logic Controller), or a VoIP phone acts as a potential gateway for sophisticated adversaries. To secure these environments, organizations must transition to <strong>Zero Trust Architecture (ZTA)</strong>.</p> <p>As defined by
Knowledge Map
Connected Articles — Knowledge Graph
This article is connected to other articles through shared AI topics and tags.
More in Products
Implementing Zero Trust Architecture in IoT-Heavy Enterprise Networks
<h2> The Paradigm Shift: From Castle-and-Moat to Zero Trust Edge </h2> <p>For decades, the standard for enterprise security was the "castle-and-moat" model. This architectural philosophy assumed that anything inside the network perimeter was inherently trustworthy, while everything outside was potentially malicious. However, the explosion of the Internet of Things (IoT) and the decentralization of the workforce have rendered this model obsolete. In a modern enterprise environment, the perimeter has dissolved. Today, a smart thermostat, an industrial PLC (Programmable Logic Controller), or a VoIP phone acts as a potential gateway for sophisticated adversaries. To secure these environments, organizations must transition to <strong>Zero Trust Architecture (ZTA)</strong>.</p> <p>As defined by
Buffer Overflows on x64 Windows: A Practical Beginners Guide (Part 2): Exploitation
<h2> Introduction </h2> <p>Welcome back. Mirrai here. In part 1 we covered the theory. The stack, RIP, and what a buffer overflow actually is. Now we get our hands dirty. By the end of this guide you should have a working exploit that gives you control of RIP and redirects execution to your own code.<br> Before we start, make sure you have x64dbg and pwntools installed from part 1. You'll also need the vulnerable program we wrote. If you haven't read part 1, go do that first. Buckle up, this might take a while.</p> <p>For your convenience, here's the old vuln program code<br> </p> <div class="highlight js-code-highlight"> <pre class="highlight c"><code><span class="cp">#include</span> <span class="cpf"><stdio.h></span><span class="cp"> #include</span> <span class="cpf"><windows.h></span><s
DeepSource for Python: Static Analysis and Autofix
<p><strong>DeepSource provides one of the most thorough Python static analysis experiences available in 2026.</strong> Its Python analyzer covers over 150 rules across bug detection, security scanning, performance optimization, and code style enforcement - with a sub-5% false positive rate that keeps findings actionable rather than noisy. Combined with Autofix, which generates ready-to-apply code changes for detected issues, DeepSource turns Python static analysis from a reporting exercise into an automated remediation workflow.</p> <p>This guide covers everything you need to set up DeepSource for Python projects - from the initial <code>.deepsource.toml</code> configuration to advanced features like type checking integration, Django and Flask security rules, and coverage reporting with py
How I built an AI that reads bank contracts the way bankers do (not the way customers do)
<h1> How I built an AI that reads bank contracts the way bankers do (not the way customers do) </h1> <p>The problem started in 2009. I was a banker. I watched loan officers use internal scoring grids that customers never saw. The information asymmetry wasn't illegal — it was just never shared.</p> <p>Fifteen years later, the asymmetry got worse. Banks now run LLMs on customer data before any human reviews it. The customer still signs without understanding what they're signing.</p> <p>So I built the reverse.</p> <h2> The core insight: bankers read contracts differently than customers </h2> <p>A customer reads a loan contract linearly — page by page, looking for the monthly payment.</p> <p>A banker reads it dimensionally — simultaneously scanning for:</p> <ul> <li> <strong>Covenant triggers<
Discussion
Sign in to join the discussion
No comments yet — be the first to share your thoughts!