<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vishal Kamath on Medium]]></title>
        <description><![CDATA[Stories by Vishal Kamath on Medium]]></description>
        <link>https://medium.com/@vishal.kamath?source=rss-6dc96cc59796------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SvpkLBv6JLVdpSO3</url>
            <title>Stories by Vishal Kamath on Medium</title>
            <link>https://medium.com/@vishal.kamath?source=rss-6dc96cc59796------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:20:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vishal.kamath/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Java Virtual Threads vs Goroutines: Is Java Catching Up to Go?]]></title>
            <link>https://medium.com/@vishal.kamath/java-virtual-threads-vs-goroutines-is-java-finally-catching-up-to-go-a4130bdf0647?source=rss-6dc96cc59796------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4130bdf0647</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Vishal Kamath]]></dc:creator>
            <pubDate>Wed, 29 Jul 2026 10:40:25 GMT</pubDate>
            <atom:updated>2026-07-29T10:48:56.958Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Suppose you want to build an application that has to handle 10,000+ concurrent requests.</strong></p><p>In traditional Java, every thread you spawn is mapped 1:1 to an OS thread. Each one costs you around 1MB of stack memory, plus real OS scheduling overhead. So if your app tries to handle those 10,000 requests the naive way one thread per request you’re left with two bad outcomes: you either run out of memory, or your CPU ends up spending more time context-switching between threads than actually doing the work.</p><p>And here’s the thing modern apps <em>need</em> to handle thousands, sometimes millions, of concurrent requests. Most of these requests aren’t even doing much they’re just waiting. Waiting on a database query. Waiting on a file read. Waiting on some other service to respond. Blocking an entire expensive OS thread just to sit around and wait is, frankly, wasteful.</p><p>So we have two very different answers to this exact same problem. Go solved it with <strong>goroutines</strong>, baked into the language from day one. Java solved it with <strong>Virtual Threads</strong>, introduced in its newer versions.</p><p>Which brings us to the real question: <strong>is Java just catching up to Go?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jUCy0XMSmMXY9htX5JTGoQ.png" /></figure><p><strong>Go’s Goroutines : </strong>So how does Go actually pull this off?</p><p>The answer is Go’s <strong>M:N scheduling model</strong>. Instead of mapping one goroutine to one OS thread which is exactly the 1:1 problem we saw with traditional Java threads Go’s runtime maps a large number of goroutines onto a much smaller number of OS threads. Goroutines are the function that runs concurrently along with the main program and can be defined using go keyword. The Go runtime sits on top of the OS scheduler, deciding at any given moment which goroutine gets to run on which OS thread.</p><p>This is possible because goroutines are incredibly cheap. A goroutine starts with a stack of just about <strong>2KB</strong>, compared to the roughly <strong>1MB</strong> an OS thread needs. And that stack isn’t fixed it grows and shrinks dynamically as the goroutine needs more or less memory. That’s the real reason you can spin up hundreds of thousands, even millions, of goroutines in a single Go program without your app falling over.</p><p>The syntax reflects this simplicity too. There’s no thread pool to configure, no executor service to manage. You just write: <strong>go handlerFunc()</strong></p><p>That single keyword <strong>go</strong> hands the function off to the runtime, which takes care of scheduling it. No lifecycle management, no manual tuning.</p><p><strong>Java’s Virtual Threads: </strong>Java took a different road to solve the same problem and it took Java a while to get there.</p><p>Virtual Threads arrived as a preview feature in <strong>Java 19</strong> (2022) and became stable in <strong>Java 21</strong> (September 2023), as part of <strong>Project Loom</strong> (JEP 444). The goal was the same one Go had already solved: handle massive concurrency without needing one expensive OS thread per task. But Java had a constraint Go never had three decades of existing code that couldn’t just be thrown away.</p><p>Under the hood, Java still has real OS threads they’re just called <strong>carrier threads</strong> now. Instead of mapping one virtual thread to one OS thread, the JVM schedules many virtual threads on top of a small pool of carrier threads. Sound familiar? It’s the same M:N model goroutines use.</p><p>The real magic is in how blocking is handled. When a virtual thread hits something blocking a network call, a database query the JVM automatically <strong>unmounts</strong> it from its carrier thread, freeing that OS thread up to run a different virtual thread. Once the blocking operation completes, the virtual thread gets <strong>mounted</strong> back onto whatever carrier thread is free to continue running. All of this happens automatically, invisible to you as a developer.</p><p>But there’s a catch Go developers never have to think about: <strong>pinning</strong>. In certain situations, a virtual thread can get stuck to its carrier thread and <em>can’t</em> be unmounted even while blocked mainly when it’s running inside a synchronized block, or making certain native method calls. If a pinned virtual thread blocks, it holds its entire carrier thread hostage, quietly defeating the whole point of using virtual threads in the first place. It&#39;s a real gotcha teams run into when they lift old code code written with synchronized in mind straight onto virtual threads, expecting free scaling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8PDCV8w7Sr6niWmQXU1tnA.png" /></figure><p><strong>So is Java catching up to Go?</strong> Architecturally, yes both landed on M:N scheduling with cheap, disposable units of concurrency. But how they got there tells a different story. Go was built from scratch with this problem in mind. Java took the harder path retrofitting the same idea onto 30 years of existing code without breaking any of it.</p><p>If you’re building something new and starting fresh, Go’s model is elegant and simple by default. If you’re already deep in the Java ecosystem, Virtual Threads mean you get most of that same scalability without rewriting a single line of your existing business logic.</p><p>Either way, the era of one thread per request costs you a megabyte is over. And that’s a genuinely exciting time to be writing concurrent code, no matter which language you picked.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4130bdf0647" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Complete JWT Authentication System in Spring Boot- Step by Step]]></title>
            <link>https://medium.com/@vishal.kamath/build-a-complete-jwt-authentication-system-in-spring-boot-step-by-step-f77e80868db5?source=rss-6dc96cc59796------2</link>
            <guid isPermaLink="false">https://medium.com/p/f77e80868db5</guid>
            <category><![CDATA[jwt-authentication]]></category>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vishal Kamath]]></dc:creator>
            <pubDate>Thu, 02 Jul 2026 10:35:08 GMT</pubDate>
            <atom:updated>2026-07-02T10:35:08.056Z</atom:updated>
            <content:encoded><![CDATA[<p>Every time a client sends a request to the server, the server needs to verify one fundamental question “Is this request coming from a legitimate user?”</p><p>Without a proper authentication mechanism, the user would have to log in before every single request they make. Imagine having to log into Instagram every time you scroll your feed terrible user experience, right? This is exactly the problem JWT (JSON Web Token) solves.</p><p>When a user successfully logs in, the server generates a JWT token and sends it to the client. From that point forward, the client attaches this token to every request it makes. The server simply validates the token and knows exactly who is making the request.</p><p>Now, generating and validating tokens is one thing but we also need a robust framework to handle the entire security layer of our application. That’s where <strong>Spring Security</strong> comes in. Spring Security is a powerful framework in the Spring ecosystem that handles both <strong>Authentication</strong> (who are you?) and <strong>Authorization</strong> (what are you allowed to do?). It comes packed with features like role based access control, password encoding, session management and much more.</p><p>In this article, we will build a complete JWT authentication system from scratch using Spring Boot and Spring Security covering everything from project setup to testing protected endpoints with Postman.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Yk8jRSHqPsa_AIap" /></figure><h3>How Spring Security Works — The Filter Chain</h3><p>Before any request reaches your controller, it must pass through a series of checks this is called the <strong>Security Filter Chain</strong>.</p><p>Think of it like security checkpoints at an airport. Every passenger (request) must pass through each checkpoint in order. If any check fails the passenger never boards the plane (never reaches the controller).</p><p>Spring Security’s <strong>SecurityFilterChain</strong> consists of multiple filters, each responsible for exactly one job such as <strong>UsernameAndPasswordAuthenticationFilter</strong> handles username and pasword auth,<strong>AuthorizationFilter</strong> handles roles and permission checks,<strong>BearerTokenAuthenticationFilter</strong> handles JWT auth,<strong>BasicAuthenticationFilter</strong> handles http basich auth.</p><p>These Filters run in order and if any of them fails then the request i rejected and never reaches the controller and 401 Unauthorized/403 forbidden is sent to the client.</p><h3>Core Components and Authentication Flow</h3><p>To understand Spring Security deeply, you need to know five core components and how they talk to each other.</p><h4>1. UserDetails</h4><p>UserDeatisl is a built-in interface provided by Spring Security. Your User entity implements this interface, essentially telling Spring Security &quot;Hey, my User class speaks your language.&quot;</p><p>It provides seven key methods -&gt; isAccountNonExpired() ,isAccountNonLocked(),isCredentialsNonExpired(),isEnabled(), getPassword(),getUsername,getAuthorities().</p><h4>2. UserDetailsService</h4><p>UserDetailsService is another built-in interface with just one method -<strong>loadUserByUsername( ).</strong></p><p>You implement this yourself, it’s the bridge between Spring Security and your database. When Spring Security needs to verify a user, it calls this method to fetch the user from your DB.</p><h4>3. AuthenticationProvider</h4><p>AutehnticationProvider is where the actual verification happens. Spring Boot provides DaoAuthenticationProvider of the box which we configure with our UserDetailsService and PasswordEncoder.</p><h4>4. AuthenticationManager</h4><p>AuthenticationManager orchestrates the authentication process. It doesn&#39;t do the verification itself it simply delegates to the right AutehnticationProvider. Think of it as a manager who assigns work rather than doing it himself.</p><h4>5. SecurityContext</h4><p>Once authentication succeeds, the authenticated user object is stored in the SecurityContext a <strong>thread-local storage</strong> that holds the authenticated user for the entire duration of that request.</p><h3>What JWT comprises of and how it works?</h3><p>JWT stands for JSON Web Token. Upon successful login, the server generates a JWT and sends it to the client. From that point forward, the client attaches this token to every request it makes allowing the server to verify that the request is coming from an authenticated user without requiring them to log in again.</p><p>A JWT consists of three parts — the Header, Payload, and Signature.</p><p>The Header contains the algorithm used to sign the token, such as HS256. The Payload carries the actual user data things like username, role, issued-at time, and expiration time. The Signature is formed by combining the Header and Payload with a secret key stored securely in your environment file ensuring that nobody can tamper with the token without the server knowing.</p><p>Here is how the verification works when the user sends the token back with a request, the server takes the Header and Payload from the token, re-signs them using the same secret key, and compares the result with the signature present in the token. If they match, the request is from a legitimate user. If they don’t match, the token has been tampered with and the request is immediately rejected.</p><h3>Project Setup</h3><p>Head over to <a href="https://start.spring.io/">start.spring.io</a> and create a new Spring Boot project with the following dependencies:</p><p><strong>Spring Web</strong> — to build REST APIs and expose HTTP endpoints.</p><p><strong>Spring Data JPA</strong> — to interact with the database using Java objects instead of raw SQL queries.</p><p><strong>MySQL Driver</strong> — to establish a connection between your Spring Boot application and MySQL database.</p><p><strong>Lombok</strong> — to eliminate boilerplate code like getters, setters, and constructors by using simple annotations like @Data, @AllArgsConstructor, and @NoArgsConstructor.</p><p><strong>Spring Security</strong> — to handle authentication and authorization out of the box.</p><p>Now head over to <a href="https://mvnrepository.com/">mvnrepository.com</a> and manually add these three JWT dependencies to your pom.xml — these are not available on Spring Initializr:</p><p><strong>jjwt-api</strong> — the core JWT interface that your code interacts with directly.</p><p><strong>jjwt-impl</strong> — the actual implementation of the JWT library, added with runtime scope since you never interact with it directly.</p><p><strong>jjwt-jackson</strong> — handles JSON parsing for JWT tokens, also added with runtime scope.</p><p>All three should be from io.jsonwebtoken group with version 0.11.5.</p><h3><strong>Lest Start Building Step by Step</strong></h3><h3>Step 1 — User Entity and Role Enum</h3><p>file link: <a href="https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/model">https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/model</a></p><p>The first thing we need is a User entity that Spring Security can understand. To make that happen, our User class must implement the UserDetails interface — a built-in interface provided by Spring Security that acts as a contract between your user model and the security framework.</p><p>By implementing UserDetails, we are essentially telling Spring Security — &quot;Hey, my User class speaks your language. Ask me anything about the user and I will answer.&quot;</p><p>The User entity has four fields — an auto-generated id, a username, a password, and a role. The role field uses a Role enum with values ADMIN and USER, stored as a String in the database using @Enumerated(EnumType.STRING).</p><p>Implementing UserDetails requires us to override seven methods. The two most important ones are getUsername() and getPassword() — but since we are using Lombok&#39;s @Data annotation, it automatically generates these getters for us behind the scenes.</p><p>The getAuthorities() method tells Spring Security what roles this user has. We wrap our role in a SimpleGrantedAuthority object with the ROLE_ prefix — this is a Spring Security convention that must be followed.</p><p>The remaining four methods — isAccountNonExpired(), isAccountNonLocked(), isCredentialsNonExpired(), and isEnabled() — are account status checks that Spring Security calls during authentication. For simplicity, we return true for all of them, meaning accounts never expire, never get locked, and are always active.</p><h3>Step 2 — User Repository</h3><p>file link: <a href="https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/repository">https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/repository</a></p><p>Next we create the UserRepository interface which extends JpaRepository giving us all standard database operations like save, findById, and delete out of the box.</p><p>But we also need one custom method findByUsername(). During the login process, Spring Security needs to fetch the user from the database using their username. Spring Data JPA is smart enough to automatically generate the query for this method just by reading the method name — no SQL needed.</p><p>We also wrap the return type in Optional so instead of getting a null when the user is not found, we get an empty Optional that we can handle gracefully by throwing a meaningful exception.</p><h3>Step 3 — Custom User Details Service</h3><p>file link: <a href="https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/service">https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/service</a></p><p>Now we need to tell Spring Security how to fetch a user from our database. This is done by implementing the UserDetailsService interface — a built-in Spring Security interface with just one method: loadUserByUsername().</p><p>Spring Security automatically calls this method during authentication, passing the username entered by the user. Our job is simple — go to the database, find the user by that username, and return them.</p><p>Since our User entity already implements UserDetails, we can return it directly without any conversion — Spring Security understands it perfectly.</p><p>If the user is not found in the database, we throw a UsernameNotFoundException — a built-in Spring Security exception that signals authentication failure and returns a 401 Unauthorized response to the client.</p><h3>Step 4 — JWT Service</h3><p>file link: <a href="https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/blob/main/JWTDemo/src/main/java/com/example/JWTDemo/service/JWTService.java">https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/blob/main/JWTDemo/src/main/java/com/example/JWTDemo/service/JWTService.java</a></p><p>The JwtService is the heart of our JWT implementation. It is responsible for three things — generating tokens after successful login, extracting the username from an incoming token, and validating whether a token is genuine and not expired.</p><p><strong>Generating the Token</strong></p><p>When a user successfully logs in, we use the Jwts.builder() to construct a JWT token. We set the username as the subject of the token, record the current time as the issued-at timestamp, calculate the expiration time by adding 24 hours to the current time, and finally sign the token with our secret key using the HS256 algorithm. The compact() method at the end builds and returns the final JWT string.</p><p><strong>Extracting Claims</strong></p><p>The extractClaim() method is the core utility of this class. It parses the incoming token using our secret key, extracts the payload, and applies a function to retrieve whichever field we need. This generic approach allows us to extract any claim username, expiration date, or any custom field using a single reusable method.</p><p><strong>Validating the Token</strong></p><p>The isTokenValid() method performs two checks it verifies that the username inside the token matches the user fetched from the database, and confirms that the token has not expired. Only if both checks pass do we consider the token valid.</p><p><strong>The Secret Key</strong></p><p>The getSigningKey() method converts our plain text secret key stored in application.properties into a cryptographic Key object that the JWT library understands. The secret key is Base64 decoded into raw bytes and then converted into an HMAC SHA key this is what gets used to sign and verify every token.</p><p><a href="https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/config">https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/config</a></p><h3>Step 5 — Security Configuration</h3><p>file link:<a href="https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/config">https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/config</a></p><p>The SecurityConfig class is the <strong>rulebook</strong> of our entire security setup. This is where we tell Spring Security how to authenticate users, which endpoints are public, and how to handle sessions.</p><p><strong>Password Encoder</strong></p><p>We expose BCryptPasswordEncoder as a Spring bean. BCrypt is a powerful hashing algorithm that encodes passwords before storing them in the database and verifies them during login. By making it a bean, Spring Security can find and use it automatically anywhere in the application.</p><p><strong>Authentication Provider</strong></p><p>We use DaoAuthenticationProvider — Spring Security&#39;s built-in provider for database backed authentication. We wire it with our CustomUserDetailsService so it knows how to fetch users from the database, and with our PasswordEncoder so it knows how to verify passwords. This provider is the one that actually does the heavy lifting of authenticating a user.</p><p><strong>Security Filter Chain</strong></p><p>This is where we define the access rules for every endpoint in our application. We disable CSRF protection since we are building a stateless REST API that uses JWT tokens instead of browser sessions. We then define our authorization rules — /auth/** endpoints are publicly accessible for login and registration, while all other endpoints require a valid authenticated session. Finally we set the session policy to STATELESS — telling Spring Security to never create HTTP sessions since every request will carry its own JWT token.</p><h3>Step 6 — JWT Authentication Filter</h3><p>file link:<a href="https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/filter">https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo/src/main/java/com/example/JWTDemo/filter</a></p><p>The JwtAuthFilter is the most important piece of our JWT implementation. It is the bridge between the incoming HTTP request and Spring Security intercepting every request, reading the JWT token, validating it, and telling Spring Security who the user is.</p><p>Our filter extends OncePerRequestFilter a built-in Spring class that guarantees the filter runs exactly once per request, preventing any duplicate processing.</p><p><strong>Reading the Token</strong></p><p>Every request that requires authentication must carry a JWT token in the Authorization header in this format — Bearer &lt;token&gt;. Our filter reads this header from the incoming request. If the header is missing or does not start with Bearer, we simply pass the request forward to the next filter without any JWT processing — this handles public endpoints like login and register.</p><p><strong>Extracting and Validating</strong></p><p>Once we confirm the token is present, we extract the raw JWT by removing the Bearer prefix using substring(7). We then use our JwtService to extract the username from the token. With the username in hand, we fetch the user from the database and run the token through our isTokenValid() method — checking that the username matches and the token has not expired.</p><p><strong>Setting Authentication in SecurityContext</strong></p><p>If the token passes validation, we create a UsernamePasswordAuthenticationToken object containing the user&#39;s details and their roles, and store it in the SecurityContext. This is how we tell Spring Security — &quot;this user is authenticated, trust them for this request.&quot; The AuthorizationFilter then reads from the SecurityContext to check if the user has permission to access the requested endpoint.</p><p><strong>Passing the Request Forward</strong></p><p>At the end of the filter regardless of whether authentication succeeded or not we always call filterChain.doFilter(). This passes the request to the next filter in the chain. Think of it like a relay race each filter does its job and passes the baton forward. Without this call, the request would get stuck in our filter and never reach the controller.</p><h3>Step 7 — Wiring the JWT Filter into Security Config</h3><p>Creating the JwtAuthFilter alone is not enough — we need to tell Spring Security to actually use it. We do this by injecting the filter into our SecurityConfig and registering it in the filter chain using addFilterBefore().</p><p>This single line tells Spring Security to run our JwtAuthFilter before the default UsernamePasswordAuthenticationFilter. This is important because we need to read and validate the JWT token first and set the authentication in the SecurityContext before Spring Security&#39;s own filters kick in. Without this, our filter would never be executed and every request would be treated as unauthenticated.</p><h3>Step 8 — DTOs (Data Transfer Objects)</h3><p>Before building the controller, we create two simple DTO classes — RegisterRequest and LoginRequest. These represent the data that the client sends in the request body.</p><p>We never expose our User entity directly to the outside world — it contains sensitive internal fields. DTOs give us full control over exactly what data comes in and goes out of our API, keeping our entity layer clean and secure.</p><h3>Step 9 — Auth Service</h3><p>The AuthService contains the core business logic for registration and login.</p><p>During <strong>registration</strong>, we take the incoming request, encode the plain text password using BCryptPasswordEncoder before saving it to the database. We never store plain text passwords — even if the database is compromised, the attacker only sees an irreversible BCrypt hash.</p><p>During <strong>login</strong>, we fetch the user from the database by username. We then use passwordEncoder.matches() to compare the raw password from the request against the encoded password stored in the database. Direct string comparison would always fail here since one is plain text and the other is a BCrypt hash. If the password matches, we call JwtService.generateToken() and return the JWT token to the client.</p><h3>Step 10 — Auth Controller</h3><p>Finally we expose two endpoints through our AuthController:</p><p>POST /auth/register — accepts a RegisterRequest body and registers a new user in the system.</p><p>POST /auth/login — accepts a LoginRequest body, verifies the credentials, and returns a JWT token that the client must attach to every subsequent request.</p><p>Both endpoints are publicly accessible — configured in our SecurityConfig with permitAll() — since the user is not authenticated yet at this point.</p><h3><strong>Test Result in Postman</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*ow48u01GtbaooM8P-sVPXg.png" /></figure><p>Test with different cases like -&gt; Register an admin user ,register an user,Login with valid credentials,hit protected endpoint with valid token,hit endpoint without token,login with wrong password, user role accessing admin endpoint.</p><h3>Conclusion</h3><p>In this article we built a complete JWT authentication system from scratch using Spring Boot and Spring Security. We started by understanding the core concepts — the filter chain, authentication flow, and how each component like UserDetails, UserDetailsService, and AuthenticationProvider work together. We then implemented it step by step — from the User entity to the JwtAuthFilter — and tested every scenario using Postman.</p><p>This is just the foundation. From here you can explore refresh tokens to handle token expiry gracefully, exception handling for cleaner error responses, and integrating this security layer into a full fledged REST API.</p><p>The complete source code for this project is available on GitHub</p><p><a href="https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo">https://github.com/M-VISHAL-KAMATH26/SpringBootPOCProjects/tree/main/JWTDemo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f77e80868db5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Nginx and Why Should You Care as a Developer?]]></title>
            <link>https://medium.com/@vishal.kamath/what-is-nginx-and-why-should-you-care-as-a-developer-0aaad94620bd?source=rss-6dc96cc59796------2</link>
            <guid isPermaLink="false">https://medium.com/p/0aaad94620bd</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[back-end-development]]></category>
            <category><![CDATA[nginx-reverse-proxy]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Vishal Kamath]]></dc:creator>
            <pubDate>Thu, 28 May 2026 09:23:12 GMT</pubDate>
            <atom:updated>2026-05-28T09:24:13.679Z</atom:updated>
            <content:encoded><![CDATA[<p>You build an app. It works perfectly on localhost fast, smooth, exactly how you imagined it. Then you deploy it to the real world and suddenly everything falls apart. It slows down under real traffic, crashes when too many users hit it at once, and has no HTTPS leaving your users on an unsecured connection.</p><p>Sound familiar? These are some of the most common and frustrating problems developers face when moving from development to production. And most of them can be solved by one tool: <strong>Nginx</strong> (pronounced <em>“Engine-X”</em>).</p><p>In this post, we’ll cover what Nginx actually is, what it gives you as a developer, and how to start using it .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_ixAAbG9o8wHeomw3Rt1A.png" /></figure><h4>So… What Actually is Nginx?</h4><p>Nginx is an open-source web server that sits between the client and your server. When a user makes a request say, opening your website Nginx receives that request, forwards it to your server, and then sends the server’s response back to the client. Simple, but incredibly powerful.</p><p>It was introduced in 2004 by Igor Sysoev to solve what was then known as the <strong>C10K problem -</strong>the challenge of handling 10,000 concurrent connections on a single server. At the time, existing web servers struggled with this, and Nginx was built from the ground up to tackle it head-on.</p><p>What started as a solution to one specific problem quickly grew into something much bigger. Today, Nginx is used for reverse proxying, load balancing, caching, SSL termination, and a whole lot more making it one of the most versatile tools.</p><h4>What Does Nginx Offer?</h4><p>Nginx is far more than just a web server. Here’s what it brings to the table:</p><p><strong>Static File Caching</strong> Static assets like CSS, JavaScript, and images don’t change with every request. Nginx can cache and serve these files directly without the request ever touching your backend server. This means faster load times and less unnecessary load on your app.</p><p><strong>Reverse Proxy</strong> Nginx acts as a middleman between the client and your server. The client never communicates directly with your backend all requests go through Nginx first, which then forwards them to the appropriate service. This adds a clean layer of security and control over your traffic.</p><p><strong>Load Balancing</strong> When your app scales to multiple server instances, Nginx intelligently distributes incoming requests across them. It supports strategies like <strong>round robin</strong> (requests distributed evenly in order) and <strong>least connections</strong> (requests sent to the least busy server) keeping your app responsive even under heavy traffic.</p><p><strong>SSL Termination</strong> Instead of configuring HTTPS on every single microservice, Nginx handles SSL at its own level. Your internal services can communicate over plain HTTP while Nginx takes care of the HTTPS layer simplifying your architecture significantly.</p><p><strong>Response Compression</strong> Nginx can compress responses using Gzip before sending them to the client. Smaller response sizes mean faster API performance, quicker page loads, and less bandwidth consumed a win across the board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*iNkloIJBmUDGlPTuYIQE2w.png" /></figure><h4>Nginx vs Apache — What’s the Difference?</h4><p>At a high level, both Nginx and Apache serve the same purpose but the way they work under the hood is quite different, and that difference matters a lot at scale.</p><p><strong>Apache</strong> follows a <strong>process-based model</strong>. Every incoming request gets assigned its own thread, and each thread consumes a fixed chunk of memory typically around 20–30MB. For a handful of requests, this is fine. But when thousands of users hit your server simultaneously, you’re spawning thousands of threads, each eating up RAM. The server quickly runs out of resources and buckles under the load.</p><p><strong>Nginx</strong>, on the other hand, uses an <strong>event-driven, asynchronous model</strong>. A single worker process handles thousands of connections concurrently. When a request involves a slow operation like a database call or a file read ,Nginx doesn’t sit around waiting. It registers a callback, moves on to handle the next request, and comes back when the result is ready. No idle threads, no wasted memory.</p><p>This is exactly where Nginx shines and why it was built in the first place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*sF48Q34nTqk5zB-cilMacg.png" /></figure><h4>A Real-World Setup (Hands-On)</h4><p>Here’s everything you need to know to set it up on Ubuntu and actually use it day to day.</p><p><strong>Installation</strong></p><pre>sudo apt update<br>sudo apt install nginx<br>sudo systemctl start nginx</pre><p>That’s it. Visit http://localhost in your browser and you should see the Nginx welcome page.</p><p><strong>Understanding the Folder Structure</strong></p><p>Once installed, Nginx organizes its config files like this:</p><pre>/etc/nginx/<br>├── nginx.conf  # the main config file — global settings live here<br>├── sites-available/# all your site configs go here (active or not)<br>└── sites-enable# symlinks to configs you want Nginx to actually serve</pre><p>The key idea: you write your config in <strong>sites-available</strong>, then enable it by creating a symlink to <strong>sites-enabled</strong>. This makes it easy to switch sites on and off without deleting anything.</p><pre>sudo systemctl status nginx      # check if Nginx is running<br>sudo nginx -t                    # test your config for errors before reloading<br>sudo systemctl start nginx       # start Nginx<br>sudo systemctl stop nginx        # stop Nginx<br>sudo systemctl restart nginx     # full restart (causes brief downtime)<br>sudo systemctl reload nginx      # reload config with zero downtime — prefer this always<br>sudo nano /etc/nginx/sites-available/myapp.conf       # edit your site config<br>sudo nginx -t &amp;&amp; sudo systemctl reload nginx          # test + reload in one shot<br>sudo nginx -t &amp;&amp; sudo systemctl reload nginx   # after any config change<br>sudo tail -f /var/log/nginx/error.log          # when something breaks</pre><h4>Why Should YOU Care as a Developer?</h4><p>You might be thinking — “I’m a developer..Do I really need to know this?”</p><p>Yes. And here’s why.</p><p><strong>You’ll encounter it everywhere</strong> Whether it’s your first internship or your fifth job, Nginx will show up. It’s one of those tools that’s quietly running behind almost every production deployment you’ll ever work with. Knowing what it is and how it works puts you ahead of most developers who only know it by name.</p><p><strong>It makes you a more complete developer</strong> There’s a huge difference between a developer who can only run things locally and one who understands how their app behaves in production. Knowing Nginx even at a basic level shows that you think beyond just writing code.</p><p><strong>It’s not as hard as it looks</strong> Most developers avoid Nginx because it feels like infrastructure stuff. But as you’ve seen in this post, the basics are straightforward. A simple reverse proxy config is just a few lines.</p><p><strong>What’s coming in this series</strong></p><ul><li><strong>Part 1 ← You’re here:</strong> What is Nginx? Core concepts and why every developer should know it</li><li><strong>Part 2:</strong> Nginx as a Reverse Proxy -hiding your backend, securing your app, and how production deployments really work</li><li><strong>Part 3:</strong> Nginx as a Load Balancer -distributing traffic across multiple servers and keeping your app alive under heavy load</li><li><strong>Part 4:</strong> Nginx as a Static File Server &amp; Caching -serving assets at lightning speed without touching your backend</li><li><strong>Part 5:</strong> Nginx as Response Compression-shrinking your responses with Gzip and making your app noticeably faster</li><li><strong>Part 6:</strong> Nginx &amp; SSL-setting up HTTPS for free with Certbot and securing your app the right way</li></ul><p>Thanks for reading..! hope this made Nginx a little less mysterious</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0aaad94620bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Response Compression -Stop Sending Fat JSON]]></title>
            <link>https://medium.com/@vishal.kamath/response-compression-stop-sending-fat-json-8c02bb916b07?source=rss-6dc96cc59796------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c02bb916b07</guid>
            <category><![CDATA[response-compression]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[performance-api]]></category>
            <category><![CDATA[full-stack-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vishal Kamath]]></dc:creator>
            <pubDate>Wed, 20 May 2026 12:15:55 GMT</pubDate>
            <atom:updated>2026-05-20T12:15:55.281Z</atom:updated>
            <content:encoded><![CDATA[<p>Want your pages to load faster? Want your APIs to respond in a flash? Want to cut down bandwidth usage and reduce hosting costs ,all while climbing up the SEO rankings?</p><p>There’s one simple technique that does all of this at once <strong>Response Compression</strong>.</p><p><strong>So, what exactly is Response Compression?</strong></p><p>Response Compression is a technique where the server compresses the data whether it’s HTML, CSS, JavaScript, or JSON before sending it over the network to the browser. The browser then receives this compressed data, decompresses it behind the scenes, and renders everything normally. The end user sees no difference just a faster, snappier experience.</p><p><strong>Before Response Compression What’s Actually Happening?</strong></p><p>Let’s take an real world example</p><p>Imagine you have an ecommerce site. A user opens the product listing page and the browser sends a request to the server asking for 50 products. The server processes this request, fetches the data, and builds a JSON response product names, prices, images URLs, descriptions, stock status and so on. In its raw uncompressed form, this JSON is about 100KB(just prediction).</p><p>Now here’s where it gets interesting. This 100KB of data doesn’t fly over the internet in one shot. It gets broken down into smaller chunks called <strong>packets </strong>each roughly 10KB. So to deliver that one JSON response, the network has to send <strong>10 separate packets</strong> from the server to the browser.</p><p>And here’s the risk the more packets travelling across the network, the higher the chance of <strong>packet loss</strong>. A packet gets dropped, the browser has to request it again, and suddenly your response that should have taken milliseconds is now delayed. On top of that, you’re consuming more bandwidth for every single request, which directly adds to your hosting and infrastructure costs.</p><p>More packets = more risk. More packets = more bandwidth. More bandwidth = more money.</p><p><strong>This is exactly the problem Response Compression solves.</strong></p><p>Now let’s take the same example the browser requests 50 products, the server builds the JSON response, and it’s sitting at <strong>100KB</strong> in its raw form.</p><p>But this time, before the server sends it over the network, it does something smart ,it <strong>compresses the JSON</strong> using a compression algorithm like <strong>Gzip</strong> or <strong>Brotli</strong>.</p><p>Here’s how the algorithm works in brief. It scans through the entire JSON and looks for <strong>patterns and repetitions</strong>. And JSON is full of them think about it, in a 50 product response you’ll have the key “pricee” repeated 50 times, “product_id” repeated 50 times, and so on. Instead of writing out these keys in full every single time, the algorithm says <strong>&quot;I&#39;ll replace this repeated pattern with a tiny symbol&quot;</strong>. On the other end, it knows exactly what each symbol means and expands everything back to its original form. The content is 100% identical just represented in a far more efficient way.</p><p>The result- <strong>100KB JSON shrinks down to roughly 50KB</strong> sometimes even less depending on how repetitive the data is.</p><p>Now instead of breaking into <strong>10 packets</strong> and sending them across the network, the server only needs to send <strong>5 packets</strong>. Half the packets, half the risk of packet loss, half the bandwidth consumed and a significantly faster response reaching the browser.</p><p>The browser receives the compressed data, decompresses it instantly in the background, and renders the products on screen. The user sees nothing different just a faster, smoother experience.</p><p><strong>What’s Happening Behind the Scenes?</strong></p><p>This whole compression process works because of a silent conversation happening between the browser and the server through HTTP headers.</p><p>When the browser sends a request, it doesn’t just ask for data it also tells the server what it is capable of handling. It sends a header called <strong>Accept-Encoding</strong> saying <strong>“Hey, I understand gzip and brotli compression, feel free to compress the response.”</strong></p><p>The server receives this, compresses the JSON, and sends it back with a header called <strong>Content-Encoding</strong> saying <strong>“I’ve compressed this in gzip, decompress it on your end.”</strong></p><p>The browser reads that header, decompresses the data silently in the background, and hands over the clean readable JSON to your application.</p><p>The whole thing happens in milliseconds, completely invisible to the user and even to the developer. You don’t write any special code to handle it on the frontend the browser takes care of it automatically.</p><p>let’s look at the actual numbers from a real test run on our own API.</p><p>We hit the same endpoint twice once without compression and once with compression. The results speak for themselves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*3y1pf1Cdg8MZK5jMqe0xBQ.png" /></figure><p>From <strong>16,781 bytes</strong> down to just <strong>703 bytes</strong> that’s a <strong>95% reduction</strong> in size, and the response time dropped from <strong>0.003664s</strong> to <strong>0.003486s</strong>. Same data, fraction of the size.</p><p><strong>Implementation</strong></p><p>One way to implement this is using the compression package a middleware officially maintained by the Express team.Its a global middleware meaning every single request that hits the server automatically gets compressed without any extra work per route.</p><p>But what makes it even better is the fine tuning it offers. The <strong>level</strong> config controls how aggressively the data is compressed, ranging from 1 to 9 where 1 is the fastest but least compressed and 9 is the most compressed but heaviest on performance a sweet spot of 6 works great for most cases. The <strong>threshold</strong> config is equally important since compression consumes CPU resources, you don’t want to waste that power on tiny responses that are already small. Threshold lets you set a minimum size limit so only responses larger than that value get compressed, keeping your CPU free from unnecessary overhead.</p><p><a href="https://www.npmjs.com/package/compression?activeTab=readme">https://www.npmjs.com/package/compression?activeTab=readme</a></p><p>Response Compression is one of those rare optimizations that costs almost nothing, and delivers real measurable impact. With this we can cut our response sizes dramatically, reduce bandwidth consumption, speed up our APIs and give the users a noticeably faster experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c02bb916b07" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>