<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Vishal C. Chaliya</title>
    <description>The latest articles on Forem by Vishal C. Chaliya (@crvishal).</description>
    <link>https://forem.com/crvishal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3765922%2F8d9e9766-78e0-444e-9530-552dc0e41e90.jpg</url>
      <title>Forem: Vishal C. Chaliya</title>
      <link>https://forem.com/crvishal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/crvishal"/>
    <language>en</language>
    <item>
      <title>Mastering the Saga Microservice Pattern in Event-Driven Systems</title>
      <dc:creator>Vishal C. Chaliya</dc:creator>
      <pubDate>Sat, 02 May 2026 06:47:33 +0000</pubDate>
      <link>https://forem.com/crvishal/mastering-the-saga-microservice-pattern-in-event-driven-systems-2h5j</link>
      <guid>https://forem.com/crvishal/mastering-the-saga-microservice-pattern-in-event-driven-systems-2h5j</guid>
      <description>&lt;p&gt;When you send money overseas to a friend or a family member you just tap and the money is sent, it feels instantaneous, but behind the scenes, a complex dance of microservices ensures that the transaction is a success. Let's explore a common scenario in a cross-border transaction and see how different microservices coordinate this intricate process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Cross-Border Payment Journey&lt;/strong&gt;&lt;br&gt;
Inside a financial institution say a bank or currency exchange partner, a series of specialized microservices comes alive when you initiate a transfer. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
A Payment Gateway acknowledges your request, passing it to the Currency Conversion service, which determines the optimal exchange rate. Following conversion, the transaction must adhere to the Compliance service to meet international regulations and pass through Fraud Detection to ensure legitimacy. Finally, the Payment Execution service processes the transaction, with a Notification service confirming the transfer to your friend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Complexity of Distributed Systems&lt;/strong&gt;&lt;br&gt;
In the above flow what if the Fraud Detection flags the transaction or the Currency Conversion fails? In a monolithic system, rolling back is straightforward, but the distributed architecture complicates things. This is where the saga pattern can save your life, coordinating the services without a central controller, much like a flock of birds flying in formation" or "emergency responders reacting to a radio call(all playing their part independently).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Saga Pattern&lt;/strong&gt;&lt;br&gt;
The saga pattern manages distributed transactions by allowing each microservice to execute its part of the process independently and react to failures with compensation logic. Each service performs local transactions and is responsible for its "oops, let's fix that" plan, ensuring system stability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Cross-Border Payment: The Saga Approach&lt;/strong&gt;&lt;br&gt;
In a distributed Saga, the "perfect" flow is broken into a chain of independent local transactions. Instead of one giant lock, each service commits its own work immediately and then shouts to the next service: "I’m done, your turn!"&lt;/p&gt;

&lt;p&gt;&lt;em&gt;How it works: Choreography&lt;/em&gt;&lt;br&gt;
In our payment journey, the Currency Conversion service doesn't wait for permission. It locks in the exchange rate, updates its own database, and emits a RateConverted event. The Compliance service, which has been "listening" for that specific event, wakes up and begins its check.&lt;/p&gt;

&lt;p&gt;This creates a Choreography: a decentralized dance where no single "boss" directs the flow. Like a jazz ensemble, each microservice knows the "rhythm" (the sequence of events) and improvises its part when it hears the right cue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The "Safety Net": Compensating Transactions&lt;/strong&gt;&lt;br&gt;
The true power of a Saga is how it handles failure. If the Fraud Detection service flags the transfer as suspicious, it emits a FraudDetected event. Because there is no "Undo" button in a distributed system, the previous services must execute compensating transactions&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For Example&lt;br&gt;
Currency Conversion sees the fraud event and automatically executes a reversal to release the held funds at the original rate.&lt;/p&gt;

&lt;p&gt;Payment Gateway receives the failure and updates your dashboard to "Rejected," triggering a refund if necessary.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Real-World Challenges&lt;/strong&gt;&lt;br&gt;
While the saga sounds good but Implementing sagas in production introduces challenges. Debugging distributed systems can be complex, akin to piecing together a mystery novel with scattered pages. Ensuring smooth scaling, managing event broker loads like Kafka, and maintaining idempotency are critical considerations. Because there is no central log, you must rely on Distributed Tracing to follow a single transaction across five different services.&lt;/p&gt;

