<?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"><channel><title><![CDATA[Roshan]]></title><description><![CDATA[Roshan]]></description><link>https://rosan-shrestha.com.np</link><generator>RSS for Node</generator><lastBuildDate>Wed, 20 May 2026 13:55:58 GMT</lastBuildDate><atom:link href="https://rosan-shrestha.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Modern Databases: The Architecture That’s 10x Faster Without Sacrificing Consistency]]></title><description><![CDATA[As a developer who has spent years optimizing databases for high-traffic applications, I’ve seen a recurring pattern: traditional relational databases struggle once real scale hits. Vertical scaling b]]></description><link>https://rosan-shrestha.com.np/modern-databases-the-architecture-that-s-10x-faster-without-sacrificing-consistency</link><guid isPermaLink="true">https://rosan-shrestha.com.np/modern-databases-the-architecture-that-s-10x-faster-without-sacrificing-consistency</guid><category><![CDATA[amazon-aurora]]></category><category><![CDATA[modern-databases]]></category><category><![CDATA[Compute-Storage Decoupling]]></category><category><![CDATA[cloud architecture]]></category><category><![CDATA[database scaling]]></category><category><![CDATA[PostgreSQL]]></category><category><![CDATA[MySQL]]></category><category><![CDATA[distributed systems]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Wed, 15 Apr 2026 14:40:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/62b9c02ef2e6c7d70c123e7b/8f621e88-511e-4cdc-ba28-46733d697d0c.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As a developer who has spent years optimizing databases for high-traffic applications, I’ve seen a recurring pattern: traditional relational databases struggle once real scale hits. Vertical scaling becomes limiting, failovers are slow, and there’s always a trade-off between performance and consistency.</p>
<p>Then I discovered <strong>modern databases</strong> — specifically Amazon Aurora and DynamoDB — and everything changed.</p>
<p>These aren’t just “managed versions” of MySQL or PostgreSQL. They represent a <strong>complete architectural revolution</strong>: the decoupling of compute from storage. This single design decision delivers massive performance gains, true elasticity, and operational simplicity that legacy systems simply cannot match.</p>
<p>In this deep-dive, I’ll walk you through why modern databases are fundamentally different, how they work under the hood, their real-world benefits, and when you should migrate.</p>
<hr />
<h3>1. Traditional Databases: The Monolithic Era</h3>
<p>Classic databases like MySQL and PostgreSQL were designed for a pre-cloud world. Everything — CPU, memory, and storage — lived on the <strong>same machine</strong>.</p>
<p>When load increased:</p>
<ul>
<li><p>The entire instance slowed down.</p>
</li>
<li><p>You had to upgrade the whole server (expensive and disruptive).</p>
</li>
<li><p>Failover was slow and painful.</p>
</li>
<li><p>Scaling read replicas required complex replication management.</p>
</li>
</ul>
<p>Here’s what that architecture looks like in practice:</p>
<img src="https://d2908q01vomqb2.cloudfront.net/887309d048beef83ad3eabf2a79a64a389ab1c9f/2024/05/17/REVDBBLOG-75-img2.png" alt="" style="display:block;margin:0 auto" />

<p><em>RDS PostgreSQL Multi-AZ setup (traditional model). Synchronous replication across AZs, but everything is still tightly coupled to the primary instance.</em></p>
<p>This monolithic design worked great for small-to-medium workloads. But at scale? It becomes a bottleneck.</p>
<hr />
<h3>2. Modern Databases: Compute-Storage Decoupling</h3>
<p>Modern databases flip the script entirely.</p>
<p><strong>Compute Layer</strong> (handles queries, transactions, caching)<br /><strong>Storage Layer</strong> (only responsible for durable, replicated storage)</p>
<p>They communicate over the network, but they scale <strong>independently</strong>.</p>
<p>This is the core innovation behind Amazon Aurora, Google Spanner, and DynamoDB.</p>
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6T2dhoovXNzt0IEgti9ijdf2wN79lzx4YQ-J_35G6SSPYGP7o6Th57KuAmsqlFlfKVInG2kyuqKSQODqySIHiNqHU6LcaDmQxvSlAGlBM5UfD24mJfKghSM0h7h5-H5r4gmVmmdg0fRnf9TV0HiRV0WjVxHDepunlQaU14Ea1EDkGmHmlEccSyAlbK0Wy/s1766/Aurora%20Decoupled%20Architecture.jpg" alt="" style="display:block;margin:0 auto" />

<p><em>Amazon Aurora’s decoupled architecture in detail. The compute node only sends redo logs to the distributed storage layer — no full data pages, no checkpoint stalls.</em></p>
<p>The storage layer uses sophisticated techniques (Aurora’s famous 6-way replication across 3 AZs with quorum writes) to ensure durability while keeping the compute layer lightweight and fast.</p>
<img src="https://docs.aws.amazon.com/images/AmazonRDS/latest/AuroraUserGuide/images/aurora_architecture.png" alt="" style="display:block;margin:0 auto" />

<p>Shared storage volume across Availability Zones. Writer and reader instances share the exact same storage — enabling instant failover and read scaling.</p>
<img src="https://miro.medium.com/v2/resize:fit:1400/1*9wE-5uy6lXFAbPfS4GFKfQ.png" alt="" style="display:block;margin:0 auto" />

<p>Simple view of an Aurora cluster: One writer instance + multiple reader instances, all backed by the same shared storage volume.</p>
<hr />
<h3>3. The Game-Changing Benefits</h3>
<p>This architectural shift unlocks capabilities that were impossible in traditional databases:</p>
<ul>
<li><p><strong>Independent Scaling:</strong> Need more query throughput? Spin up more compute nodes. Storage stays untouched.</p>
</li>
<li><p><strong>Super-Fast Failover:</strong> If the primary compute node fails, another one takes over in seconds — because storage is already consistent and shared.</p>
</li>
<li><p><strong>Instant Read Replicas:</strong> Add readers almost instantly. No heavy replication lag.</p>
</li>
<li><p><strong>Serverless-like Billing:</strong> Pay only for the compute and storage you actually use.</p>
</li>
<li><p><strong>Resilience by Design:</strong> Storage node failures don’t bring down your database.</p>
</li>
</ul>
<p>Here’s Aurora PostgreSQL in action across multiple AZs:</p>
<img src="https://d2908q01vomqb2.cloudfront.net/887309d048beef83ad3eabf2a79a64a389ab1c9f/2024/05/17/REVDBBLOG-75-img1.png" alt="" style="display:block;margin:0 auto" />

