<?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 Bendesai on Medium]]></title>
        <description><![CDATA[Stories by Bendesai on Medium]]></description>
        <link>https://medium.com/@bendesai5703?source=rss-263fc5bf098a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QRycoKc33AOCYR0S</url>
            <title>Stories by Bendesai on Medium</title>
            <link>https://medium.com/@bendesai5703?source=rss-263fc5bf098a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:19:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bendesai5703/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[Understanding JDK, JRE, and JVM: The Complete Java Execution Flow]]></title>
            <link>https://medium.com/@bendesai5703/understanding-jdk-jre-and-jvm-the-complete-java-execution-flow-33409e63f68c?source=rss-263fc5bf098a------2</link>
            <guid isPermaLink="false">https://medium.com/p/33409e63f68c</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-full-stack-developer]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Bendesai]]></dc:creator>
            <pubDate>Thu, 18 Jun 2026 06:29:43 GMT</pubDate>
            <atom:updated>2026-06-18T06:29:43.945Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re learning Java, you’ve probably heard the terms <strong>JDK</strong>, <strong>JRE</strong>, and <strong>JVM</strong>. These are the foundation of the Java ecosystem and are among the most frequently asked topics in Java interviews.</p><p>While many developers use these terms interchangeably, they serve very different purposes. In this article, we’ll understand the difference between JDK, JRE, and JVM, and then walk through what happens internally when you run a simple Java program.</p><h3>The Java Program</h3><p>Let’s start with a simple example:</p><pre>public class Main {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Hello World&quot;);<br>    }<br>}</pre><p>Before understanding how this code executes, we need to understand the three major components involved.</p><h3>What is JVM?</h3><p><strong>JVM (Java Virtual Machine)</strong> is the engine responsible for executing Java bytecode.</p><p>When you write Java code, the JVM does not execute the source code directly. Instead, it executes the compiled bytecode generated by the Java compiler.</p><p>The JVM is responsible for:</p><ul><li>Loading classes into memory</li><li>Verifying bytecode</li><li>Executing instructions</li><li>Managing memory</li><li>Performing Garbage Collection</li><li>Providing platform independence</li></ul><p>The JVM is the reason a Java application can run on Windows, Linux, or macOS without changing the source code.</p><h3>Key Point</h3><p>The JVM understands <strong>bytecode (.class files)</strong>, not <strong>Java source code (.java files)</strong>.</p><h3>What is JRE?</h3><p><strong>JRE (Java Runtime Environment)</strong> provides everything required to run a Java application.</p><p>It includes:</p><ul><li>JVM</li><li>Core Java libraries</li><li>Runtime components</li></ul><p>Think of the JRE as a package that contains the JVM along with the supporting libraries required by Java programs.</p><p>If you only want to run Java applications, the JRE is enough.</p><h3>What is JDK?</h3><p><strong>JDK (Java Development Kit)</strong> is the complete toolkit used by Java developers.</p><p>It includes:</p><ul><li>JRE</li><li>Java Compiler (javac)</li><li>Debugging tools</li><li>Documentation tools</li><li>Development utilities</li></ul><p>When you write and compile Java code, you’re using tools provided by the JDK.</p><p>For example:</p><pre>javac Main.java</pre><p>The javac compiler comes from the JDK.</p><p>Without the JDK, you cannot compile Java source code.</p><h3>JDK vs JRE vs JVM</h3><p>FeatureJVMJREJDKExecutes Java Programs✅✅✅Contains JVM❌✅✅Contains Java Libraries❌✅✅Contains Compiler (javac)❌❌✅Used for Development❌❌✅Used for Running Applications✅✅✅</p><h3>Relationship</h3><p>The relationship between them is:</p><p><strong>JDK → JRE → JVM</strong></p><p>This means:</p><ul><li>JDK contains JRE</li><li>JRE contains JVM</li></ul><p>A simple analogy:</p><ul><li>JVM = Engine</li><li>JRE = Car</li><li>JDK = Factory that builds the car</li></ul><h3>What Happens When You Run a Java Program?</h3><p>Now let’s understand what happens behind the scenes when we run:</p><pre>public class Main {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Hello World&quot;);<br>    }<br>}</pre><h3>Step 1: Writing the Source Code</h3><p>The code is written and saved as:</p><pre>Main.java</pre><p>At this stage, the file contains human-readable source code.</p><p>The operating system cannot execute this code directly.</p><h3>Step 2: Compilation</h3><p>The Java compiler converts the source code into bytecode.</p><p>Command:</p><pre>javac Main.java</pre><p>During compilation, the compiler:</p><ul><li>Performs lexical analysis</li><li>Checks syntax</li><li>Validates semantics</li><li>Generates bytecode</li></ul><p>If everything is correct, a new file is created:</p><pre>Main.class</pre><p>This file contains platform-independent bytecode.</p><h3>Step 3: Bytecode Generation</h3><p>The compiler produces bytecode that can run on any system with a JVM.</p><p>The process looks like this:</p><pre>Main.java → javac → Main.class</pre><p>This is the foundation of Java’s “Write Once, Run Anywhere” philosophy.</p><h3>Step 4: JVM Startup</h3><p>When we execute:</p><pre>java Main</pre><p>the JVM starts running.</p><p>During startup, the JVM creates important runtime memory areas such as:</p><ul><li>Heap Memory</li><li>Stack Memory</li><li>Method Area</li><li>Program Counter Register</li><li>Native Method Stack</li></ul><p>These memory areas are used throughout the program’s execution.</p><h3>Step 5: Class Loading</h3><p>The JVM’s Class Loader Subsystem loads the required classes into memory.</p><p>This includes:</p><ul><li>Main.class</li><li>java.lang.Object</li><li>java.lang.String</li><li>java.lang.System</li><li>Other required Java classes</li></ul><p>Java uses different class loaders to load these classes efficiently.</p><h3>Step 6: Bytecode Verification</h3><p>Before execution begins, the JVM verifies the bytecode.</p><p>It checks for:</p><ul><li>Invalid instructions</li><li>Illegal memory access</li><li>Type mismatches</li><li>Stack integrity issues</li></ul><p>This verification step is one reason Java is considered secure.</p><h3>Step 7: Linking</h3><p>After loading classes, the JVM performs linking.</p><p>Linking consists of:</p><h3>Verification</h3><p>Ensures bytecode is valid.</p><h3>Preparation</h3><p>Allocates memory for static variables.</p><h3>Resolution</h3><p>Converts symbolic references into actual memory references.</p><h3>Step 8: Initialization</h3><p>Static variables and static blocks are initialized.</p><p>For example:</p><pre>static {<br>    System.out.println(&quot;Initializing...&quot;);<br>}</pre><p>would execute before the main() method.</p><p>Since our example has no static blocks, initialization is minimal.</p><h3>Step 9: Finding the Main Method</h3><p>The JVM searches for:</p><pre>public static void main(String[] args)</pre><p>This method serves as the entry point of the application.</p><p>Execution begins here.</p><h3>Step 10: Stack Frame Creation</h3><p>A stack frame is created for the main() method.</p><p>The frame stores:</p><ul><li>Local variables</li><li>Method parameters</li><li>Intermediate results</li><li>Method execution information</li></ul><p>Every method call creates a new stack frame.</p><h3>Step 11: Executing the Bytecode</h3><p>The JVM’s Execution Engine begins executing instructions.</p><p>For:</p><pre>System.out.println(&quot;Hello World&quot;);</pre><p>the JVM:</p><ol><li>Loads the System class.</li><li>Accesses the static out object.</li><li>Finds the println() method.</li><li>Passes &quot;Hello World&quot; as an argument.</li><li>Sends the output to the console.</li></ol><h3>Step 12: JIT Compilation</h3><p>Modern JVMs include a <strong>Just-In-Time (JIT) Compiler</strong>.</p><p>Instead of repeatedly interpreting bytecode, the JVM identifies frequently executed code and converts it into native machine code.</p><p>This significantly improves performance.</p><p>The flow becomes:</p><pre>Bytecode → JIT Compiler → Native Machine Code</pre><p>For a simple Hello World program, the impact is negligible. For large enterprise applications, JIT optimization is a major performance advantage.</p><h3>Step 13: Displaying the Output</h3><p>The operating system receives the output request and displays:</p><pre>Hello World</pre><p>on the console.</p><h3>Step 14: Program Termination</h3><p>After the main() method finishes execution:</p><ul><li>The stack frame is removed.</li><li>Resources are released.</li><li>The JVM process terminates.</li></ul><p>The program ends successfully.</p><h3>Complete Flow Summary</h3><pre>Main.java<br>   ↓<br>javac Main.java<br>   ↓<br>Main.class (Bytecode)<br>   ↓<br>java Main<br>   ↓<br>JVM Starts<br>   ↓<br>Class Loading<br>   ↓<br>Bytecode Verification<br>   ↓<br>Linking<br>   ↓<br>Initialization<br>   ↓<br>main() Method Execution<br>   ↓<br>JIT Optimization<br>   ↓<br>Hello World Printed<br>   ↓<br>Program Terminates</pre><h3>Final Thoughts</h3><p>Understanding the difference between <strong>JDK</strong>, <strong>JRE</strong>, and <strong>JVM</strong> is essential for every Java developer.</p><ul><li><strong>JDK</strong> is used to develop Java applications.</li><li><strong>JRE</strong> provides the environment required to run them.</li><li><strong>JVM</strong> executes the bytecode and makes Java platform-independent.</li></ul><p>When a Java application runs, it goes through multiple stages including compilation, class loading, bytecode verification, memory allocation, execution, JIT optimization, and termination.</p><p>Mastering these fundamentals will not only help you in interviews but also give you a strong foundation for understanding advanced topics such as JVM internals, Garbage Collection, Multithreading, and Spring Boot.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33409e63f68c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Next.js Is Not a Reliable Choice for Backend APIs]]></title>
            <link>https://medium.com/@bendesai5703/why-next-js-is-not-a-reliable-choice-for-backend-apis-97d86a24b95c?source=rss-263fc5bf098a------2</link>
            <guid isPermaLink="false">https://medium.com/p/97d86a24b95c</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Bendesai]]></dc:creator>
            <pubDate>Fri, 01 May 2026 11:32:53 GMT</pubDate>
            <atom:updated>2026-05-01T11:32:53.741Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0u7K5-hwK8R0nvcWSG9Y5g.png" /></figure><p>Next.js has exploded in popularity over the past few years. It markets itself as a <em>full-stack React framework</em>, promising that you can build both frontend and backend in one place.</p><p>At first glance, that sounds perfect.</p><p>But once you move beyond small projects and start building production-grade systems, cracks begin to show — especially when you try to use Next.js as your backend API layer.</p><p>This article breaks down <strong>why Next.js can be unstable and a poor fit for backend APIs</strong>, particularly in real-world, scalable applications.</p><h3>1. Next.js API Routes Are Not a True Backend</h3><p>Next.js API routes are essentially <strong>serverless functions</strong>, not a traditional backend server.</p><p>That distinction matters.</p><p>Unlike a dedicated backend (Node.js + Express, Fastify, Spring Boot, etc.), Next.js:</p><ul><li>Doesn’t maintain persistent processes</li><li>Treats each request as isolated execution</li><li>Has limited control over connection lifecycle</li></ul><p>This leads to problems like:</p><ul><li>Re-initializing database connections on every request</li><li>Difficulty managing shared state</li><li>Performance overhead due to cold starts</li></ul><p>👉 In short: It behaves more like a <em>function runner</em>, not a <em>backend system</em>.</p><h3>2. Cold Starts Kill Performance</h3><p>If you’re deploying on platforms like Vercel (which Next.js is optimized for), your API routes are serverless.</p><p>That means <strong>cold starts</strong>.</p><p>When a function hasn’t been used recently:</p><ul><li>It spins up from scratch</li><li>Loads dependencies</li><li>Initializes environment</li></ul><p>This adds noticeable latency.</p><p>For user-facing APIs, this becomes unacceptable:</p><ul><li>First request delay</li><li>Inconsistent performance</li><li>Poor UX under low traffic conditions</li></ul><p>Traditional backends don’t have this issue — they stay “warm” and ready.</p><h3>3. Poor Scalability for Complex Systems</h3><p>Next.js API routes work fine for:</p><ul><li>Simple CRUD</li><li>Small apps</li><li>Prototypes</li></ul><p>But they struggle with:</p><ul><li>Microservices architecture</li><li>Background jobs (queues, workers)</li><li>WebSockets or real-time systems</li><li>Long-running processes</li></ul><p>Why?</p><p>Because serverless functions are:</p><ul><li>Stateless</li><li>Time-limited</li><li>Execution-bound</li></ul><p>You cannot reliably build:</p><ul><li>Event-driven systems</li><li>Streaming services</li><li>Persistent workers</li></ul><p>👉 This makes Next.js unsuitable for serious backend engineering.</p><h3>4. Tight Coupling of Frontend and Backend</h3><p>Next.js encourages putting everything in one repo:</p><pre>/app<br>/pages<br>/api</pre><p>While this looks convenient, it introduces <strong>tight coupling</strong>:</p><ul><li>Frontend and backend deployments are linked</li><li>Scaling independently becomes hard</li><li>Backend changes can affect frontend builds</li></ul><p>In larger systems, this becomes a bottleneck.</p><p>A proper architecture separates concerns:</p><ul><li>Frontend → UI layer</li><li>Backend → API/services layer</li></ul><p>Next.js blurs that boundary — and that’s not always a good thing.</p><h3>5. Limited Middleware and Control</h3><p>Backend frameworks like Express or Fastify offer:</p><ul><li>Fine-grained routing</li><li>Middleware pipelines</li><li>Request lifecycle control</li></ul><p>Next.js API routes, on the other hand, are limited:</p><ul><li>Less flexibility in request handling</li><li>No advanced middleware ecosystem</li><li>Harder to implement cross-cutting concerns (auth, logging, rate limiting)</li></ul><p>You often end up reinventing patterns that mature backend frameworks already solved.</p><h3>6. Debugging and Observability Issues</h3><p>Debugging Next.js APIs in production can be frustrating:</p><ul><li>Logs are often platform-dependent (e.g., Vercel logs)</li><li>Limited visibility into execution flow</li><li>Harder to trace issues across requests</li></ul><p>Compare this to:</p><ul><li>Structured logging in backend servers</li><li>Monitoring tools (APM, tracing, metrics)</li></ul><p>Next.js simply doesn’t provide the same level of observability.</p><h3>7. Vendor Lock-In (Especially with Vercel)</h3><p>Next.js works best on Vercel — no surprise there.</p><p>But that creates a hidden risk:</p><ul><li>Your architecture starts depending on Vercel’s serverless model</li><li>Migration becomes harder later</li><li>Cost scaling can become unpredictable</li></ul><p>A standalone backend gives you:</p><ul><li>Cloud flexibility (AWS, GCP, Azure, on-prem)</li><li>Better cost control</li><li>Infrastructure independence</li></ul><h3>8. Not Designed for Backend-Heavy Applications</h3><p>Let’s be clear:</p><p>Next.js is <strong>frontend-first</strong>, not backend-first.</p><p>Its core strengths are:</p><ul><li>Server-side rendering (SSR)</li><li>Static site generation (SSG)</li><li>UI performance optimization</li></ul><p>Backend support is an <em>add-on</em>, not its primary design goal.</p><p>Trying to force it into a backend role leads to:</p><ul><li>Architectural compromises</li><li>Performance issues</li><li>Maintainability problems</li></ul><h3>When Should You Use Next.js API Routes?</h3><p>To be fair, Next.js API routes are useful when:</p><ul><li>You need a quick backend for a frontend app</li><li>You’re building a prototype or MVP</li><li>Your logic is simple and stateless</li></ul><p>But beyond that, you should reconsider.</p><h3>What Should You Use Instead?</h3><p>For serious backend systems, consider:</p><ul><li><strong>Node.js + Express / Fastify</strong> → flexible and mature</li><li><strong>NestJS</strong> → structured, scalable Node.js framework</li><li><strong>Spring Boot</strong> → enterprise-grade backend</li><li><strong>Go / Rust backends</strong> → high-performance systems</li></ul><p>These are built specifically for backend workloads.</p><h3>Final Verdict</h3><p>Next.js is an excellent frontend framework.</p><p>But using it as your primary backend API is often a mistake.</p><p>It introduces:</p><ul><li>Performance inconsistencies</li><li>Scalability limitations</li><li>Architectural constraints</li></ul><p>👉 Treat Next.js API routes as a <em>convenience feature</em>, not a <em>backend replacement</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97d86a24b95c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Next.js 16 + React Query: The Ultimate Guide to Modern Data Fetching, Caching & Performance…]]></title>
            <link>https://medium.com/@bendesai5703/next-js-16-react-query-the-ultimate-guide-to-modern-data-fetching-caching-performance-ac13a62d727d?source=rss-263fc5bf098a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac13a62d727d</guid>
            <category><![CDATA[nextjs-16]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[first-post]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[nextjs-tutorial]]></category>
            <dc:creator><![CDATA[Bendesai]]></dc:creator>
            <pubDate>Sun, 16 Nov 2025 15:42:20 GMT</pubDate>
            <atom:updated>2025-11-16T15:42:20.691Z</atom:updated>
            <content:encoded><![CDATA[<h3>🚀 Next.js 16 + React Query: The Ultimate Guide to Modern Data Fetching, Caching &amp; Performance (2025)</h3><p>Next.js 16 is not just another upgrade — it’s a <strong>complete evolution</strong> in how React apps handle rendering, caching, pre-rendering, and routing. Combined with <strong>React 19.2</strong> and the now-mature <strong>React Compiler</strong>, the DX feels like magic.</p><p>But here’s the real game changer:</p><h3>Next.js 16 Cache Components + Client-Side React Query = The Perfect Full-Stack Data Strategy</h3><p>This blog explores:</p><ul><li>What’s new in <strong>Next.js 16</strong></li><li>Why <strong>React Query</strong> STILL matters in 2025</li><li>Advanced patterns for combining <strong>RSC + React Query</strong></li><li><strong>Server Actions</strong>, <strong>cache tags</strong>, <strong>PPR</strong>, and <strong>hydration</strong></li><li>Complete <strong>code snippets</strong> for real projects</li></ul><p>Let’s dive in. 🔥</p><h3>🧠 Why Next.js 16 Changed Everything</h3><p>Next.js 16 introduces major architecture shifts:</p><h3>✅ 1. Cache Components (&quot;use cache&quot;)</h3><pre>&quot;use cache&quot;;</pre><pre>export const getPosts = async () =&gt; {<br>  const res = await fetch(&quot;https://api.example.com/posts&quot;, {<br>    next: { tags: [&quot;posts&quot;], revalidate: 3600 },<br>  });<br>  return res.json();<br>};</pre><p>This allows you to cache <strong>entire components</strong> or <strong>server functions</strong>.<br> Lightning fast, built-in SSR caching + tagging.</p><h3>✅ 2. New Invalidation APIs</h3><h4>Revalidate after some time</h4><pre>import { revalidateTag } from &quot;next/cache&quot;;</pre><pre>export async function revalidatePosts() {<br>  &quot;use server&quot;;<br>  revalidateTag(&quot;posts&quot;, &quot;hours&quot;);<br>}</pre><h4>Instant invalidation (read-your-writes)</h4><pre>import { updateTag } from &quot;next/cache&quot;;</pre><pre>export async function updatePostsInstantly() {<br>  &quot;use server&quot;;<br>  updateTag(&quot;posts&quot;);<br>}</pre><h3>✅ 3. refresh() API (Server Actions Only)</h3><p>Refreshes <strong>only the uncached data</strong> — no unnecessary re-renders.</p><pre>&quot;use server&quot;;</pre><pre>import { refresh } from &quot;next/navigation&quot;;</pre><pre>export async function refreshPage() {<br>  refresh();<br>}</pre><h3>✅ 4. Turbopack is the Default 🏎️</h3><p>Up to <strong>10× faster HMR</strong>, <strong>5× faster builds</strong>.</p><h3>✅ 5. proxy.ts replaces middleware.ts</h3><pre>// proxy.ts<br>export default function proxy(request: Request) {<br>  return fetch(request);<br>}</pre><p>Cleaner API, more predictable architecture.</p><h3>🧩 Where React Query Fits Into This New Architecture</h3><p>With all this server-side caching power, some devs think React Query is “not needed anymore”.</p><p>Wrong.<br> React Query is still critically important — <strong>but in the RIGHT place</strong>.</p><h3>Use Server Components (RSC) for:</h3><p>✔ SEO<br> ✔ Public data<br> ✔ Cached static-like data<br> ✔ Layout-level content</p><h3>Use React Query for:</h3><p>✔ Client interactions<br> ✔ Infinite scroll<br> ✔ Real-time updates<br> ✔ Live dashboards<br> ✔ Forms + optimistic updates<br> ✔ User-specific data</p><p><strong>Next.js 16 + React Query is a hybrid architecture.</strong></p><h3>🔥 Advanced Setup: React Query in Next.js 16 (With RSC Prefetching)</h3><p>This is the <strong>best modern approach</strong>, used by top companies.</p><h3>Step 1 — Create a Request-Scoped Query Client</h3><pre>// lib/getQueryClient.ts<br>import { QueryClient } from &quot;@tanstack/react-query&quot;;<br>import { cache } from &quot;react&quot;;</pre><pre>export const getQueryClient = cache(() =&gt; new QueryClient());</pre><h3>Step 2 — Prefetch Data in a Server Component</h3><pre>// app/posts/page.tsx<br>import { getQueryClient } from &quot;@/lib/getQueryClient&quot;;<br>import { dehydrate } from &quot;@tanstack/react-query&quot;;<br>import Hydrate from &quot;@/components/Hydrate&quot;;<br>import Posts from &quot;@/components/Posts&quot;;<br>import { fetchPosts } from &quot;@/services/posts&quot;;</pre><pre>export default async function Page() {<br>  const queryClient = getQueryClient();</pre><pre>  await queryClient.prefetchQuery({<br>    queryKey: [&quot;posts&quot;],<br>    queryFn: fetchPosts,<br>  });</pre><pre>  return (<br>    &lt;Hydrate state={dehydrate(queryClient)}&gt;<br>      &lt;Posts /&gt;<br>    &lt;/Hydrate&gt;<br>  );<br>}</pre><h3>Step 3 — Hydrate on the Client</h3><pre>// components/Hydrate.tsx<br>&quot;use client&quot;;</pre><pre>import { HydrationBoundary, QueryClientProvider } from &quot;@tanstack/react-query&quot;;<br>import { queryClient } from &quot;@/lib/react-query-client&quot;;</pre><pre>export default function Hydrate({ state, children }) {<br>  return (<br>    &lt;QueryClientProvider client={queryClient}&gt;<br>      &lt;HydrationBoundary state={state}&gt;{children}&lt;/HydrationBoundary&gt;<br>    &lt;/QueryClientProvider&gt;<br>  );<br>}</pre><h3>Step 4 — Use React Query in the Client Component</h3><pre>// components/Posts.tsx<br>&quot;use client&quot;;</pre><pre>import { useQuery } from &quot;@tanstack/react-query&quot;;<br>import { fetchPosts } from &quot;@/services/posts&quot;;</pre><pre>export default function Posts() {<br>  const { data, isPending, isError } = useQuery({<br>    queryKey: [&quot;posts&quot;],<br>    queryFn: fetchPosts,<br>  });</pre><pre>  if (isPending) return &lt;p&gt;Loading...&lt;/p&gt;;<br>  if (isError) return &lt;p&gt;Error...&lt;/p&gt;;</pre><pre>  return (<br>    &lt;ul className=&quot;space-y-2&quot;&gt;<br>      {data.map((post) =&gt; (<br>        &lt;li key={post.id} className=&quot;p-4 rounded-xl bg-neutral-900&quot;&gt;<br>          {post.title}<br>        &lt;/li&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>}</pre><h3>🧨 Client → Server Sync with Server Actions + React Query</h3><h3>Mutation on the client:</h3><pre>const mutation = useMutation({<br>  mutationFn: (data) =&gt; createPost(data),<br>  onSuccess: () =&gt; {<br>    queryClient.invalidateQueries([&quot;posts&quot;]);<br>  }<br>});</pre><h3>Server Action:</h3><pre>&quot;use server&quot;;</pre><pre>import { updateTag } from &quot;next/cache&quot;;</pre><pre>export async function createPost(data) {<br>  await fetch(&quot;/api/posts&quot;, {<br>    method: &quot;POST&quot;,<br>    body: JSON.stringify(data),<br>  });</pre><pre>  updateTag(&quot;posts&quot;); // Instant cache invalidation<br>}</pre><p>This gives you:</p><ul><li><strong>Fast UI</strong> (React Query)</li><li><strong>Instant SSR cache syncing</strong> (Next.js tags)</li></ul><p>Perfect consistency.</p><h3>⚡ Example: Optimistic UI with React Query</h3><pre>const mutation = useMutation({<br>  mutationFn: updateTodo,<br>  onMutate: async (updatedTodo) =&gt; {<br>    await queryClient.cancelQueries([&quot;todos&quot;]);<br> const previous = queryClient.getQueryData([&quot;todos&quot;]);<br>    queryClient.setQueryData([&quot;todos&quot;], (old) =&gt;<br>      old.map((item) =&gt;<br>        item.id === updatedTodo.id ? { ...item, ...updatedTodo } : item<br>      )<br>    );<br>    return { previous };<br>  },<br>  onError: (err, variables, context) =&gt; {<br>    queryClient.setQueryData([&quot;todos&quot;], context.previous);<br>  },<br>  onSettled: () =&gt; {<br>    queryClient.invalidateQueries([&quot;todos&quot;]);<br>  },<br>});</pre><p>Optimistic UI + RSC cached components = <strong>the fastest UX possible.</strong></p><h3>🔥 Best Practices for Next.js 16 + React Query (2025 Edition)</h3><h3>1. SSR public data → use Server Components</h3><p>Use &quot;use cache&quot; and tags.</p><h3>2. Private or interactive data → React Query</h3><p>Never use RSC for user-specific or real-time data.</p><h3>3. Mutations → Server Actions</h3><p>Let React Query handle client cache,<br> let Next.js handle server cache.</p><h3>4. Use updateTag() over revalidateTag()</h3><p>If you want instant UI sync.</p><h3>5. Use refresh() sparingly</h3><p>Use only when you need partial refresh.</p><h3>6. Avoid fetch in Client Components</h3><p>Always use React Query for client fetching.</p><h3>7. Use Turbopack &amp; React Compiler</h3><p>You get auto-memoization + faster reloads.</p><h3>🏁 Final Thoughts</h3><p>Next.js 16 represents a <strong>new era</strong> in web development:</p><ul><li>Cached server components</li><li>Partial pre-rendering</li><li>New invalidation APIs</li><li>React 19.2</li><li>Turbo rendering stack</li><li>Better routing architecture</li></ul><p>React Query remains the <strong>gold standard</strong> for managing client-side state and interactive UIs.</p><p>Together, they form a <strong>superpower architecture</strong> that is now used by:</p><ul><li>Vercel</li><li>Netflix</li><li>PayPal</li><li>DigitalOcean</li></ul><p>And thousands of modern React app</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac13a62d727d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hello It’s My First Post On Medium]]></title>
            <link>https://medium.com/@bendesai5703/hello-its-my-first-post-on-medium-81b03c320755?source=rss-263fc5bf098a------2</link>
            <guid isPermaLink="false">https://medium.com/p/81b03c320755</guid>
            <dc:creator><![CDATA[Bendesai]]></dc:creator>
            <pubDate>Fri, 26 Jul 2024 15:52:16 GMT</pubDate>
            <atom:updated>2024-07-26T15:52:16.095Z</atom:updated>
            <content:encoded><![CDATA[<p>Happy to contribute here the Content</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81b03c320755" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>