&lt;p&gt;Furthermore, developers must ensure Idempotency—the guarantee that if a service receives the same "Failure" event twice, it doesn't accidentally execute the compensation twice. Managing the load on event brokers like Kafka and handling "out-of-order" events are the technical taxes you pay for such high resilience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Embracing a New Perspective&lt;/strong&gt;&lt;br&gt;
The saga pattern is not about avoiding failures but embracing them and designing for graceful recovery. This approach shifts focus from preventing errors to effectively managing them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trade-Offs and Decisions&lt;/strong&gt;&lt;br&gt;
Is the saga pattern always the best choice? Not necessarily. For applications needing real-time responses or where compensating actions are intricate, sagas might add unwarranted complexity. Eventual consistency is a trade-off, and if your business can't accept it, sagas might not be suitable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion: Crafting a Harmonious System&lt;/strong&gt;&lt;br&gt;
The saga microservice pattern acts as a safety net for distributed systems, allowing each service to function independently while preserving overall process integrity. It's not a panacea, but when applied judiciously, it turns a chaotic orchestra into a harmonious symphony. Next time you send money globally, remember the saga pattern ensuring smooth operations. For engineers, embracing this complexity is part of the adventure.&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>eventdriven</category>
      <category>systemdesign</category>
      <category>designpatterns</category>
    </item>
    <item>
      <title>When do companies actually adopt Kafka / event-driven architecture?</title>
      <dc:creator>Vishal C. Chaliya</dc:creator>
      <pubDate>Sat, 28 Feb 2026 17:04:19 +0000</pubDate>
      <link>https://forem.com/crvishal/when-do-companies-actually-adopt-kafka-event-driven-architecture-56lf</link>
      <guid>https://forem.com/crvishal/when-do-companies-actually-adopt-kafka-event-driven-architecture-56lf</guid>
      <description>&lt;p&gt;I’ve been spending a lot time learning more about Kafka, streaming systems, CDC, and event-driven architecture.&lt;/p&gt;

&lt;p&gt;It’s really very interesting — but I’m trying to figure out whether this specialization actually makes sense as a service offering.&lt;/p&gt;

&lt;p&gt;At what point does a team say, “Okay, we need Kafka now”?&lt;/p&gt;

&lt;p&gt;From what I’ve seen, in early-stage startups usually try to keep things simple(no cdc, no kafka, no microservices). &lt;br&gt;
On the other hand, larger companies often already have dedicated teams and established infrastructure.&lt;br&gt;
So I am curious like do someone actually hires a kafka specialist or they just hire full time employee.&lt;br&gt;
If you’ve worked at a company that adopted Kafka or event-driven systems:&lt;br&gt;
What triggered it?&lt;br&gt;
Was it traffic growth?&lt;br&gt;
Microservices getting messy?&lt;br&gt;
Data consistency issues?&lt;br&gt;
Analytics or integration needs?&lt;br&gt;
Something breaking in production?&lt;/p&gt;

&lt;p&gt;And when that complexity showed up, how did your team handle it?&lt;br&gt;
Did you grow the expertise internally?&lt;br&gt;
Hire someone specifically for it?&lt;br&gt;
Bring in outside help?&lt;br&gt;
Or just let backend engineers figure it out over time?&lt;/p&gt;

&lt;p&gt;I’m not asking whether specialization helps land a job — I understand that it can.&lt;br&gt;
I’m asking whether, from a business standpoint, there’s a sustainable niche for independent specialists in streaming architecture. Or is this almost always something companies internalize once they’re big enough?&lt;/p&gt;