<p>Writer + readers across three Availability Zones, all connected to the same distributed storage nodes with continuous backups to S3.</p>
<hr />
<h3>4. The Distributed Systems Reality (The Trade-Off)</h3>
<p>Of course, nothing is free.</p>
<p>In modern databases, writes travel over the network to multiple storage nodes. The final commit latency is determined by the <strong>slowest node</strong> in the quorum. This is the classic challenge of distributed systems — network variability becomes part of the equation.</p>
<p>But Aurora has engineered clever solutions:</p>
<ul>
<li><p>Quorum-based writes (4 out of 6 copies in Aurora)</p>
</li>
<li><p>Log-only shipping instead of full page writes</p>
</li>
<li><p>Optimized networking within AWS regions</p>
</li>
</ul>
<p>The result? You still get strong consistency, but with dramatically higher throughput.</p>
<hr />
<h3>5. When Should You Choose Modern Databases?</h3>
<p><strong>Choose Aurora / Google Spanner / DynamoDB when you need:</strong></p>
<ul>
<li><p>High availability and sub-second failover</p>
</li>
<li><p>Massive read scale (hundreds of readers)</p>
</li>
<li><p>Predictable performance at cloud scale</p>
</li>
<li><p>Pay-as-you-go economics</p>
</li>
<li><p>Multi-AZ or multi-region resilience</p>
</li>
</ul>
<p><strong>Stick with traditional RDS (MySQL/PostgreSQL) only for:</strong></p>
<ul>
<li><p>Very small workloads</p>
</li>
<li><p>Legacy applications with complex stored procedures</p>
</li>
<li><p>Teams that prefer full control over the database engine</p>
</li>
</ul>
<h3>Final Thoughts</h3>
<p>Modern databases aren’t just an incremental improvement — they’re a <strong>paradigm shift</strong> in how we think about data persistence in the cloud era.</p>
<p>The decoupling of compute and storage is the same kind of leap that containers brought to compute and S3 brought to object storage. Once you experience it, going back to monolithic databases feels old-fashioned.</p>
<p>As someone building systems that need to scale reliably, I’ve made a plan to switch to Aurora. The performance, resilience, and developer experience are simply unmatched.</p>
<p>If you’re still running self-managed MySQL/PostgreSQL or even the older RDS models, it might be time to rethink your stack.</p>
<p>The future of databases is decoupled, distributed, and cloud-native.</p>
<p>What’s your experience with modern databases? Have you migrated to Aurora or Spanner yet? Drop your thoughts in the comments — I’d love to hear how these architectures are shaping your projects.</p>
<hr />
<p><strong>Tags:</strong> Amazon Aurora, Modern Databases, Compute-Storage Decoupling, Cloud Architecture, Database Scaling, PostgreSQL, MySQL, Distributed Systems</p>
<p><em>This post is part of my ongoing series on cloud-native architecture and system design. Follow for more deep-dives into scalable systems.</em></p>
]]></content:encoded></item><item><title><![CDATA[Frontend Is Not UI Anymore.]]></title><description><![CDATA[Most developers approach React the wrong way. And, with the evolution of tools that automatically generate code, the learning approach is shrinking day after day.
They focus on mastering components, h]]></description><link>https://rosan-shrestha.com.np/frontend-is-not-ui-anymore</link><guid isPermaLink="true">https://rosan-shrestha.com.np/frontend-is-not-ui-anymore</guid><category><![CDATA[React]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[Design Systems]]></category><category><![CDATA[design thinking]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Tue, 07 Apr 2026 15:52:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/62b9c02ef2e6c7d70c123e7b/703f903c-5b0b-4268-becb-903478e5f8b1.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Most developers approach React the wrong way. And, with the evolution of tools that automatically generate code, the learning approach is shrinking day after day.</p>
<p>They focus on mastering components, hooks, and patterns.</p>
<p>They build clean UIs, memorize useEffect, and feel productive.</p>
<p>It works… until it doesn’t.</p>
<p>Because modern frontend is no longer about components.</p>
<p>It’s about systems.</p>
<hr />
<h3><strong>The Shift No One Talks About</strong></h3>
<p>In interviews and real-world systems, the questions change:</p>
<ul>
<li><p>Design a real-time dashboard</p>
</li>
<li><p>Build a scalable shared state model</p>
</li>
<li><p>Create a reusable component system for multiple teams</p>
</li>
<li><p>Handle offline-first interactions without data loss</p>
</li>
</ul>
<p>None of these care about JSX.</p>
<p>They test how you think about architecture inside the browser.</p>
<hr />
<h3><em><strong>Frontend = System Design (Inside the Browser)</strong></em></h3>
<p>Let’s break down what that actually means.</p>
<ol>
<li><strong>State Topology: Designing the Source of Truth</strong></li>
</ol>
<p>A scalable frontend system separates three types of state:</p>
<ul>
<li><p><strong>Server state</strong> → Comes from APIs, needs caching, syncing, revalidation</p>
</li>
<li><p><strong>Global client state</strong> → Shared across features (auth, theme, user data)</p>
</li>
<li><p><strong>Local/UI state</strong> → Component-specific (modals, inputs, toggles)</p>
</li>
</ul>
<p>Key Decisions:</p>
<ul>
<li><p>What is the single source of truth?</p>
</li>
<li><p>What should persist across refreshes or crashes?</p>
</li>
<li><p>What happens when the user goes offline?</p>
</li>
</ul>
<p>Common mistake: Putting everything in global state or everything inside components.</p>
<p><strong>2.Data Flow &amp; Consistency: Handling Real-World Chaos</strong></p>
<p>In real applications, data is messy.</p>
<p>You deal with:</p>
<ul>
<li><p>Partial responses</p>
</li>
<li><p>Stale caches</p>
</li>
<li><p>Retry logic</p>
</li>
<li><p>Race conditions</p>
</li>
</ul>
<p>What you must design:</p>
<ul>
<li><p>When to revalidate vs trust cache</p>
</li>
<li><p>When to use optimistic updates</p>
</li>
<li><p>How to handle failures and rollbacks</p>
</li>
<li><p>How to sync server state with local actions</p>
</li>
</ul>
<p>Tools help, but understanding data flow is what matters.</p>
<p><strong>3.Real-Time Systems: More Than Just Fetching Data</strong></p>
<p>A real-time dashboard is not just about calling APIs repeatedly.</p>
<p>You need to think about:</p>
<ul>
<li><p>Handling high-frequency updates</p>
</li>
<li><p>Preventing UI lag</p>
</li>
<li><p>Batching or throttling updates</p>
</li>
<li><p>Normalizing incoming data</p>
</li>
</ul>
<p>Without this, your UI will freeze under load.</p>
<p><strong>4.Rendering Strategy: Performance Is a Design Problem</strong></p>
<p>Rendering is not automatic—it’s a design decision.</p>
<p>You need to consider:</p>
<ul>
<li><p>What triggers re-renders?</p>
</li>
<li><p>How often does the UI update?</p>
</li>
<li><p>What runs on the main thread?</p>
</li>
</ul>
<p>Key practices:</p>
<ul>
<li><p>Avoid unnecessary re-renders</p>
</li>
<li><p>Use memoization wisely</p>
</li>
<li><p>Batch updates when possible</p>
</li>
</ul>
<p>Fast data + naive rendering = slow UI.</p>
<p><strong>5.Scalable Component Systems</strong></p>
<p>Components are not just reusable UI pieces.</p>
<p>They are APIs for other developers.</p>
<p>You need to think about:</p>
<ul>
<li><p>How will other teams use this component?</p>
</li>
<li><p>What should be customizable?</p>
</li>
<li><p>What should be hidden?</p>
</li>
</ul>
<p>A good component systems:</p>
<ul>
<li><p>Enforce consistency</p>
</li>
<li><p>Prevent misuse</p>
</li>
<li><p>Evolve without breaking existing features</p>
</li>
</ul>
<p>Bad design systems scale problems across teams.</p>
<p><strong>6.Failure-First UX: Designing for When Things Break</strong></p>
<p>Most tutorials assume everything works perfectly.</p>
<p>Real systems don’t.</p>
<p>You must design for:</p>
<ul>
<li><p>Network failures</p>
</li>
<li><p>Interrupted actions</p>
</li>
<li><p>Data conflicts</p>
</li>
</ul>
<p>Ask yourself:</p>
<ul>
<li><p>What happens if the network drops mid-action?</p>
</li>
<li><p>Does the user lose progress?</p>
</li>
<li><p>How does the system recover and sync?</p>
</li>
</ul>
<p>Great UX works even when things go wrong.</p>
<hr />
<h3><strong>The “Vibe Coding” Problem in Modern Frontend</strong></h3>
<p>There’s a growing trend:</p>
<p>Developers “vibe code” frontend using AI tools.</p>
<p>They:</p>
<ul>
<li><p>Prompt UI components</p>
</li>
<li><p>Generate pages instantly</p>
</li>
<li><p>Copy-paste working code</p>
</li>
</ul>
<p>And it feels productive.</p>
<p>Also, A Hidden Risk</p>
<p>You can now build:</p>
<ul>
<li><p>A beautiful dashboard</p>
</li>
<li><p>A working CRUD app</p>
</li>
<li><p>A polished UI</p>
</li>
</ul>
<p>But, Without understanding:</p>
<ul>
<li><p>Where state lives</p>
</li>
<li><p>How data flows</p>
</li>
<li><p>What happens under load</p>
</li>
<li><p>How failures are handled</p>
</li>
</ul>
<p>The result: <strong>Apps that look good but break at scale</strong>.</p>
<hr />
<h3><strong>The New Learning Path</strong></h3>
<p>Don’t stop using AI. Don’t stop building fast.</p>
<p>But upgrade your thinking.</p>
<p>Instead of asking:</p>
<p>“Can I build this UI?”</p>
<p>Start asking:</p>
<ul>
<li><p>What is the source of truth?</p>
</li>
<li><p>How does data flow through the system?</p>
</li>
<li><p>What happens when this fails?</p>
</li>
<li><p>How will this scale across teams?</p>
</li>
</ul>
<hr />
<h3><em><strong>Final Thought</strong></em></h3>
<p>Frontend is no longer about components.</p>
<p>It’s about designing systems that render UI.</p>
<p>And in a world of vibe coding, the developers who understand systems…</p>
<p>…are the ones who stand out.</p>
]]></content:encoded></item><item><title><![CDATA[What Really Kills Most Frontend Apps (Hint: It's Not Bad Code)]]></title><description><![CDATA[When users start noticing problems…
❓ Why does my site's First Contentful Paint (FCP) take 5 seconds on a phone?❓ Why does scrolling feel slow or choppy?❓ Why does the app crash after some use?❓ Why does changing one thing refresh half the page unnec...]]></description><link>https://rosan-shrestha.com.np/what-really-kills-most-frontend-apps-hint-its-not-bad-code</link><guid isPermaLink="true">https://rosan-shrestha.com.np/what-really-kills-most-frontend-apps-hint-its-not-bad-code</guid><category><![CDATA[React]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[frontend]]></category><category><![CDATA[Next.js]]></category><category><![CDATA[Lighthouse]]></category><category><![CDATA[memory-management]]></category><category><![CDATA[performance]]></category><category><![CDATA[Performance Optimization]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Wed, 24 Sep 2025 17:57:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1758769982151/16a6c8fd-0f3a-47e4-892c-a035ffcc7d47.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When users start noticing problems…</p>
<p>❓ Why does my site's First Contentful Paint (FCP) take <strong>5 seconds</strong> on a phone?<br />❓ Why does scrolling feel slow or choppy?<br />❓ Why does the app crash after some use?<br />❓ Why does changing one thing refresh half the page unnecessarily?</p>
<p>How have you solved this problem ; you being the developer of your app ?</p>
<p>Many developer fails as they overlook the bigger picture. It’s rare, but sometimes, even when millions of users are happily using your app, issues like slow performance, crashes, or pages not loading can suddenly appear. Performance bottlenecks aren’t always React-specific or other frontend tech-stack specific.</p>
<p>More often, they live in three areas:</p>
<ul>
<li><p>The Build &amp; Network</p>
</li>
<li><p>The Rendering Process</p>
</li>
<li><p>The Browser Itself</p>
</li>
</ul>
<p>Let’s Dive more in details:</p>
<ol>
<li><p>Bundling Blindness</p>
<p> Your bundle is massive. Why?</p>
<ul>
<li><p>The code isn’t split into smaller parts.</p>
</li>
<li><p>Unused code is still included.</p>
</li>
<li><p>Images and files aren’t compressed properly.</p>
<p>  The result? The browser has to download, parse, and execute a <strong>mountain of JavaScript</strong> before anything shows up.</p>
</li>
</ul>
</li>
<li><p>Network Latency</p>
<p> Fast code ≠ fast app.</p>
<p> If your API is slow, the app feels slow.</p>
<p> Ask yourself: Are you making multiple calls for tiny bits of data?</p>
<p> Consider the following approaches:</p>
<ul>
<li><p>Use <strong>REST endpoints that return everything needed at once</strong></p>
</li>
<li><p>Implement <strong>caching</strong> to avoid repeated requests</p>
</li>
<li><p>Use <strong>pagination or lazy loading</strong> to reduce data per request</p>
</li>
</ul>
</li>
<li><p>Unnecessary Re-renders</p>
</li>
</ol>
<p>Often, the problem isn’t missing <code>React.memo</code>—it’s how you manage state.</p>
<ul>
<li><p>Does changing a global state cause the whole app to re-render?</p>
</li>
<li><p>Could you move state closer to the components that actually need it? Putting in simple way “Prop Drilling”.</p>
</li>
</ul>
<hr />
<p>Beside the above, I’ve noticed that many developers aren’t aware of following issues, so I’ve broken them down and simplified everything as much as possible. Most don’t think about these areas, even though overlooking them can seriously hamper an application’s performance. By understanding and addressing them early, you can save time, frustration, and keep your users happy.</p>
<ol>
<li><p>The Browser Itself</p>
<p> Not all browsers handle JavaScript the same way. An app that runs smoothly in Chrome might lag or freeze in Safari or Firefox, especially during heavy calculations or complex UI updates.</p>
<p> 💡 <strong>Solution:</strong> Test your app across browsers, optimize performance, and use tools like <strong>Web Workers</strong> for heavy tasks so every user gets a smooth experience.</p>
</li>
<li><p>Memory Leaks</p>
<p> Sometimes your app keeps holding onto things it doesn’t need: Unsubscribed event listeners, forgotten timers, or unmanaged state.</p>
<p> Memory usage climbs… until your app <strong>crashes</strong>.</p>
</li>
</ol>
<hr />
<p>👉 Tools you should always have in your workflow:</p>
<ul>
<li><p><strong>Chrome DevTools Performance tab</strong></p>
</li>
<li><p><strong>Lighthouse audits</strong></p>
</li>
<li><p><strong>Network request analysis</strong></p>
</li>
</ul>
<p>Performance issues in frontend apps can come from many places. But, frontend performance isn’t just about writing fast code—it’s about the whole environment your app runs in.</p>
<p>✅ Audit your bundles to remove unused code.<br />✅ Optimize your APIs to reduce latency.<br />✅ Manage state smartly to avoid unnecessary re-renders.<br />✅ Profile memory usage to prevent leaks.<br />✅ Test across browsers to handle different behaviors.</p>
<p>Because <strong>Frontend Performance</strong> isn’t just code—it’s the <strong>ecosystem</strong> around it.</p>
]]></content:encoded></item><item><title><![CDATA[OAuth vs JWT — The Difference Every Developer Should Know]]></title><description><![CDATA[If you’ve ever been confused between OAuth and JWT, you’re not alone. Many developers mix them up because they often appear together in modern applications. But here’s the truth: OAuth is not JWT, and JWT is not OAuth. They are different, but they wo...]]></description><link>https://rosan-shrestha.com.np/oauth-vs-jwt</link><guid isPermaLink="true">https://rosan-shrestha.com.np/oauth-vs-jwt</guid><category><![CDATA[oauth]]></category><category><![CDATA[JWT]]></category><category><![CDATA[keycloak]]></category><category><![CDATA[SSO]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Thu, 14 Aug 2025 16:35:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1755189166147/8be6245b-1a08-4387-87dc-d62a018c415e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you’ve ever been confused between <strong>OAuth</strong> and <strong>JWT</strong>, you’re not alone. Many developers mix them up because they often appear together in modern applications. But here’s the truth: <strong>OAuth is not JWT</strong>, and <strong>JWT is not OAuth</strong>. They are different, but they work well together. Let’s understand them in the simplest way possible.</p>
<hr />
<h2 id="heading-what-is-oauth"><strong>What is OAuth?</strong></h2>
<p>OAuth is an <strong>authorization framework</strong> — it’s about permissions, not passwords. It allows one application to securely access another application’s data without asking for the user’s password.</p>
<p><strong>Example:</strong><br />When you click <strong>“Login with Gmail”</strong> or <strong>“Continue with GitHub”</strong>, you’re using OAuth. The app you’re logging into never sees your Gmail or GitHub password. Instead, OAuth gives the app a <strong>temporary key</strong> to perform certain actions, like reading your email address or accessing your profile, for a limited time.</p>
<p><strong>Purpose:</strong><br />Grant <strong>limited</strong> and <strong>time-bound</strong> access securely — like giving someone a key to <strong>one room</strong> in your house, not the whole house.</p>
<hr />
<h2 id="heading-what-is-jwt"><strong>What is JWT?</strong></h2>
<p>JWT stands for <strong>JSON Web Token</strong>. It’s a small, self-contained piece of data that proves your identity or permissions.</p>
<p><strong>Think of it as:</strong><br />A <strong>digital passport</strong> your application can show when it needs to prove who you are or what you’re allowed to do.</p>
<p>A JWT usually contains:</p>
<ul>
<li><p><strong>User identity</strong> (who you are)</p>
</li>
<li><p><strong>Expiry time</strong> (how long it’s valid)</p>
</li>
<li><p><strong>Signature</strong> (to ensure it hasn’t been changed)</p>
</li>
</ul>
<p><strong>Common Uses:</strong></p>
<ul>
<li><p>Authenticating users in SPAs (Single Page Applications)</p>
</li>
<li><p>Securing API requests</p>
</li>
<li><p>Managing sessions without storing them on the server</p>
</li>
</ul>
<hr />
<h2 id="heading-how-they-work-together"><strong>How They Work Together</strong></h2>
<p>Here’s how it works if your app has a <strong>“Login with Gmail”</strong> button:</p>
<ol>
<li><p>You click the button.</p>
</li>
<li><p><strong>OAuth</strong> handles the secure login and permission flow with Gmail.</p>
</li>
<li><p>Gmail sends back a token — often a <strong>JWT</strong>.</p>
</li>
<li><p>Your app stores this JWT securely (e.g., in an HttpOnly cookie or memory).</p>
</li>
<li><p>Whenever you make API requests, you attach this JWT to prove your identity and access rights.</p>
</li>
</ol>
<hr />
<h2 id="heading-the-key-difference"><strong>The Key Difference</strong></h2>
<ul>
<li><p><strong>OAuth</strong> = <em>How you get access</em></p>
</li>
<li><p><strong>JWT</strong> = <em>The proof you have access</em></p>
</li>
</ul>
<p><strong>Without OAuth</strong>, you wouldn’t get the JWT.<br /><strong>Without JWT</strong>, you couldn’t prove you belong.</p>
<hr />
<h2 id="heading-conclusion">Conclusion</h2>
<p>OAuth and JWT are often mentioned together, but they solve <strong>different problems</strong>.</p>
<ul>
<li><p><strong>OAuth</strong> is all about the <strong>process of getting access</strong> — deciding <em>who</em> can do <em>what</em>.</p>
</li>
<li><p><strong>JWT</strong> is about <strong>carrying proof</strong> — showing you have the right to do it.</p>
</li>
</ul>
<p>Think of OAuth as the <strong>security check</strong> and JWT as the <strong>pass</strong> you carry afterward.</p>
<p>When combined, they make applications both <strong>secure</strong> and <strong>user-friendly</strong> — protecting user data while providing smooth login and authorization flows.</p>
<p>If you’re a developer, understanding the difference will save you from <strong>common mistakes</strong> and help you design <strong>better, more secure applications</strong>.</p>
]]></content:encoded></item><item><title><![CDATA[TypeScript to Go 10X Faster !!!]]></title><description><![CDATA[According to TypeScript’s official announcement, they are fully rewriting TypeScript in Go, achieving a 10x speedup.
To get more info about the announcement, follow this Official Typescript Blog Link .
Here’s the some insights I get to know after tak...]]></description><link>https://rosan-shrestha.com.np/typescript-to-go-10x-faster</link><guid isPermaLink="true">https://rosan-shrestha.com.np/typescript-to-go-10x-faster</guid><category><![CDATA[TypeScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[Developer]]></category><category><![CDATA[fullstack]]></category><category><![CDATA[js]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Fri, 14 Mar 2025 04:27:15 GMT</pubDate><content:encoded><![CDATA[<p>According to TypeScript’s official announcement, they are fully rewriting TypeScript in Go, achieving a 10x speedup.</p>
<p>To get more info about the announcement, follow this <a target="_blank" href="https://devblogs.microsoft.com/typescript/typescript-native-port/">Official Typescript Blog Link</a> .</p>
<p>Here’s the some insights I get to know after taking time overviewing the annoucements and reading the blogs which have covered the breaking changes.</p>
<h2 id="heading-will-this-impact-me">Will this impact me?</h2>
<p>TypeScript is being rewritten in <strong>Go</strong>, which will make everything <strong>much faster</strong> for developers. Here’s how it helps:</p>
<ul>
<li><p><strong>Faster Coding Experience</strong> – Your code editor (like VS Code) will respond <strong>10x faster</strong> when showing errors, suggestions, and navigating through code. This is especially helpful for large projects.</p>
</li>
<li><p><strong>Faster Compilation</strong> – The TypeScript compiler (<code>tsc</code>) will work <strong>10x faster</strong>, making your projects build quickly. This also means <strong>faster CI/CD pipelines</strong>, so deploying apps will take less time.</p>
</li>
</ul>
<p>Simply put, everything you do with TypeScript will become <strong>way smoother and quicker</strong> which means <em>“ IT IMPROVE DX FOR EVERY TYPESCRIPT DEVELOPERS.”</em></p>
<h2 id="heading-need-to-update-my-code">Need to update my code?</h2>
<p>The answer is NO. The code remains the same.</p>
<h2 id="heading-why-not-rust">Why Not Rust?</h2>
<p>Well, the typescript team has put the reason for choosing Go behind all others in its github discussion. Here’s the link: <a target="_blank" href="https://github.com/microsoft/typescript-go/discussions/411">https://github.com/microsoft/typescript-go/discussions/411</a> .</p>
<p>Go was the best choice mainly because it is very similar to JavaScript in structure. Its coding style is a lot like TypeScript’s current setup, making the transition smoother.</p>
<h2 id="heading-why-not-make-the-javascript-code-faster-instead">Why not make the JavaScript code faster instead?</h2>
<p>I found the topic covered watching the videos in youtube, sharing their views on javascript and typescript. To simply put this on the table, <strong>JavaScript runs on a single thread</strong>, meaning it can only handle one task at a time. The reason JavaScript itself wasn't optimized for speed. While upcoming features like <strong>Shared Structs</strong> may improve this in the future, they aren’t fully developed yet. On the other hand, languages like <strong>Go and Rust</strong> have <strong>built-in multi-threading support</strong>, allowing them to use <strong>multiple CPU cores</strong> to process tasks simultaneously. This parallel processing makes them <strong>much faster</strong> than JavaScript, which is why TypeScript is being rewritten in Go instead of trying to speed up the existing JavaScript code.</p>
<h2 id="heading-wanna-try-it-out">Wanna Try It Out?</h2>
<p>Visit the official <a target="_blank" href="https://github.com/microsoft/typescript-go">Typescript-Go repo</a> and follow the instructions to hands on this new and amazing update.</p>
]]></content:encoded></item><item><title><![CDATA[A Beginner’s Guide to OAuth: Secure User Authentication]]></title><description><![CDATA[What is OAuth?
OAuth is the industry standard protocol for secure authorization, enabling applications to access resources on behalf of a user without sharing their credentials. It provides user-consented access and allows restricted actions on resou...]]></description><link>https://rosan-shrestha.com.np/a-beginners-guide-to-oauth-secure-user-authentication</link><guid isPermaLink="true">https://rosan-shrestha.com.np/a-beginners-guide-to-oauth-secure-user-authentication</guid><category><![CDATA[OAuth 2.0]]></category><category><![CDATA[authentication]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Thu, 06 Mar 2025 03:37:12 GMT</pubDate><content:encoded><![CDATA[<h1 id="heading-what-is-oauth">What is OAuth?</h1>
<p><strong>OAuth</strong> is the industry standard protocol for secure authorization, enabling applications to access resources on behalf of a user without sharing their credentials. It provides user-consented access and allows restricted actions on resources. It is a system that helps apps, websites, and devices work together safely. It lets an app use your data from another service (like letting a game use your Google account) without sharing your password. It's used on many platforms like websites, phone apps, and smart devices to keep your information secure while allowing apps to do what you’ve allowed them to.</p>
<h3 id="heading-key-concepts-in-oauth">Key Concepts in OAuth</h3>
<ol>
<li><p><strong>Resource Owner (User):</strong> The user who owns the data and grants permission to the application to access their data.</p>
</li>
<li><p><strong>Client (Application):</strong> The application requesting access to the resource owner's data.</p>
</li>
<li><p><strong>Resource Server:</strong> The server that holds the user's data (e.g., Google, Facebook).</p>
</li>
<li><p><strong>Authorization Server:</strong> The server that issues tokens to the client after authenticating the resource owner and obtaining authorization.</p>
</li>
<li><p><strong>Access Token:</strong> A short-lived token the client uses to access the resource server.</p>
</li>
</ol>
<h2 id="heading-oauth-scopes">OAuth Scopes</h2>
<p>OAuth <strong>scope</strong> defines what specific actions or data an application is allowed to access on behalf of a user. It's like setting boundaries for what an app can do with your account or data. They are used to specify exactly the reason for which access to resources may be granted. It places the payload data in the JWT tokens.</p>
<h3 id="heading-oauth-20-authorization-code-flow"><strong>OAuth 2.0 Authorization Code Flow</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1732417699870/bbd40c7d-cecc-42e0-b946-d4745c65dc14.png" alt="OAuth 2.0 Authorization Code Flow" class="image--center mx-auto" /></p>
<ol>
<li><p><strong>User → Application Client</strong>:</p>
<ul>
<li>The user opens the <strong>Application Client</strong> (like a mobile app or web app) and starts an action that needs access to a protected resource, such as user data from Google or Facebook. It’s a kind of opening the login page of the</li>
</ul>
</li>
<li><p><strong>Application Client → Authorization Page</strong>:</p>
<ul>
<li><p>The <strong>Application Client</strong> redirects the user to the <strong>Authorization Page</strong> (hosted by the <strong>Authorization Server</strong>). The URL typically includes the following:</p>
<ul>
<li><p><code>client_id</code> (the identifier of the application)</p>
</li>
<li><p><code>redirect_uri</code> (where the user will be sent after granting permission)</p>
</li>
<li><p><code>scope</code> (the permissions the app is requesting)</p>
</li>
<li><p><code>response_type=code</code> (indicating the Authorization Code flow)</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>User → Give Access by Clicking Allow → Authorization Page</strong>:</p>
<ul>
<li>The <strong>Authorization Page</strong> presents the user with a login screen (if the user isn't logged in already). The user then enters the userId either username/email and passsword to complete the authentication process. But typically, for granting the access from the third party such as google, github, etc, the system asks them to <strong>grant access</strong> by clicking "Allow" or "Authorize" to give the <strong>Application Client</strong> permission to access their data.</li>
</ul>
</li>
<li><p><strong>Authorization Page → Authorization Server</strong>:</p>
<ul>
<li>Once the user grants permission, the Authorization Page sends them back to the Authorization Server with an authorization code, verifying their consent. How can we understand this one; the system generates the code to exchange the token.</li>
</ul>
</li>
<li><p><strong>Authorization Server → Authorization Page</strong>:</p>
<ul>
<li>The Authorization Server checks the request, and if the user has allowed access, it creates an authorization code. This code is then added to the URL (e.g., <a target="_blank" href="https://client.com/callback?code=AUTHORIZATION_CODE">https://client.com/callback?code=AUTHORIZATION_CODE</a>) and <a target="_blank" href="https://client.com/callback?code=AUTHORIZATION_CODE">sent back to the Authorization Page.</a></li>
</ul>
</li>
<li><p><a target="_blank" href="https://client.com/callback?code=AUTHORIZATION_CODE"><strong>Authoriz</strong></a><strong>ation Page → Application Client</strong>:</p>
<ul>
<li>The Authorization Page sends the user back to the Application Client with an authorization code attached to the redirect link (e.g., <a target="_blank" href="https://client.com/callback?code=AUTHORIZATION_CODE">https://client.com/callback?code=AUTHORIZATION_CODE</a>). It is the same code that will exchange the JWT token.</li>
</ul>
</li>
<li><p><strong>Application Client → Application Server</strong>:</p>
<ul>
<li>The Application Client takes the authorization code it got from the Authorization Page and sends it to its Application Server to ask for an access token.</li>
</ul>
</li>
<li><p><strong>Application Server → Authorization Server</strong>:</p>
<ul>
<li><p>The <strong>Application Server</strong> sends a request to the <strong>Authorization Server's token endpoint</strong>, including:</p>
<ul>
<li><p>The <strong>authorization code</strong> (received from the <strong>Authorization Page</strong>)</p>
</li>
<li><p>The <strong>client secret</strong> (to authenticate the app)</p>
</li>
<li><p>The <strong>redirect URI</strong> (for validation purposes)</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Authorization Server → Application Server</strong>:</p>
<ul>
<li>The Authorization Server checks the request to make sure the authorization code, client ID, and client secret are correct. If everything is valid, it sends back an access token (and sometimes a refresh token). The Application Server can use this access token to make secure API requests.</li>
</ul>
</li>
<li><p><strong>Application Server → Resource (Source) Server</strong>:</p>
</li>
</ol>
<ul>
<li>The Application Server now uses the access token to safely request information from the Resource Server (like Google API or Facebook API). This lets it access the user's protected data, such as profile details or files. The same token can further used in the backend system to authorize the endpoints.</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Authentication vs. Authorization]]></title><description><![CDATA[Introduction:
Authentication and Authorization are two critical terms that form the backbone of security on the internet. Together, they help protect our personal information, prevent unauthorized access, and ensure that only trusted users can access...]]></description><link>https://rosan-shrestha.com.np/authentication-vs-authorization</link><guid isPermaLink="true">https://rosan-shrestha.com.np/authentication-vs-authorization</guid><category><![CDATA[oauth]]></category><category><![CDATA[OAuth 2.0]]></category><category><![CDATA[authentication]]></category><category><![CDATA[authorization]]></category><category><![CDATA[Auth ]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Wed, 13 Nov 2024 08:08:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1731484983189/07c9b1c8-2bc4-4ce4-9c11-bc5d6300df8c.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction:</h2>
<p><strong>Authentication</strong> and <strong>Authorization</strong> are two critical terms that form the backbone of security on the internet. Together, they help protect our personal information, prevent unauthorized access, and ensure that only trusted users can access certain features or data.</p>
<p>To make things simple and sound, imagine you’re at the entrance of a big concert. To get inside, you need to show your ticket and maybe even prove who you are. But once you’re in, there are certain areas you can and can’t go. This is a lot like how <strong>Authentication</strong> and <strong>Authorization</strong> work on the internet!</p>
<p>Let’s make a deeper dive into each term and why they’re so essential for security on the internet.</p>
<h2 id="heading-what-is-authentication">What is Authentication?</h2>
<p><strong>Authentication</strong> is like proving who you are. It’s a process that helps a system verify that you are actually who you claim to be.</p>
<h4 id="heading-example"><strong>Example:</strong></h4>
<p>Imagine you have a school ID card. When you show it to the school gatekeeper, they let you in because they recognize that you’re a student there.</p>
<ul>
<li><strong>In the digital world</strong>: Authentication often involves things like entering a username and password. If you enter the right information, the system lets you in, just like the gatekeeper at school.</li>
</ul>
<h4 id="heading-why-is-authentication-important"><strong>Why is Authentication Important?</strong></h4>
<ol>
<li><p><strong>Protects Personal Data</strong>: Think about all the personal details you store online – your social media profiles, email, bank accounts, and more. Authentication ensures that only you (or someone with your permission) can access this information.</p>
</li>
<li><p><strong>Prevents Fraud</strong>: By confirming a user’s identity, authentication helps prevent fraud. It stops people from pretending to be someone else, which is crucial in financial transactions, healthcare, and other sensitive areas.</p>
</li>
</ol>
<h4 id="heading-common-ways-to-authenticate"><strong>Common Ways to Authenticate:</strong></h4>
<ol>
<li><p><strong>Passwords</strong> – Like a secret code only you know.</p>
</li>
<li><p><strong>OTP (One-Time Password)</strong> – A unique number sent to your phone that you use just once.</p>
</li>
<li><p><strong>Biometrics</strong> – Like using your fingerprint or face recognition.</p>
</li>
</ol>
<h2 id="heading-what-is-authorization">What is Authorization?</h2>
<p><strong>Authorization</strong> is about deciding what you’re allowed to do once you’re inside. It’s the permissions that define what you can access or change.</p>
<h4 id="heading-example-1"><strong>Example:</strong></h4>
<p>After you enter your school, you may be allowed into the library or the sports ground, but maybe not the principal’s office. Each area has rules on who can go in.</p>
<ul>
<li><strong>In the digital world</strong>: After you log in to a website, you might be allowed to view your profile or make changes to it, but you might not be allowed to change other people’s profiles. We enforce authorization through either Role-Based Access Control (RBAC) or Attribute Access Control (ACC). We will talk about this is next blogs.</li>
</ul>
<h4 id="heading-why-is-authorization-important"><strong>Why is Authorization Important?</strong></h4>
<ol>
<li><p><strong>Restricts Access to Sensitive Data</strong>: Not everyone who logs into a system needs access to all areas. Authorization makes sure that users can only access information that’s relevant to them, keeping sensitive data safe.</p>
</li>
<li><p><strong>Prevents Misuse of Privileges</strong>: Authorization limits users to specific actions based on their roles. For example, in a company’s system, regular employees might be able to view only their own information, while managers have access to team data, and admins can view everything.</p>
</li>
</ol>
<h4 id="heading-types-of-permissions-authorization"><strong>Types of Permissions (Authorization):</strong></h4>
<ol>
<li><p><strong>View Only</strong> – You can look at the information, but not edit it.</p>
</li>
<li><p><strong>Edit Access</strong> – You can view and make changes.</p>
</li>
<li><p><strong>Admin Access</strong> – You have complete control, like a teacher having access to all student records.</p>
</li>
</ol>
<h2 id="heading-the-differences">The Differences?</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Authentication</td><td>Authorization</td></tr>
</thead>
<tbody>
<tr>
<td>Proves <strong>who you are.</strong></td><td>Decides <strong>what you can do</strong>.</td></tr>
<tr>
<td>Happens <strong>first.</strong></td><td>Happens <strong>after authentication</strong>.</td></tr>
<tr>
<td>Controlled by <strong>login details.</strong></td><td>Controlled by <strong>permissions.</strong></td></tr>
</tbody>
</table>
</div><h3 id="heading-how-authentication-and-authorization-work-together-to-protect-us"><strong>How Authentication and Authorization Work Together to Protect Us</strong></h3>
<p>Let’s take the scenario of using the Instagram app:</p>
<ol>
<li><p><strong>Authentication</strong>: First, we enter our username and password. The system verifies the identity, perhaps even asking for a second factor, like a code sent to their phone.</p>
</li>
<li><p><strong>Authorization</strong>: Once logged in, the app checks our authorization level. For example, if we try to view the profile of a user who has enabled a private profile, their details will remain hidden from us.</p>
</li>
</ol>
<p>By combining authentication (verifying who someone is) and authorization (defining what they can do), systems can keep data safe, allowing only trusted users to access and interact with it appropriately.</p>
<h2 id="heading-summary">Summary</h2>
<p>On the internet, vast amounts of sensitive data are shared, stored, and accessed every second – from personal identities to financial information. Without strong authentication and authorization measures, it would be easy for unauthorized users to break in and misuse this data.</p>
<p>Together, these two processes form a secure digital barrier that protects users, allowing them to interact online safely and confidently.</p>
]]></content:encoded></item><item><title><![CDATA[HLS (HTTP Live Streaming)  Adaptive Bitrate Streaming (Part 1)]]></title><description><![CDATA[For the past weeks, I have been involved in developing HLS system using AWS services. Before I present the full pledge of the project I have worked on, I thought it would be quite better to sum up the topic comprehensively.
HLS (HTTP Live Streaming) ...]]></description><link>https://rosan-shrestha.com.np/hls-http-live-streaming-adaptive-bitrate-streaming-part-1</link><guid isPermaLink="true">https://rosan-shrestha.com.np/hls-http-live-streaming-adaptive-bitrate-streaming-part-1</guid><category><![CDATA[hls]]></category><category><![CDATA[streaming]]></category><category><![CDATA[AWS]]></category><category><![CDATA[AWS SQS]]></category><category><![CDATA[Docker]]></category><category><![CDATA[ABR]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Thu, 26 Sep 2024 17:25:16 GMT</pubDate><content:encoded><![CDATA[<p>For the past weeks, I have been involved in developing HLS system using AWS services. Before I present the full pledge of the project I have worked on, I thought it would be quite better to sum up the topic comprehensively.</p>
<p>HLS (HTTP Live Streaming) Adaptive Bitrate (ABR) streaming is a technique used to deliver video content efficiently over the internet by adjusting the quality of the video stream in real-time based on the viewer's network conditions. To put it simply, it is a technique for improving streaming over HTTP networks. It is what exactly the Video Streaming gaint, YouTube uses to play the video auto-playing into different quality.</p>
<h3 id="heading-key-terms">Key Terms:</h3>
<ul>
<li><p><strong>Bitrate:</strong> The amount of data transmitted per second. Higher bitrates result in better quality but require more bandwidth.</p>
</li>
<li><p><strong>Segmentation:</strong> Dividing the video into smaller segments allows for more flexible streaming and easier adaptation to changing network conditions.</p>
</li>
<li><p><strong>Adaptive Algorithm:</strong> The algorithm used to determine the optimal bitrate based on network conditions and player performance.</p>
</li>
</ul>
<h3 id="heading-how-it-works-in-brief">How It Works In Brief:</h3>
<p>Adaptive bitrate streaming works by dynamically adjusting the video quality based on the viewer's internet connection. First, the video is encoded into multiple versions, each with different bitrates and resolutions. These versions are then split into small segments, typically a few seconds long, allowing the video to be delivered in parts rather than as a whole file. When playback begins, the video player initially requests the lowest bitrate to ensure smooth streaming. At the end of each segment, the player assesses the network conditions and adjusts the bitrate accordingly. If the connection is strong, it switches to a higher-quality version; if the connection weakens, it shifts to a lower bitrate to avoid buffering. The player dynamically switches between different bitrate variants depending on the user’s bandwidth and device capabilities.</p>
<h3 id="heading-benefits">Benefits:</h3>
<ul>
<li><p><strong>Seamless Streaming</strong>: Reduces buffering and provides a smooth viewing experience even with changing network conditions.</p>
</li>
<li><p><strong>Device Optimization</strong>: Different devices (e.g., mobile, tablet, desktop) can be served video at resolutions optimized for their screens and performance capabilities.</p>
</li>
<li><p><strong>Efficient Bandwidth Usage</strong>: It ensures that users with lower bandwidth aren't overloaded with high-quality streams, saving data usage.</p>
</li>
</ul>
<h3 id="heading-use-cases">Use Cases:</h3>
<ul>
<li><p><strong>Video-On-Demand</strong>: Platforms like Netflix or YouTube utilize ABR to provide seamless viewing experiences across various devices.</p>
</li>
<li><p><strong>Live Streaming</strong>: Sports events, webinars, or other live broadcasts rely on HLS with ABR to ensure viewers get the best quality stream based on their current network.</p>
</li>
</ul>
<p>Coming to an end, in future blogs I’ll be discussing the behind hood algorithm and talk about my system design for creating HLS adaptive bitrate streaming from scratch using AWS services.</p>
<p>Till Then, See You !!!</p>
<p>Keep Learning !!!</p>
]]></content:encoded></item><item><title><![CDATA[Streamlining API Calls in Web Applications : A Comprehensive Guide]]></title><description><![CDATA[Introduction
In the early stages of my journey as a Frontend Web Developer, I encountered a recurring challenge: making API calls to fetch data from the server. While this task is essential to building interactive and data-driven web applications, I ...]]></description><link>https://rosan-shrestha.com.np/streamlining-api-calls-in-web-applications-a-comprehensive-guide</link><guid isPermaLink="true">https://rosan-shrestha.com.np/streamlining-api-calls-in-web-applications-a-comprehensive-guide</guid><category><![CDATA[2Articles1Week]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[Next.js]]></category><category><![CDATA[tanstack]]></category><category><![CDATA[user experience]]></category><category><![CDATA[React]]></category><category><![CDATA[ReactHooks]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Tue, 10 Sep 2024 19:00:22 GMT</pubDate><content:encoded><![CDATA[<hr />
<h3 id="heading-introduction">Introduction</h3>
<p>In the early stages of my journey as a Frontend Web Developer, I encountered a recurring challenge: making API calls to fetch data from the server. While this task is essential to building interactive and data-driven web applications, I found myself writing the same code repeatedly in different components—whether using the native <code>fetch</code> API or libraries like <code>Axios</code>. Each time, I had to manually handle errors, manage loading states, and integrate responses into the UI. This process led my codebase complicated and made it harder to maintain and scale.</p>
<h3 id="heading-the-problem-statement-repetitive-code-and-api-calls">The Problem Statement: Repetitive Code and API Calls</h3>
<p>Whether the project we have been working on or worked on is simple or complex, the data needs to be fetched from the different endpoints for different pages to power our website. During the process, we have been repeating the block of the API call function which makes our codebase difficult to maintain &amp; scale. And, on the same hand, increases the complexity of our project.</p>
<h3 id="heading-the-solution-centralized-web-api-call">The Solution: Centralized Web API Call</h3>
<p>As I progressed, I discovered a better way to manage these API calls: centralizing them using <strong><em>custom hooks</em></strong> combined with <strong><em>TanStack Query</em></strong>. By creating custom hooks and leveraging <code>useQuery</code> for GET requests and <code>useMutation</code> for PUT, PATCH, and other methods, I was able to streamline API interactions, add caching, —all while keeping my code clean and maintainable.</p>
<h3 id="heading-step-by-step-guide-to-implementing-centralized-api-calls">Step-by-Step Guide to Implementing Centralized API Calls</h3>
<ol>
<li><p><strong>Building Custom Hooks for API Calls</strong></p>
<p> One of the most effective ways to centralize API calls is by creating custom hooks. Custom hooks allow you to encapsulate the logic for making API requests into reusable functions that can be shared across multiple components.</p>
<p> I prefer creating a separate folder named apiServices and start creating the custom hook. Here’s how my Next.js folder structure looks like:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1725991507465/8357dcbe-ba75-4674-a36d-cee51db99ffc.png" alt class="image--center mx-auto" /></p>
<p> Let’s take an example I have worked on in my project. Here, by centralizing the export functionality into the custom hook, we can easily manage the process of exporting data to Excel, handling any errors, and providing feedback to the user through a snackbar(toast) notification.</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">import</span> { useMutation } <span class="hljs-keyword">from</span> <span class="hljs-string">"@tanstack/react-query"</span>;
 <span class="hljs-keyword">import</span> { axioInstance } <span class="hljs-keyword">from</span> <span class="hljs-string">"@/config/axiosConfig"</span>;
 <span class="hljs-comment">//streamline custom hook to make api call</span>
 <span class="hljs-keyword">const</span> useExportToExcel = <span class="hljs-function">(<span class="hljs-params">{
   endpoint,
   mutationKey,
   params,
   fileNamePrefix,
   setSnackbarData,
 }</span>) =&gt;</span> {  
   <span class="hljs-keyword">const</span> apiEndpoint = params ? <span class="hljs-string">`<span class="hljs-subst">${endpoint}</span>?<span class="hljs-subst">${params}</span>`</span> : <span class="hljs-string">`<span class="hljs-subst">${endpoint}</span>`</span>;   
   <span class="hljs-keyword">return</span> useMutation(
     [...mutationKey],
     <span class="hljs-function">() =&gt;</span> {
       <span class="hljs-keyword">return</span> axiosInstance.get(apiEndpoint, {
         <span class="hljs-attr">responseType</span>: <span class="hljs-string">"blob"</span>, <span class="hljs-comment">//necessary to handle binary response data</span>
       });
     },
     {
       <span class="hljs-attr">onSuccess</span>: <span class="hljs-function">(<span class="hljs-params">response</span>) =&gt;</span> {
         <span class="hljs-comment">// on success, we download the excel file, simply setting it in memory</span>
         <span class="hljs-comment">// buffer, creating a tag to get from buffer to our pc</span>
         <span class="hljs-keyword">const</span> blob = <span class="hljs-keyword">new</span> Blob([response.data], {
           <span class="hljs-attr">type</span>: response.headers[<span class="hljs-string">"content-type"</span>],
         });
         <span class="hljs-keyword">const</span> url = <span class="hljs-built_in">window</span>.URL.createObjectURL(blob);
         <span class="hljs-keyword">const</span> link = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">"a"</span>);

         link.href = url;
         <span class="hljs-keyword">const</span> fileName = <span class="hljs-string">`<span class="hljs-subst">${fileNamePrefix}</span>.xlsx`</span>;
         link.setAttribute(<span class="hljs-string">"download"</span>, fileName);
         <span class="hljs-built_in">document</span>.body.appendChild(link);
         link.click();

         <span class="hljs-comment">// Call your success snackbar or notification logic</span>
         setSnackbarData({
           <span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,
           <span class="hljs-attr">severity</span>: <span class="hljs-string">"success"</span>,
           <span class="hljs-attr">message</span>: <span class="hljs-string">"Export successful"</span>,
         });
       },
       <span class="hljs-attr">onError</span>: <span class="hljs-function">(<span class="hljs-params">error</span>) =&gt;</span> {
         <span class="hljs-keyword">let</span> err_msg = error?.response?.status;

         setSnackbarData({
           <span class="hljs-attr">show</span>: <span class="hljs-literal">true</span>,
           <span class="hljs-attr">severity</span>: <span class="hljs-string">"error"</span>,
           <span class="hljs-attr">message</span>:
             err_msg
               ? err_msg
               : <span class="hljs-string">"Error: Export Unsuccessful !!!"</span>,
         });
       },
     }
   );
 };
 <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> useExportToExcel;
