<?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: Varun Patil</title>
    <description>The latest articles on Forem by Varun Patil (@varunpatil1709).</description>
    <link>https://forem.com/varunpatil1709</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%2F3499916%2Ffc089418-5a8d-475e-9853-5ca234f87625.png</url>
      <title>Forem: Varun Patil</title>
      <link>https://forem.com/varunpatil1709</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/varunpatil1709"/>
    <language>en</language>
    <item>
      <title>A Developer’s Guide to Apache Kafka: From Basics to Architecture in One Read</title>
      <dc:creator>Varun Patil</dc:creator>
      <pubDate>Sat, 22 Nov 2025 17:26:04 +0000</pubDate>
      <link>https://forem.com/varunpatil1709/a-developers-guide-to-apache-kafka-from-basics-to-architecture-in-one-read-3i21</link>
      <guid>https://forem.com/varunpatil1709/a-developers-guide-to-apache-kafka-from-basics-to-architecture-in-one-read-3i21</guid>
      <description>&lt;p&gt;In today’s world, applications are no longer simple systems with a single database and a few users. Modern platforms like &lt;strong&gt;Uber, Netflix, Zomato, Amazon, Instagram, and even banking apps&lt;/strong&gt; generate millions of events every second—a ride request, a payment update, a login attempt, a notification, a cart update, a video play, and so on.&lt;/p&gt;

&lt;p&gt;Handling this constant flow of data in real time is no longer a luxury—it’s a necessity.&lt;br&gt;
And traditional systems struggle badly with this.&lt;/p&gt;

&lt;p&gt;They are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;slow&lt;/li&gt;
&lt;li&gt;tightly coupled&lt;/li&gt;
&lt;li&gt;difficult to scale&lt;/li&gt;
&lt;li&gt;easily break under heavy load.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To solve these modern data challenges, companies use &lt;strong&gt;Apache Kafka&lt;/strong&gt;, a distributed event streaming platform designed to handle massive volumes of real-time data with high speed, fault tolerance, and scalability.&lt;/p&gt;

&lt;p&gt;This blog will walk you through Kafka in the simplest possible way—from beginner concepts to intermediate architecture—using relatable examples, clear explanations, and real-life use cases.&lt;br&gt;
Whether you’ve never touched Kafka or want to strengthen your basics before learning about microservices, this guide will provide you with a solid foundation.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Why Do We Need Apache Kafka? (The Problem Before the Solution)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before understanding what Kafka is, it’s important to understand why it was created.&lt;br&gt;
Modern systems generate enormous amounts of data every second, yet traditional communication patterns were never designed to handle this scale or speed.&lt;/p&gt;

&lt;p&gt;Let’s break this down in simple terms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;2.1 Traditional Service Communication Was Broken&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most old systems communicated through direct API calls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Service A → Service B → Service C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;This approach creates several problems:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tight Coupling:&lt;/strong&gt;&lt;br&gt;
If Service B goes down, Service A also fails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complex Dependencies:&lt;/strong&gt;&lt;br&gt;
You add one new service, and every old service must be updated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;High Latency:&lt;/strong&gt;&lt;br&gt;
Each service waits for the previous one to respond.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Difficult to Scale:&lt;/strong&gt;&lt;br&gt;
At high traffic, these direct calls easily collapse.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;2.2 Real-Time Data Processing Was Hard&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Traditional systems used batch processing—data is collected first, then processed after a few minutes or hours.&lt;/p&gt;

&lt;p&gt;But today, apps require instant updates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Uber must show the driver’s live location&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Zomato must show live order status&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Netflix must track what you’re watching right now&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Banks must detect fraud in milliseconds&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Batch processing is too slow for this world.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;2.3 Databases Alone Could Not Handle Event Streams&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developers tried using databases as messaging systems:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Write event in DB&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Another service reads it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Marks it as “processed”&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This fails because:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Databases cannot handle millions of writes per second&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Polling the DB constantly is expensive&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No proper real-time streaming&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hard to replay events&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No distributed scalability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Databases were never meant for continuous event flow.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;2.4 Scaling Microservices Was a Nightmare&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When companies switched to microservices, a new problem came:&lt;/p&gt;

&lt;p&gt;Every service had to communicate with 5–10 other services.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order Service → Payment Service → Delivery Partner Service → Notification Service → Live Tracking Service → Analytics Service

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If any one service goes down, everything breaks.&lt;/p&gt;