&lt;p&gt;I will really appreciate any insight on this topic.&lt;br&gt;
Thank you in advance.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>What is the Outbox Pattern? Solving a Nightmare</title>
      <dc:creator>Vishal C. Chaliya</dc:creator>
      <pubDate>Tue, 24 Feb 2026 10:46:49 +0000</pubDate>
      <link>https://forem.com/crvishal/what-is-the-outbox-pattern-solving-a-nightmare-93b</link>
      <guid>https://forem.com/crvishal/what-is-the-outbox-pattern-solving-a-nightmare-93b</guid>
      <description>&lt;p&gt;Before we define it, let’s understand the nightmare it was designed to solve:&lt;br&gt;
&lt;strong&gt;Why does this design pattern exist in the first place?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s take a simple example.&lt;/p&gt;

&lt;p&gt;Suppose you’re in the mood to watch a movie and relax.&lt;br&gt;
You’ve got your popcorn, your comfy sofa, and Netflix open.&lt;/p&gt;

&lt;p&gt;You log in. Netflix already recommends movies based on your watch history.&lt;br&gt;
You select one, press “Watch Now,” and the movie starts streaming.&lt;/p&gt;

&lt;p&gt;That’s the ideal scenario.&lt;/p&gt;

&lt;p&gt;But behind that smooth experience, what is actually happening?&lt;/p&gt;

&lt;p&gt;Imagine You’re Designing This System&lt;/p&gt;