</code></pre>
<h4 id="heading-parameter-breakdown"><strong>Parameter Breakdown</strong></h4>
<p> To better understand how the <code>useExportToExcel</code> hook works, let’s break down the parameters:</p>
<ul>
<li><p><code>endpoint</code> (<code>string</code>): The API endpoint from which the Excel export data will be fetched.</p>
<p>  <strong>Example</strong>: <code>'/api/export/excel'</code></p>
</li>
<li><p><code>mutationKey</code> (<code>string</code>): A unique key to identify the mutation, used for caching or refetching.</p>
<p>  <strong>Example</strong>: <code>'export-excel-data'</code></p>
</li>
<li><p><code>params</code> (<code>object</code>): The parameters to be sent with the request, typically as query or body data.</p>
<p>  <strong>Example</strong>: <code>'startDate=2024-01-07&amp;endDate=2024-11-30'</code> → <code>{endpoint}?startDate=2024-01-07&amp;endDate=2024-11-30</code></p>
</li>
<li><p><code>fileNamePrefix</code> (<code>string</code>): A prefix for the exported Excel file name, used to customize the file name.</p>
<p>  <strong>Example</strong>: <code>'example'</code> → <code>example.xlsx</code></p>
</li>
<li><p><code>setSnackbarData</code> (<code>function</code>): A toast function to handle setting data for a toast snackbar notification upon success or failure.</p>
</li>
</ul>
</li>
</ol>
<p>    By centralizing the export functionality into this custom hook, you can easily manage the process of exporting data to Excel, handling any errors, and providing feedback to the user through a snack bar notification.</p>
<ol start="2">
<li><p><strong>Using the Custom Hook in a Component</strong></p>
<p> Implementation of custom hook in the component for API call;</p>
</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;
<span class="hljs-keyword">import</span> useExportToExcel <span class="hljs-keyword">from</span> <span class="hljs-string">"@/api/export-services-hook/useExportToExcel"</span>;
<span class="hljs-keyword">import</span> SnackbarComponent <span class="hljs-keyword">from</span> <span class="hljs-string">"../../../shared/snackbar/SnackbarComponent"</span>;
<span class="hljs-keyword">import</span> { ExcelExportApi } <span class="hljs-keyword">from</span> <span class="hljs-string">"../../../../utils/apiUrls"</span>;