&lt;p&gt;Adding even a single new service (e.g., fraud detection) means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Updating 5–10 other services&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Changing code everywhere&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;More API calls = More delays&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Microservices became too dependent on each other.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. What Is Apache Kafka? (Simple Definition + Analogy)
&lt;/h2&gt;

&lt;p&gt;Apache Kafka is a distributed event streaming platform designed to handle huge amounts of real-time data efficiently and reliably.&lt;/p&gt;

&lt;p&gt;If that sounds complex, here’s the simplest explanation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Kafka is like a high-speed delivery system that collects, stores, and distributes data (events) between different systems in real time.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Kafka acts as a middle layer between producers (systems that generate data) and consumers (systems that use the data).&lt;/p&gt;

&lt;p&gt;No direct communication.&lt;br&gt;
No dependency.&lt;br&gt;
No delays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.1 A Simple Analogy (Easy to Remember)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine a YouTube Channel.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Topic = The channel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Partition = Playlists inside the channel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Producers = People uploading videos&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consumers = Subscribers watching videos&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offset = The position of each video in the playlist&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Broker = YouTube server&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;YouTube doesn't send videos directly to you.&lt;br&gt;
You pull them whenever you want.&lt;/p&gt;

&lt;p&gt;Kafka works the same way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.2 Real Definition (Technical But Clear)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apache Kafka is a distributed publish-subscribe messaging system designed for high-throughput, fault-tolerant, real-time event streaming.&lt;/p&gt;

&lt;p&gt;Let’s decode that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Distributed → runs on multiple servers (brokers)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Publish-subscribe → producers publish, consumers subscribe&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;High-throughput → handles millions of events per second&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fault-tolerant → even if servers fail, data is safe&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-time → consumers get events instantly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Event streaming → continuous flow of data&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  4. Kafka Architecture: Understanding the Structure of Kafka
&lt;/h2&gt;

&lt;p&gt;To understand how Kafka actually works, you need to know its internal structure. Kafka is built from a few simple but powerful components. Once you understand these blocks, the whole system becomes easy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.1 High-Level Kafka Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here is the simplest breakdown of Kafka’s structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Producers → Topics → Partitions → Brokers → Consumers → Consumer Groups

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;4.2 Core Components of Kafka Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1️⃣ &lt;strong&gt;Topics&lt;/strong&gt;&lt;br&gt;
A topic is a category or channel where data is stored.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;orders&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;payments&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;user-logins&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Kafka topics are append-only logs—events are added at the end.&lt;/p&gt;

