0
0
Kafkadevops~3 mins

Why Subscribing to topics in Kafka? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could get all updates automatically the moment they happen, without lifting a finger?

The Scenario

Imagine you want to get updates from many different news channels by calling each one separately every minute to ask if there is new news.

The Problem

This manual checking is slow, wastes time, and you might miss important news if you check too late. Also, it's easy to make mistakes by forgetting to check some channels or mixing up the news.

The Solution

Subscribing to topics means you tell the system which news channels you want to follow, and it automatically sends you updates as soon as they happen. You don't have to keep asking; the updates come to you instantly and reliably.

Before vs After
Before
while True:
    for channel in channels:
        news = check_news(channel)
        if news:
            print(news)
    sleep(60)
After
consumer.subscribe(['news_channel'])
for message in consumer:
    print(message.value)
What It Enables

It enables real-time, efficient, and reliable data flow without constant manual checking.

Real Life Example

A stock trading app subscribes to stock price updates and instantly shows you changes without you refreshing or asking repeatedly.

Key Takeaways

Manual checking is slow and error-prone.

Subscribing automates receiving updates instantly.

This makes programs faster, simpler, and more reliable.