<span class="hljs-keyword">const</span> ExportExcelComponent= <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">const</span> [snackbarData, setSnackbarData] = useState({
    <span class="hljs-attr">show</span>: <span class="hljs-literal">false</span>,
    <span class="hljs-attr">severity</span>: <span class="hljs-string">""</span>,
    <span class="hljs-attr">message</span>: <span class="hljs-string">""</span>,
  });

  <span class="hljs-comment">// custom hook for excel api call</span>
  <span class="hljs-keyword">const</span> { <span class="hljs-attr">isLoading</span>: excelLoading, <span class="hljs-attr">mutate</span>: exportExcelMutate } =
    useExportToExcel({
      <span class="hljs-attr">mutationKey</span>: [<span class="hljs-string">"export_due_list_excel"</span>],
      <span class="hljs-attr">endpoint</span>: ExcelExportApi ,
      <span class="hljs-attr">params</span>: <span class="hljs-string">"startDate=2024-01-07&amp;endDate=2024-11-30"</span>,
      <span class="hljs-attr">fileNamePrefix</span>: <span class="hljs-string">"excel"</span>,
      <span class="hljs-attr">setSnackbarData</span>: setSnackbarData,
    });
  <span class="hljs-keyword">const</span> handleExcelExport = <span class="hljs-function">() =&gt;</span> {
    exportExcelMutate();
  };

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
     {snackbarData.show &amp;&amp; (
        <span class="hljs-tag">&lt;<span class="hljs-name">SnackbarComponent</span>
          <span class="hljs-attr">show</span>=<span class="hljs-string">{snackbarData.show}</span>
          <span class="hljs-attr">handleClose</span>=<span class="hljs-string">{handleSnackbarClose}</span>
          <span class="hljs-attr">data</span>=<span class="hljs-string">{snackbarData}</span>
        /&gt;</span>
      )}
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span> Demo on DownLoading Excel File <span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{handleExcelExport}</span>&gt;</span> DownLoad Excel <span class="hljs-tag">&lt;/<span class="hljs-name">Button</span>&gt;</span>    
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> ExportExcelComponent;
</code></pre>
<h3 id="heading-summary">Summary</h3>
<p>With the incorporation of streamline API call, it not make the code consistency, but also helps in scaling and maintaining as the project leaps to more complexity.</p>
<hr />
<p>That’s all for the day.</p>
<p>Feel Free To Cross Question.</p>
<p>Thank You !!</p>
]]></content:encoded></item><item><title><![CDATA[WSO2 IS Integration In Next js Using next-auth.js (Part 1)]]></title><description><![CDATA[In the ever-evolving landscape of web development, authentication remains a critical component for building secure and user-friendly applications. WSO2 Identity Server (IS) is a powerful, open-source identity management solution that provides robust ...]]></description><link>https://rosan-shrestha.com.np/wso2-is-integration-with-next-js-using-next-authjs-part-1</link><guid isPermaLink="true">https://rosan-shrestha.com.np/wso2-is-integration-with-next-js-using-next-authjs-part-1</guid><category><![CDATA[Next.js]]></category><category><![CDATA[WSO2]]></category><category><![CDATA[WSO2 IS]]></category><category><![CDATA[SSO]]></category><category><![CDATA[nextauth.js]]></category><category><![CDATA[Developer]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Thu, 22 Aug 2024 06:26:00 GMT</pubDate><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1724302646605/550bfc1e-d312-4f3e-9f82-bb95819f8033.png" alt class="image--center mx-auto" /></p>
<p>In the ever-evolving landscape of web development, authentication remains a critical component for building secure and user-friendly applications. <strong>WSO2 Identity Server (IS)</strong> is a powerful, open-source identity management solution that provides robust support for single sign-on (SSO), identity federation, and OAuth 2.0-based authentication. With its enterprise-grade features, WSO2 IS is a popular choice for organizations looking to implement comprehensive identity and access management.</p>
<p>On the front-end side, <strong>Next.js</strong> has gained immense popularity as a React-based framework for building modern web applications. Known for its server-side rendering capabilities, static site generation, and API routes, Next.js offers a seamless development experience. However, integrating a secure authentication system into a Next.js application can be a challenging task.</p>
<p>This is where <strong>NextAuth.js</strong> comes into play. NextAuth.js is a versatile authentication library for Next.js applications, offering out-of-the-box support for various providers, including OAuth, OpenID Connect (OIDC), and even custom backends. It simplifies the implementation of secure authentication flows, making it an excellent choice for developers working with Next.js.</p>
<p>For the next blog, we’ll explore how to integrate WSO2 Identity Server with a Next.js application using NextAuth.js. We’ll cover everything configuring WSO2 IS using NextAuth in Next js, and ultimately, creating a secure authentication flow that you can use in your projects.</p>
<p><strong>STAY TUNED</strong> <strong>!!!</strong></p>
<p>XOXO !!!</p>
]]></content:encoded></item><item><title><![CDATA[Hello World !!!]]></title><description><![CDATA[If you're new to programming, you've probably heard the phrase "Hello, World!" before. It's a standard initial program that many developers create while learning a new programming language.

💡
Reflecting on the initial days of embarking on the codin...]]></description><link>https://rosan-shrestha.com.np/hello-world</link><guid isPermaLink="true">https://rosan-shrestha.com.np/hello-world</guid><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Roshan Shrestha]]></dc:creator><pubDate>Wed, 20 Mar 2024 03:52:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1710927772716/cea49087-eb6a-4395-a895-a1a0b2101531.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you're new to programming, you've probably heard the phrase "Hello, World!" before. It's a standard initial program that many developers create while learning a new programming language.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Reflecting on the initial days of embarking on the coding journey, crafting the quintessential "Hello, World!" program stood as the inaugural milestone in navigating the paradigms of the coding universe.</div>
</div>