&lt;p&gt;2️⃣ &lt;strong&gt;Partitions&lt;/strong&gt;&lt;br&gt;
Each topic is split into multiple partitions.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;To increase speed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To process data in parallel&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To scale horizontally&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each partition stores messages in order, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Partition 0:** [msg1, msg2, msg3...]
**Partition 1:** [msg4, msg5, msg6...]
**Partition 2:** [msg7, msg8...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More partitions = higher throughput (millions of messages/second).&lt;/p&gt;

&lt;p&gt;3️⃣ &lt;strong&gt;Brokers&lt;/strong&gt;&lt;br&gt;
A broker is a single Kafka server.&lt;/p&gt;

&lt;p&gt;Kafka clusters contain multiple brokers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Broker 1
Broker 2
Broker 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each broker:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Stores data&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Manages partitions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Serves consumer requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensures high availability&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If one broker fails, Kafka still works because of replication.&lt;/p&gt;

&lt;p&gt;4️⃣ &lt;strong&gt;Replication&lt;/strong&gt;&lt;br&gt;
Kafka replicates partitions across brokers.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Partition 0 → Leader on Broker 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Replica copies on Broker 2 and Broker 3&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If Broker 1 fails, Broker 2 becomes leader.&lt;/p&gt;

&lt;p&gt;This makes Kafka fault-tolerant.&lt;/p&gt;

&lt;p&gt;5️⃣ &lt;strong&gt;Producers&lt;/strong&gt;&lt;br&gt;
Producers send (publish) messages to topics.&lt;/p&gt;

&lt;p&gt;They can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;choose which partition to write to&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;send millions of messages per second&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;handle failures using retries and acks&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;6️⃣ &lt;strong&gt;Consumers&lt;/strong&gt;&lt;br&gt;
Consumers read messages from topics.&lt;/p&gt;

&lt;p&gt;They read data in sequence, based on offsets.&lt;/p&gt;

&lt;p&gt;Consumers do NOT delete messages. Kafka keeps them until retention time is over.&lt;/p&gt;

&lt;p&gt;7️⃣ &lt;strong&gt;Consumer Groups&lt;/strong&gt;&lt;br&gt;
A consumer group is a set of consumers reading from the same topic.&lt;/p&gt;

&lt;p&gt;Kafka ensures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;one partition → only one consumer of the group&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;perfect load balancing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;parallel processing&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Topic: orders (3 partitions)
Consumer Group:
  Consumer 1 → Partition 0
  Consumer 2 → Partition 1
  Consumer 3 → Partition 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;8️⃣ Zookeeper / KRaft (Metadata Manager)&lt;br&gt;
Kafka uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Zookeeper (older versions)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;KRaft (new versions — built-in Kafka controller)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It manages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Broker information&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Leader elections&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cluster metadata&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Modern Kafka uses KRaft only, making setup simpler.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.3 Kafka Architecture Diagram&lt;/strong&gt;&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%2Fuhhb9akq109dlot711ck.jpg" 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%2Fuhhb9akq109dlot711ck.jpg" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion: The Foundation You Need Before Diving Deeper&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Apache Kafka has become the backbone of modern real-time systems—from ride-hailing platforms and food delivery apps to banking, e-commerce, IoT, and streaming services. Understanding how Kafka works at a conceptual level—its topics, partitions, brokers, replication, producers, consumers, and consumer groups—gives you the foundation needed to navigate event-driven architectures confidently.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;By now, you should have a clear picture of:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Why traditional systems struggled&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What problem Kafka solves&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Kafka’s internal structure and architecture&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How data flows through Kafka&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why Kafka is the preferred choice for scalable microservices&lt;/p&gt;

&lt;p&gt;This knowledge sets the stage for the practical side of Kafka, where the real magic begins.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>beginners</category>
      <category>dataengineering</category>
    </item>
    <item>
      <title>Understanding and Verifying JWT Authentication in Spring Boot</title>
      <dc:creator>Varun Patil</dc:creator>
      <pubDate>Sat, 04 Oct 2025 20:11:17 +0000</pubDate>
      <link>https://forem.com/varunpatil1709/understanding-and-verifying-jwt-authentication-in-spring-boot-4i2h</link>
      <guid>https://forem.com/varunpatil1709/understanding-and-verifying-jwt-authentication-in-spring-boot-4i2h</guid>
      <description>&lt;h2&gt;
  
  
  What Is JWT (JSON Web Token)?
&lt;/h2&gt;

&lt;p&gt;JWT (JSON Web Token) is a compact, URL-safe way to represent secure information between two parties — typically between a client (like your React frontend) and a server (like your Spring Boot backend).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure of JWT&lt;/strong&gt;&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%2F0xcdqrv4hqx6zkk83s5q.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%2F0xcdqrv4hqx6zkk83s5q.png" alt=" " width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Header&lt;/strong&gt; – contains metadata about the token&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "alg": "HS256",
  "typ": "JWT"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;alg: the algorithm used to sign the token (like HMAC SHA256)&lt;/li&gt;
&lt;li&gt;typ: the type of token (always "JWT")&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Payload&lt;/strong&gt;– contains the actual data (called claims)&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "sub": "varunpatil",
  "role": "USER",
  "iat": 1696504500,
  "exp": 1696508100
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;sub: subject (usually the username or user ID)&lt;/li&gt;
&lt;li&gt;iat: issued at (timestamp)&lt;/li&gt;
&lt;li&gt;exp: expiration time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also add custom fields like email, role, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Signature&lt;/strong&gt; – ensures the token hasn’t been tampered with&lt;br&gt;
Created by combining the header, payload, and a secret key:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HMACSHA256(base64UrlEncode(header) + "." + base64UrlEncode(payload), secret)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;So a final JWT looks something like this 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJzdWIiOiJ2YXJ1bnBhdGlsIiwicm9sZSI6IlVTRVIifQ.
X7a2qDg6m8i0wRJCrjXw9sM1D_Va8m2YH7JbZp8Qb6Y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ⚙️ How JWT Works (Simple Flow)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The user logs in with credentials (email &amp;amp; password).&lt;/li&gt;
&lt;li&gt;The server verifies credentials and generates a JWT.&lt;/li&gt;
&lt;li&gt;The client stores the token (e.g., in localStorage or a cookie).&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For every request, the client sends the token in the Authorization header:&lt;br&gt;
&lt;code&gt;Authorization: Bearer &amp;lt;your_jwt_token&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The server verifies the token. If valid, it processes the request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the token is expired or invalid → the request is denied.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🔍 JWT Verification — How the Server Confirms the Token Is Legit
&lt;/h2&gt;

&lt;p&gt;When a user sends a JWT (usually in the Authorization header), the server doesn’t just trust it — it recomputes and verifies it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1️⃣ Token Received&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example token:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xxxxx.yyyyy.zzzzz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Where:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;xxxxx → Base64URL(header)&lt;/li&gt;
&lt;li&gt;yyyyy → Base64URL(payload)&lt;/li&gt;
&lt;li&gt;zzzzz → Base64URL(signature)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2️⃣ Server Splits the Token&lt;/strong&gt;&lt;br&gt;
The server separates these 3 parts.&lt;br&gt;
Then it decodes the header and payload (Base64URL → JSON):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Header: { "alg": "HS256", "typ": "JWT" }
Payload: { "sub": "varunpatil", "exp": 1696508100 }
Signature: "zzzzz"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3️⃣ Server Recreates the Signature&lt;/strong&gt;&lt;br&gt;
The server takes the same header and payload (the first two parts) and runs them through the same signing algorithm using the secret key stored securely on the backend.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;newSignature = HMACSHA256(
  base64UrlEncode(header) + "." + base64UrlEncode(payload),
  secretKey
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This produces a new hash — essentially a digital fingerprint of the token’s content.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4️⃣ Signature Comparison&lt;/strong&gt;&lt;br&gt;
Now the server compares the newly created signature with the one received in the token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (newSignature == receivedSignature)
    → ✅ Token is authentic
else
    → ❌ Token has been tampered with
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If someone even changes a single character in the payload (like user role or ID), the new hash will be completely different, and verification will fail instantly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features of JWT
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.Stateless (No Server-Side Session)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JWT is self-contained: it carries all the user information inside the token (claims).&lt;/li&gt;
&lt;li&gt;The server doesn’t need to store session data — just validate the signature.&lt;/li&gt;
&lt;li&gt;Makes scaling APIs easier because you don’t rely on in-memory sessions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.Compact and URL-Safe&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tokens are small and can be sent in:

&lt;ul&gt;
&lt;li&gt;HTTP headers (Auth: Bearer )&lt;/li&gt;
&lt;li&gt;URL query parameters&lt;/li&gt;
&lt;li&gt;Cookies&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Base64Url encoding ensures tokens are safe to transmit over the web.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Cross-Platform&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JWT is language-agnostic — works with Java, Node.js, Python, Go, etc.&lt;/li&gt;
&lt;li&gt;Can be used in mobile apps, web apps, or microservices.&lt;/li&gt;
&lt;li&gt;Perfect for distributed systems where multiple services need to verify the same token.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4.  Integrity Verified&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The signature ensures the token hasn’t been tampered with.&lt;/li&gt;
&lt;li&gt;If the payload is changed, verification will fail.&lt;/li&gt;
&lt;li&gt;Protects sensitive operations like authentication, authorization, and API access.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of JWT
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Payload Is Not Encrypted&lt;/li&gt;
&lt;li&gt;Token Revocation Is Hard&lt;/li&gt;
&lt;li&gt;Complexity in Key Management&lt;/li&gt;
&lt;li&gt;Vulnerable If Secrets Are Compromised&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Many people mistakenly believe that JWT encrypts data. In fact, JWT does not encrypt the data; it only encodes it and uses a signature to verify that the token was issued by a trusted source and hasn’t been tampered with.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Encoding vs Encryption
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;u&gt;&lt;strong&gt;1. Encoding&lt;/strong&gt;&lt;/u&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Purpose&lt;/strong&gt;: To transform data into a different format so it can be safely transmitted or stored.&lt;br&gt;
&lt;strong&gt;Key Point&lt;/strong&gt;: Encoding is not meant to be secret — anyone can decode it.&lt;br&gt;
&lt;strong&gt;Example in JWT:&lt;/strong&gt;&lt;br&gt;
Header and payload are Base64Url encoded.&lt;br&gt;
Anyone can decode and read the payload; the security comes from the signature, not the encoding.&lt;br&gt;
&lt;strong&gt;Analogy&lt;/strong&gt;: Like converting English text to Morse code — it’s readable if you know the rules.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;u&gt;&lt;strong&gt;2. Encryption&lt;/strong&gt;&lt;/u&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; To make data confidential so only authorized parties can read it.&lt;br&gt;
&lt;strong&gt;Key Point:&lt;/strong&gt; Encryption requires a secret key (or public/private key pair). Without the key, the data is unreadable.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; AES, RSA, or JWE (JSON Web Encryption).&lt;br&gt;
&lt;strong&gt;Analogy:&lt;/strong&gt; Like locking your letter in a safe — only someone with the key can open it.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;em&gt;Thank You....&lt;/em&gt;
&lt;/h2&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What is a Bean in Spring Boot?</title>
      <dc:creator>Varun Patil</dc:creator>
      <pubDate>Sat, 13 Sep 2025 19:33:32 +0000</pubDate>
      <link>https://forem.com/varunpatil1709/what-is-a-bean-in-spring-boot-3g9</link>
      <guid>https://forem.com/varunpatil1709/what-is-a-bean-in-spring-boot-3g9</guid>
      <description>&lt;p&gt;If you are learning Spring Boot, one term you’ll hear again and again is “Bean”. But what exactly is a Bean, and why is it so important? Let’s break it down in simple terms for developers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. What is a Bean?&lt;/strong&gt;&lt;br&gt;
In Spring, a Bean is simply an object managed by the Spring IoC (Inversion of Control) container.&lt;/p&gt;

&lt;p&gt;Instead of manually creating objects using new in your code, Spring creates and manages the objects for you. This allows Spring to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Automatically inject dependencies into classes.&lt;/li&gt;
&lt;li&gt;Manage the lifecycle of objects (initialization and destruction).&lt;/li&gt;
&lt;li&gt;Promote loose coupling and reusability.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;In short, a bean is just a Spring-managed object.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Beans Are Not Just Models&lt;/strong&gt;&lt;br&gt;
Many developers assume beans are only for model classes (like Car, User, etc.), but that’s not true. Beans can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Models / Entities&lt;/li&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;li&gt;Repositories / DAOs&lt;/li&gt;
&lt;li&gt;Controllers&lt;/li&gt;
&lt;li&gt;Configuration classes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Basically, any class you want Spring to manage can be a bean.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. How to Create Beans in Spring Boot&lt;/strong&gt;&lt;br&gt;
a) Using Annotations (Recommended in Spring Boot)&lt;br&gt;
Spring Boot automatically scans your packages for components and creates beans for you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Component
public class Car {
    public void drive() {
        System.out.println("Driving a Mercedes");
    }
}

@Service
public class CarService {
    private final Car car;

    @Autowired
    public CarService(Car car) {
        this.car = car;
    }

    public void startJourney() {
        car.drive();
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;b) Using Configuration Class with &lt;a class="mentioned-user" href="https://dev.to/bean"&gt;@bean&lt;/a&gt;&lt;br&gt;
You can also define beans in a central configuration class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Configuration
public class AppConfig {

    @Bean
    public Car car() {
        return new Car();
    }

    @Bean
    public CarService carService() {
        return new CarService(car());
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Why Beans Matter&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inversion of Control (IoC): Spring creates objects and injects dependencies, not your code.&lt;/li&gt;
&lt;li&gt;Dependency Injection (DI): Makes your code loosely coupled, reusable, and testable.&lt;/li&gt;
&lt;li&gt;Lifecycle Management: Spring can manage bean lifecycle (@PostConstruct, @PreDestroy, or init-method / destroy-method).&lt;/li&gt;
&lt;li&gt;Reusability:A single bean can be used across multiple services, controllers, and other beans.
**&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bean Lifecycle (Brief Overview)**&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Spring instantiates the bean&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Injects dependencies&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calls initialization methods&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Bean is ready to use&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On shutdown, calls destroy methods&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A bean is simply a Spring-managed object.&lt;/li&gt;
&lt;li&gt;Beans allow Spring to handle object creation, wiring, and lifecycle, letting you focus on building business logic.&lt;/li&gt;
&lt;li&gt;Modern Spring Boot uses annotations + component scanning, so you rarely need XML anymore.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>springboot</category>
      <category>beginners</category>
      <category>backend</category>
      <category>java</category>
    </item>
  </channel>
</rss>