&lt;p&gt;You are responsible for two critical operations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save the selected movie in the database 
(Very important — so Netflix can improve recommendations using behavioral data.)&lt;/li&gt;
&lt;li&gt;Notify another service to start streaming the movie
(By emitting an event like MovieStarted.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Seems simple.&lt;/p&gt;

&lt;p&gt;But here’s where distributed systems start laughing at you.&lt;/p&gt;

&lt;p&gt;The Real Problem&lt;/p&gt;

&lt;p&gt;What if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The database save succeeds&lt;/li&gt;
&lt;li&gt;But the event emission fails?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Or worse:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The event is emitted&lt;/li&gt;
&lt;li&gt;But the database transaction fails?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now your system is inconsistent.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The recommendation service thinks the user watched the movie.&lt;br&gt;
  The streaming service thinks nothing happened.&lt;br&gt;
  Or the opposite.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is called the &lt;strong&gt;Dual Write Problem(the nightmare we need to solve)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You are writing to two different systems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A relational database (ACID guarantees — atomicity, consistency, durability)&lt;/li&gt;
&lt;li&gt;A message broker (asynchronous, eventually consistent)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And there is no single atomic transaction spanning both.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No shared commit boundary.&lt;/li&gt;
&lt;li&gt;No guaranteed consistency.&lt;/li&gt;
&lt;li&gt;No safety.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enter the &lt;strong&gt;Transactional Outbox Pattern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The idea is simple but powerful.&lt;/p&gt;

&lt;p&gt;Instead of:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Save to DB → Emit event to broker&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You do:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Save business data&lt;br&gt;
→ Insert event into OUTBOX table&lt;br&gt;
→ Commit transaction&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Both operations succeed or both fail.&lt;/p&gt;

&lt;p&gt;Now both operations happen inside the same database transaction.&lt;/p&gt;

&lt;p&gt;If the commit fails → nothing is persisted.&lt;br&gt;
If it commits → both the state change and the event record are durable.&lt;/p&gt;

&lt;p&gt;This solves the atomicity problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ok, so now two tables have the required data — what changed?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The change is that the event is no longer sent directly to Kafka.&lt;br&gt;
Instead:&lt;/p&gt;

&lt;p&gt;You can now poll the outbox table, read the unprocessed events, emit them to the message broker, and then mark them as processed.&lt;/p&gt;

&lt;p&gt;Or you can use CDC (Change Data Capture) on the outbox table so that it directly captures database changes (from WAL/binlog) and emits them to the message broker automatically.&lt;/p&gt;

&lt;p&gt;Or you can even introduce an entirely separate service dedicated to handling this responsibility.&lt;/p&gt;

&lt;p&gt;We removed distributed transactions (2PC) and still preserved atomicity between state change and event creation.&lt;/p&gt;

&lt;p&gt;So You Solved the Problem and Saved Your Job… But What If?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The event is published, the broker acknowledges it, but the application crashes before marking the event as processed. After restart → the event is published again.
Now you have duplicates.&lt;/li&gt;
&lt;li&gt;In a horizontally scaled system, multiple instances poll the same outbox table and the same event is picked more than once.&lt;/li&gt;
&lt;li&gt;The DB transaction commits, the event is emitted, but the broker crashes before persisting it. 
Or a network timeout occurs and you don’t know whether the publish succeeded.You retry — and create duplicates.&lt;/li&gt;
&lt;li&gt;You have a high-throughput system and polling the outbox table increases database load, creates lag, and eventually becomes a bottleneck.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For these reasons, you should never rely on the Outbox implementation alone.&lt;/p&gt;

&lt;p&gt;Outbox guarantees atomicity — not delivery perfection.&lt;/p&gt;

&lt;p&gt;You must design your consumers to handle failure scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Consumers should be idempotent&lt;/li&gt;
&lt;li&gt;    Use idempotency keys&lt;/li&gt;
&lt;li&gt;    Partition by aggregate ID to preserve ordering&lt;/li&gt;
&lt;li&gt;    Handle duplicate messages safely&lt;/li&gt;
&lt;li&gt;    Use deduplication tables if required&lt;/li&gt;
&lt;li&gt;    For high DB load, prefer CDC tools like Debezium over polling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I’m Trying to Say Is&lt;/strong&gt;:&lt;br&gt;
The Outbox Pattern is not a one-stop solution.&lt;br&gt;
Many engineers assume it solves broker reliability.&lt;/p&gt;

&lt;p&gt;It does not.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Outbox Pattern does not solve reliability of the broker.&lt;br&gt;
It only guarantees atomicity between state change and event creation.&lt;br&gt;
It guarantees at-least-once delivery, not exactly-once.&lt;br&gt;
If you want to keep your job as a system designer, you must design around its weaknesses — not ignore them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that you understand the Outbox Pattern properly, let’s look at some examples on when and where it should be used — and where it should not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When To Use the Outbox Pattern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✅ 1. Database is the Source of Truth&lt;/p&gt;

&lt;p&gt;Example: Order Management System&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order saved in PostgreSQL
OrderCreated event must be emitted
Losing that event breaks inventory and billing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Strong consistency is required → Outbox is ideal.&lt;/p&gt;

&lt;p&gt;✅ 2. Financial or Healthcare Systems&lt;/p&gt;

&lt;p&gt;Example: Payment Processing&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Transaction written to DB
Event triggers ledger updates, fraud checks, notifications
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Losing the event = financial inconsistency.&lt;/p&gt;

&lt;p&gt;Outbox ensures atomicity between transaction and event creation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When NOT To Use the Outbox Pattern&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❌ 1. When the Event Log Is the Source of Truth&lt;/p&gt;

&lt;p&gt;Example: An Event Sourcing system built around Kafka&lt;/p&gt;

&lt;p&gt;In this architecture:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;All state changes are written directly to Kafka first.
The database is just a projection (materialized view).
The event log is the system of record.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here, writing to the database first and then using an outbox adds unnecessary complexity.&lt;/p&gt;

&lt;p&gt;You should publish to Kafka as the primary write operation and build state from events.&lt;/p&gt;

&lt;p&gt;Outbox is not needed.&lt;/p&gt;

&lt;p&gt;❌ 2. Ultra High Throughput Streaming Systems&lt;/p&gt;

&lt;p&gt;Example: Real-time clickstream analytics or ad impression tracking&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Millions of events per second
Events are transient and not tightly coupled to transactional DB state
Occasional event loss may be acceptable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In such systems, polling a relational database becomes a bottleneck:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Heavy I/O
Lock contention
Index scans
Increased latency
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;It is better to:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Write directly to Kafka
Use stream processing (Kafka Streams / Flink)
Materialize views downstream
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;❌ 3. When Eventual Consistency Is Acceptable&lt;/p&gt;

&lt;p&gt;Example: Tracking “user viewed product” for analytics&lt;/p&gt;

&lt;p&gt;If one tracking event is lost:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;It does not break core business logic
No financial or critical data is affected
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Using Outbox here adds operational overhead without strong benefit.&lt;/p&gt;

&lt;p&gt;❌ 4. When You Don’t Control the Database&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Using a third-party SaaS database
No ability to create tables
No transaction control
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Since Outbox relies on atomic database transactions, it cannot be properly implemented.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Closing Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Outbox Pattern is not about Kafka, polling, or CDC.&lt;br&gt;
It is about solving the dual write problem in a practical way.&lt;/p&gt;

&lt;p&gt;It guarantees &lt;strong&gt;atomicity between state change and event creation&lt;/strong&gt; —&lt;br&gt;
but it does not guarantee broker reliability or exactly-once delivery.&lt;/p&gt;

&lt;p&gt;The mistake many engineers make is believing a pattern solves the entire problem.&lt;/p&gt;

&lt;p&gt;It doesn’t.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Outbox is a powerful tool — but real reliability comes from designing for failure, not assuming it won’t happen.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you’re exploring event-driven architectures further, I’ve also written about &lt;a href="https://dev.to/crvishal/what-are-kafka-streams-and-why-should-you-care-about-them-2d80"&gt;Kafka Streams and why it matters in real-world systems:&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>eventdriven</category>
      <category>designpatterns</category>
      <category>pubsub</category>
    </item>
    <item>
      <title>What Are Kafka Streams and Why Should You Care About Them?</title>
      <dc:creator>Vishal C. Chaliya</dc:creator>
      <pubDate>Wed, 11 Feb 2026 09:28:32 +0000</pubDate>
      <link>https://forem.com/crvishal/what-are-kafka-streams-and-why-should-you-care-about-them-2d80</link>
      <guid>https://forem.com/crvishal/what-are-kafka-streams-and-why-should-you-care-about-them-2d80</guid>
      <description>&lt;p&gt;Have you ever wondered how streaming giants like &lt;strong&gt;YouTube, Netflix&lt;/strong&gt; or &lt;strong&gt;Amazon Prime&lt;/strong&gt; suggest content from the same creators you’re currently watching, recommend similar videos, or even pitch specific products in real-time?&lt;br&gt;
We know this as targeted marketing, driven by your watch history, genres, and preferred content length. To a business, this data is pure gold. But to an engineer, the real challenge is: How do we process this data "on the fly"?&lt;/p&gt;

&lt;p&gt;Suppose you are the Chief System Architect of YouTube. You are tasked with building a system that collects and analyzes this massive influx of "gold." How would you process a vast, never-ending stream of data without the system buckling?&lt;/p&gt;

&lt;p&gt;In this scenario, you turn to Stream Processing.&lt;/p&gt;

&lt;p&gt;What is Stream Processing?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Martin Kleppmann&lt;/strong&gt; defines it as:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Stream processing is a computing paradigm focused on continuously processing data as it is generated, rather than storing it first and processing it in batches. It allows systems to react to events in near real-time, enabling low-latency analytics, monitoring, and decision making. Stream processing systems ingest data streams, apply transformations or computations, and emit results while the input is still being produced.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Essentially, instead of storing data and running a massive batch job at 2:00 AM, you process it the moment it arrives. But how do we implement this?&lt;/p&gt;

&lt;p&gt;This is where Kafka Streams enters the picture.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;By textbook definition&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“Kafka Streams is a lightweight, Java-based library for building real-time, scalable stream processing applications that read from and write to Apache Kafka topics. It provides high-level abstractions for continuous processing such as filtering, mapping, grouping, windowing, and aggregations, while handling fault tolerance and state management internally.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that we know &lt;em&gt;what&lt;/em&gt; to do and &lt;em&gt;which tool&lt;/em&gt; to use, let’s build our stream pipeline.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: This is a simplified mental model to explain the role of stream processing and Kafka Streams, not an exact representation of YouTube’s internal architecture. A giant like YouTube uses multiple stream processors, batch + streaming, ML pipelines, feature stores, etc to provide a seamless user experience.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Designing the Stream Pipeline&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Kafka Streams, we map our logic into a Topology. A topology is a &lt;strong&gt;directed acyclic graph&lt;/strong&gt; (DAG) of processing nodes that represent the transformation steps applied to the data stream.&lt;/p&gt;

&lt;p&gt;We start with &lt;strong&gt;Watch History, User Activities&lt;/strong&gt; as our source of truth. In technical terms, this is our Source Processor (reading from a Kafka Topic).&lt;br&gt;
Using the Kafka Streams DSL (Domain Specific Language), we can define three distinct operations:&lt;/p&gt;

&lt;p&gt;1: &lt;strong&gt;Data Masking and Sanitization&lt;/strong&gt;&lt;br&gt;
Before deriving any higher-level signals, it is often necessary to sanitize incoming events.&lt;br&gt;
This node:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;consumes raw user interaction events&lt;/li&gt;
&lt;li&gt;removes or masks unnecessary or sensitive fields&lt;/li&gt;
&lt;li&gt;standardizes the event structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This step ensures that downstream processors operate only on relevant and safe data, reducing coupling and improving maintainability.&lt;br&gt;
The output of this node is a sanitized event stream, which becomes the input for subsequent processing steps.&lt;/p&gt;

&lt;p&gt;2: &lt;strong&gt;Similar Content Recommendation&lt;/strong&gt;&lt;br&gt;
To power this, we need the &lt;strong&gt;User ID, Channel Name&lt;/strong&gt;, and &lt;strong&gt;Genre&lt;/strong&gt;. For example, if you watch a WWE video, the genre is Professional Wrestling. The goal is to immediately suggest related promotions like AEW or TNA.&lt;/p&gt;

&lt;p&gt;In this node, we take the raw KStream, apply a map or transform operation to extract the relevant metadata, and pass it to a Sink Processor. This sink then emits the event into a new Kafka topic: similar-content.&lt;/p&gt;

&lt;p&gt;3: &lt;strong&gt;Preferred Video Length&lt;/strong&gt;&lt;br&gt;
Here, we focus on user behaviour. Does the user prefer 30-second Shorts or 20-minute video essays?&lt;br&gt;
We transform the incoming KStream into a specialized object containing the User ID and duration metrics. This transformed data is then streamed into a dedicated topic: preferred-content-length.&lt;/p&gt;

&lt;p&gt;4: &lt;strong&gt;Product Discovery&lt;/strong&gt;&lt;br&gt;
If a user searches for specific items within the platform, we can extract these signals immediately. By filtering search events within the topology, we can transform them into product-intent objects and emit them into a product-recommendations topic.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4e6mlsm3kj6om2ng3tv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4e6mlsm3kj6om2ng3tv.png" alt="fig. 1.1" width="800" height="1129"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that the data is emitted as well-defined events, downstream applications can analyze it independently and serve users far more effectively — and you get to keep your high-paying job, all thanks to stream processing and Kafka Streams 😉&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kafka Streams as a Transformer, Not the Brain&lt;/strong&gt;'&lt;br&gt;
Many descriptions label Kafka Streams as the &lt;em&gt;"brain"&lt;/em&gt; or &lt;em&gt;"heart"&lt;/em&gt; of an application (which, in some cases, may be true). However, in this architecture, Kafka Streams acts as a high-performance Transformer and Supplier.&lt;/p&gt;

&lt;p&gt;It cleans, shapes, and routes data so that downstream microservices can act on it. &lt;em&gt;This is the hallmark of a well-designed Event-Driven Architecture.&lt;br&gt;
Congratulations!&lt;/em&gt; You’ve just scratched the surface of real-time data orchestration.&lt;/p&gt;

&lt;p&gt;But a question remains: &lt;strong&gt;Why not just use a traditional database?&lt;/strong&gt; Beyond the sheer volume of "heavy writes," what are the structural drawbacks of using a database for this?&lt;br&gt;
Stay tuned for Part 2.&lt;/p&gt;




</description>
      <category>kafka</category>
      <category>eventdriven</category>
      <category>kafkastreams</category>
      <category>streamprocessing</category>
    </item>
  </channel>
</rss>