<p>In this post, we'll look at what "Hello, World!" means, why it's important, and how to build your own version in several programming languages. What is the meaning of "Hello, World!"?</p>
<p>"Hello, World!" is a simple program that displays the message "Hello, World!" on the screen or terminal. While it may appear small, this program is an important milestone for novices since it explains key concepts like syntax, variables, and output. Why say "Hello, World!"? The custom of writing a "Hello, World!" program extends back to the beginnings of computer programming. It provides a simple technique to ensure that a programming environment is properly configured and that code may be successfully compiled or run. Furthermore, it delivers immediate enjoyment by providing apparent benefits with little work.</p>
<h1 id="heading-diving-into-writing-hello-world-in-a-few-popular-programming-languages">Diving into writing "Hello, World!" in a few popular programming languages:</h1>
<pre><code class="lang-python">print(<span class="hljs-string">"Hello, World!"</span>)
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hello, World!"</span>);
</code></pre>
<pre><code class="lang-cpp"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt;</span></span>
<span class="hljs-keyword">using</span> <span class="hljs-keyword">namespace</span> <span class="hljs-built_in">std</span>;

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Hello, World!"</span>;
    <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
</code></pre>
<pre><code class="lang-csharp"><span class="hljs-keyword">using</span> System;

<span class="hljs-keyword">class</span> <span class="hljs-title">HelloWorld</span> {
    <span class="hljs-function"><span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"></span>)</span> {
        Console.WriteLine(<span class="hljs-string">"Hello, World!"</span>);
    }
}
</code></pre>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HelloWorld</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        System.out.println(<span class="hljs-string">"Hello, World!"</span>);
    }
}
</code></pre>
<p>Having being said, with each milestone you achieve, celebrate the progress made and the lessons learned. Keep the spirit of discovery alive as you continue coding. Here's to the boundless horizons of discovery and the sheer delight of bringing imagination to life. Happy Coding! 🚀✨</p>
]]></content:encoded></item></channel></rss>