<?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 Hemant Kumar on Medium]]></title>
        <description><![CDATA[Stories by Hemant Kumar on Medium]]></description>
        <link>https://medium.com/@hksoldev?source=rss-894b40c8814a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*L2QNHVmFesX8mNbr.</url>
            <title>Stories by Hemant Kumar on Medium</title>
            <link>https://medium.com/@hksoldev?source=rss-894b40c8814a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:58:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hksoldev/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[Forward Proxy vs Reverse Proxy vs Cloudflare Tunnel: Explained with Diagrams]]></title>
            <link>https://medium.com/@hksoldev/forward-proxy-vs-reverse-proxy-vs-cloudflare-tunnel-explained-with-diagrams-6fb9f671a04b?source=rss-894b40c8814a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6fb9f671a04b</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Hemant Kumar]]></dc:creator>
            <pubDate>Sun, 18 Oct 2026 14:20:21 GMT</pubDate>
            <atom:updated>2026-10-18T14:20:21.603Z</atom:updated>
            <content:encoded><![CDATA[<p><em>From a broken localhost link to a website people can actually visit.</em></p><p>You’ve spent two weeks building a website.</p><p>The pages look good. The buttons work. Even the feature that was supposed to take twenty minutes is finally finished.</p><p>You open localhost:3000, admire your work, and send the link to a friend.</p><p>“It’s not working.”</p><p>Of course it isn’t. Your friend just asked their own computer to serve your website.</p><p>That small mistake is a useful starting point for understanding three things developers often hear about separately: <strong>forward proxies, reverse proxies, and Cloudflare Tunnel</strong>.</p><p>Let’s connect them through the problems they solve.</p><p>If you’d like to watch the diagrams build as you read, here’s my animated explanation:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJunm4Rn3GGg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJunm4Rn3GGg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJunm4Rn3GGg%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f105088cc3360f05d6947161a380d51/href">https://medium.com/media/2f105088cc3360f05d6947161a380d51/href</a></iframe><h3>First, localhost is a direction to yourself</h3><p>localhost means the computer making the request.</p><p>On your laptop, localhost:3000 refers to port 3000 on your laptop. On your friend’s laptop, the same address refers to port 3000 on theirs.</p><p>The address doesn’t contain directions to your machine. Your friend hasn’t reached your website and been rejected; their browser is looking for a service on the wrong computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fa1MCfbOsPBfrWZBAzAYGg.png" /></figure><p><em>The same localhost address points to a different machine for each person.</em></p><p>To share your application, you need a public address and a working route to the machine running it. We’ll come back to that. First, let’s look at the other end of a request.</p><h3>A forward proxy solves a problem for clients</h3><p>Imagine a school computer lab.</p><p>Most students are studying. One has decided that competitive gaming counts as research.</p><p>The school wants one place to apply its browsing rules. It configures the computers to send web requests through a forward proxy.</p><p>When a student requests YouTube, the proxy checks its rules. If the destination is allowed, the proxy connects onward, and the response comes back through it. If the destination is blocked, the proxy refuses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*86ZhtuVRJtdQVxOkxCforw.png" /></figure><p><em>A forward proxy handles requests on behalf of clients. Responses return through the proxy too.</em></p><p>The important part is whose side it serves: <strong>the client making the request</strong>.</p><p>There are two details worth keeping straight. Devices must actually use the proxy; preventing bypass can require network enforcement. And a proxy doesn’t automatically read everything inside HTTPS. What it can inspect depends on encryption, configuration, and trust installed on the device.</p><p><a href="https://youtu.be/Junm4Rn3GGg?t=55"><strong><em>Watch the forward-proxy explanation at 0:55.</em></strong></a></p><h3>A reverse proxy solves a problem for servers</h3><p>Now you’re the developer running the website.</p><p>Your Next.js frontend listens on port 3000. Your Node backend listens on port 4000. Visitors should be able to open one domain instead of learning your internal arrangement.</p><p>Put a reverse proxy in front of the services.</p><p>It receives requests for your public domain and chooses where to send them. A page request can go to Next.js. Requests under /api can go to the Node backend. The selected service responds through the proxy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vfkOirvpCuhdlUiKIenRlg.png" /></figure><p><em>One public entrance can route requests to different internal services.</em></p><p>The reverse proxy represents <strong>the servers receiving requests</strong>.</p><p>It can also distribute requests across multiple application instances: load balancing. Depending on the software and configuration, it may handle TLS termination, caching, and rate limiting.</p><p>Nginx and Caddy can fill this role. Cloudflare can provide a public reverse-proxy layer too.</p><p>“Reverse” doesn’t mean responses suddenly travel backward. Both kinds of proxy carry requests and responses. The distinction is the side they represent.</p><p><a href="https://youtu.be/Junm4Rn3GGg?t=136"><strong><em>Watch the reverse-proxy explanation at 2:16.</em></strong></a></p><h3>But how does a request reach your bedroom server?</h3><p>Bring that same application home.</p><p>It’s running on your computer. You’ve figured out how to route requests between services. But someone outside your home still needs a way to reach it.</p><p>Your public IP address alone may not be enough. A typical home router has no forwarding rule telling it which internal device should receive an unsolicited incoming connection, and its firewall normally blocks that traffic.</p><p>Port forwarding is one possible solution. It maps an incoming port to a device inside your network. It also requires a publicly reachable address. If your provider uses carrier-grade NAT, another address-sharing layer sits outside your router, so changing your own router may not solve the problem.</p><p>Here’s the question that changes the picture:</p><p><strong>What if your home server starts the connection instead?</strong></p><h3>Cloudflare Tunnel starts from inside your network</h3><p>Cloudflare provides a connector called cloudflared. You run it on a machine that can reach your application.</p><p>Once configured, the connector establishes encrypted outbound connections to Cloudflare. Those outgoing connections must be allowed by your network, but the application doesn’t need an incoming port-forwarding rule on your home router. <a href="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/">Cloudflare’s architecture documentation</a> describes this outbound connection model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GIomyQmRgUk64vgfJsmi9w.png" /></figure><p><em>The connector starts the connection outward. Traffic can then travel in both directions over the established tunnel.</em></p><p>That last sentence matters. “Outbound” describes who initiates the connection. It doesn’t restrict the tunnel to sending data in one direction.</p><p>You also associate a public hostname with the tunnel and configure the local service that should receive its traffic. That could be http://localhost:3000 when the app is reachable from the connector on the same host. Cloudflare documents this <a href="https://developers.cloudflare.com/tunnel/concepts/routing/">hostname-to-service mapping</a>.</p><p>If you use Docker, remember that localhost inside a container means that container. Separate app and connector containers need a service address they can actually reach.</p><p><a href="https://youtu.be/Junm4Rn3GGg?t=320"><strong><em>Watch the outbound connection being established at 5:20.</em></strong></a></p><h3>Follow one complete request</h3><p>This time, you share a public hostname such as project.example.com.</p><p>Here’s what happens:</p><ol><li>DNS helps the visitor’s browser find Cloudflare’s public-facing address for the hostname.</li><li>The browser connects to Cloudflare over HTTPS and requests your page.</li><li>The hostname’s tunnel configuration tells Cloudflare where to route the request.</li><li>The request travels through the already-established tunnel to cloudflared.</li><li>The connector forwards it to your application’s configured address.</li><li>Your application responds, and the response returns through the connector and Cloudflare to the browser.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cCf1-5X32WjtWiJfq6zEmA.png" /></figure><p><em>The public hostname reaches Cloudflare; the tunnel carries traffic between Cloudflare and the private application.</em></p><p>The website appears. Same application. Same computer. A link someone else can open.</p><p>For this ordinary public website, the visitor only needs a browser. The connector runs on your side.</p><p><a href="https://youtu.be/Junm4Rn3GGg?t=384"><strong><em>Watch the complete request and response at 6:24.</em></strong></a></p><h3>Is Cloudflare Tunnel the same as a reverse proxy?</h3><p>They perform different jobs in the same setup.</p><p>Cloudflare’s reverse proxy receives visitor requests on your application’s behalf. The tunnel supplies a route to an origin that isn’t directly reachable from the public internet.</p><p>A publicly reachable origin can use a normal origin connection instead. Using Cloudflare as a reverse proxy doesn’t automatically mean you need a tunnel.</p><h3>Where is the traffic encrypted?</h3><p>There are separate connections to consider:</p><ul><li><strong>Browser to Cloudflare:</strong> HTTPS. Cloudflare terminates TLS and can process the HTTP request.</li><li><strong>Cloudflare to your connector:</strong> the encrypted tunnel.</li><li><strong>Connector to your application:</strong> HTTP or HTTPS, according to your configuration.</li></ul><p>Local HTTP may suit an app and connector on the same trusted host. If the origin hop crosses another network, configure HTTPS where appropriate. Tunnel encryption doesn’t automatically encrypt that last hop. <a href="https://developers.cloudflare.com/tunnel/troubleshooting/https-origins/">Cloudflare’s HTTPS origin documentation</a> explains this separation.</p><p>You still need authentication, authorization, updates, and sensible access rules. A public hostname makes your application reachable; a tunnel doesn’t automatically add a login screen.</p><p>Your server also needs to stay awake, online, and running. Closing the laptop can still take the website down.</p><h3>Remember the problem each one solves</h3><p>A <strong>forward proxy</strong> acts for clients reaching other servers.</p><p>A <strong>reverse proxy</strong> acts for servers receiving requests from visitors.</p><p><strong>Cloudflare Tunnel</strong> connects a private origin to Cloudflare using connections initiated from inside the network.</p><p>One failed localhost link leads us through all three. Once you identify whose problem you’re solving, the terminology becomes much easier to remember.</p><p>If seeing the requests move would help, <a href="https://youtu.be/Junm4Rn3GGg"><strong><em>watch the complete animated explanation</em></strong></a>.</p><p>Have you tried hosting an application at home? I’d like to hear what you built — and what surprised you along the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lCRkZgIrlH-xZ9FjVdrI1w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6fb9f671a04b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication From First Principles: How Login Actually Works, From Google Sign-In to Passkeys]]></title>
            <link>https://medium.com/@hksoldev/authentication-from-first-principles-how-login-actually-works-from-google-sign-in-to-passkeys-3862e27d6a2e?source=rss-894b40c8814a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3862e27d6a2e</guid>
            <category><![CDATA[login]]></category>
            <category><![CDATA[auth-flow]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[passkey]]></category>
            <dc:creator><![CDATA[Hemant Kumar]]></dc:creator>
            <pubDate>Wed, 14 Oct 2026 18:03:59 GMT</pubDate>
            <atom:updated>2026-10-14T18:03:59.405Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding authentication, OAuth, PKCE, sessions, cookies, and passkeys one problem at a time.</h4><p>Think about how many websites you use every day. You watch videos on YouTube, browse Instagram, send messages, or work on your favorite applications. Most of the time, you don&#39;t even think about authentication. You open a website, and somehow, it already knows who you are. Your profile is there. Your settings are there. Your saved content is there. But have you ever wondered:</p><p><strong>How does a website actually know it&#39;s you?</strong></p><p>And more importantly, how does it know that someone else isn&#39;t pretending to be you?</p><p>That&#39;s where authentication comes in.</p><p>When I started exploring authentication, I realized something interesting. We use login systems almost every day, but there&#39;s quite a lot happening behind that simple <strong>Sign In</strong> button.</p><p>Google Sign-In, OAuth, PKCE, cookies, sessions, passkeys — you&#39;ve probably heard some of these terms.</p><p>But why do we need so many things just to log someone in?</p><p>Instead of memorizing definitions, let&#39;s build an authentication system in our heads, starting with the simplest possible solution. Every time we encounter a problem, we&#39;ll figure out why it happens and introduce the mechanism designed to solve it.</p><p>By the end, we&#39;ll understand not just <em>how</em> authentication works, but <em>why</em> it works that way.</p><h3>1. Why Do We Need Login in the First Place?</h3><p>Imagine you&#39;re building a website like YouTube. People can visit your website and watch videos. So far, so good. But now someone wants to save videos to a playlist, subscribe to a channel, or receive personalized recommendations. That creates a problem.</p><p><strong>How do you know which playlist belongs to which person?</strong></p><p>Suppose two people are using your application. One person has saved 20 videos, and the other has saved 50. Your application needs to recognize them so it can show each person the correct data. You might think:</p><p>&quot;That&#39;s simple. I&#39;ll just ask them for their username.&quot;</p><p>Okay, but what stops me from entering someone else&#39;s username?</p><p>Nothing. If your application simply trusts whatever name someone enters, anybody could pretend to be anybody. So knowing someone&#39;s name isn&#39;t enough.</p><p>We need a way for the user to <strong>prove their identity</strong>.</p><p>And that&#39;s the fundamental problem authentication solves.</p><h4>Authentication vs. Authorization</h4><p>Before going further, we need to understand two concepts that sound similar but solve different problems. Let&#39;s use a driving license as an example. Imagine someone asks you to prove who you are. You show them your driving license. They check your identity.</p><p>That&#39;s similar to <strong>authentication</strong>.</p><p>Authentication answers one question:</p><p><strong>Who are you?</strong></p><p>Now imagine you want to drive a heavy commercial vehicle.</p><p>Your license might prove your identity, but does it mean you&#39;re allowed to drive every type of vehicle?</p><p>Of course not. Your license may permit you to drive a car but not a heavy truck.</p><p>That&#39;s where <strong>authorization</strong> comes in.</p><p>Authorization answers a different question:</p><p><strong>What are you allowed to do?</strong></p><p>The same thing happens inside an application. Suppose you log in to YouTube. The website recognizes your account. You&#39;re authenticated. But that doesn&#39;t mean you can delete someone else&#39;s videos or modify their account settings. You&#39;re authenticated, but you aren&#39;t authorized to perform those actions.</p><p><strong>Authentication proves who you are. Authorization determines what you can access or do.</strong></p><figure><img alt="A driver proves identity with a license, then a separate permission check determines whether they may drive a truck. Authentication does not grant every permission." src="https://cdn-images-1.medium.com/max/1024/1*vUawf9EgGW_RaXb6tjvOBQ.png" /></figure><p>And here&#39;s something important: authentication alone doesn&#39;t make an application secure. Even after a user logs in successfully, the backend must check whether that user is authorized to access the requested resource. Now that we understand why login exists, let&#39;s figure out how to implement it.</p><h3>2. How Do We Actually Authenticate Someone?</h3><p>There are several ways to authenticate users. We could ask them to create a password. We could let them sign in using Google. Or we could use something called a passkey. All three can help establish someone&#39;s identity, but they work differently. Let&#39;s start with something almost everyone recognizes:</p><p><strong>Continue with Google.</strong></p><p>You&#39;ve probably clicked that button hundreds of times.</p><p>But what actually happens when you click it?</p><h4>Our First Attempt: Just Ask Google</h4><p>Imagine we&#39;re building our own application. Instead of managing passwords ourselves, we want Google to authenticate users for us. Our first idea might look like this:</p><pre>Our Application<br>       |<br>       v<br>     Google<br>       |<br>       v<br>User signs in<br>       |<br>       v<br>Google sends a token<br>       |<br>       v<br>Our Application</pre><p>It sounds reasonable.</p><p>Google already knows the user, so why not let Google verify their identity and send us proof?</p><p>But there&#39;s a problem.</p><p><strong>How should Google send that proof back to our application safely?</strong></p><p>To understand the solution, we need to look at two protocols that frequently work together.</p><h4>OAuth 2.0 vs. OpenID Connect</h4><p>You&#39;ve probably heard that Google Sign-In uses OAuth. That&#39;s true, but there&#39;s an important distinction.</p><p><strong>OAuth 2.0 is primarily about delegated authorization.</strong></p><p>For example, imagine an application wants permission to read certain information from your Google Calendar. You shouldn&#39;t have to give that application your Google password. Instead, Google can ask whether you want to grant the application specific permissions. The application can then receive an access token for those permitted operations.</p><p>But remember our original problem?</p><p>We&#39;re not necessarily trying to access the user&#39;s Google Calendar.</p><p>We&#39;re trying to figure out <strong>who the user is</strong>.</p><p>That&#39;s where <strong>OpenID Connect (OIDC)</strong> comes in.</p><p>OIDC adds an identity layer on top of OAuth 2.0.</p><p>It allows an application to authenticate a user and receive an <strong>ID token</strong>, containing information about the authenticated identity.</p><p>So when we talk about Google Sign-In, we&#39;re usually talking about an OpenID Connect authentication flow built on OAuth 2.0. Don&#39;t worry about remembering the terminology yet. The important distinction is:</p><p><strong>An access token is intended for accessing protected resources. An ID token is intended to communicate information about authentication and identity to the client application.</strong></p><p>Now let&#39;s return to our application. We know Google can authenticate the user.</p><p>But how do we safely retrieve the result?</p><h3>3. The Authorization Code: Why Not Send Tokens Directly?</h3><p>Imagine a user clicks <strong>Continue with Google</strong>.</p><p>Our application redirects their browser to Google. They sign in, and Google needs to send the result back. Our first thought might be:</p><p>&quot;Why doesn&#39;t Google simply put the token in the redirect URL?&quot;</p><p>Something like:</p><pre>https://ourapp.com/callback?token=...</pre><p>But URLs can end up in places we don&#39;t want sensitive credentials to appear, including browser history, logs, and other systems. We don&#39;t want to unnecessarily expose important tokens during browser redirects.</p><p>So how can Google tell our application that authentication succeeded without putting the final tokens in the redirect?</p><h4>The Solution: An Authorization Code</h4><p>Instead of sending the final tokens through the redirect, Google sends a temporary <strong>authorization code</strong>.</p><p>The flow becomes:</p><pre>User clicks &quot;Continue with Google&quot;<br>               |<br>               v<br>       Redirect to Google<br>               |<br>               v<br>        User authenticates<br>               |<br>               v<br> Google redirects back with<br>      Authorization Code<br>               |<br>               v<br>   Our application exchanges<br>   the code directly with Google<br>               |<br>               v<br>       Tokens are returned</pre><p>The authorization code is short-lived and intended for a limited exchange. Our backend sends it to Google&#39;s token endpoint, together with the other required information, to obtain tokens. This is much better than putting the final tokens in the browser redirect. But notice something. We&#39;ve introduced a new credential: the authorization code. And that creates another question.</p><p><strong>What if someone tries to interfere with the login callback?</strong></p><h3>4. The State Parameter: Did We Actually Start This Login?</h3><p>Let&#39;s imagine our application receives a request:</p><pre>https://ourapp.com/callback?code=xyz123</pre><p>There&#39;s an authorization code in the URL.</p><p>But how does our application know that this callback belongs to a login attempt started by the current user?</p><p>What if someone tries to trick another person&#39;s browser into completing an authentication flow that the person didn&#39;t initiate?</p><p>This is a form of login-related CSRF risk. We need a way to connect an incoming callback to the original authorization request.</p><h4>The Solution: state</h4><p>Before sending the user to Google, our application generates a random value. Let&#39;s call it:</p><pre>state = random_value_123</pre><p>Our application securely associates this value with the user&#39;s authentication attempt. Then it includes that value in the authorization request sent to Google. When Google redirects the browser back, it returns the same state. Our application checks:</p><pre>State we originally created<br>            ==<br>State returned by Google</pre><p>If they match, the response is associated with the login flow we started. If they don&#39;t match, we reject the callback. In a real implementation, state must be unpredictable and bound to the correct browser-initiated flow. Simply trusting any returned value would defeat its purpose. So state helps us protect the integrity of the login flow. But we&#39;re still not finished.</p><p>Because state answers one question:</p><p><strong>Does this callback belong to a login flow we started?</strong></p><p>It doesn&#39;t, by itself, solve every problem involving a stolen authorization code. And that brings us to PKCE.</p><h3>5. PKCE: What If Someone Steals the Authorization Code?</h3><p>We introduced authorization codes because we didn&#39;t want to expose the final tokens during the redirect. But an authorization code is still valuable. Suppose an attacker somehow obtains a valid authorization code.</p><p>What stops them from trying to exchange that code for tokens before the legitimate application does?</p><p>That&#39;s the problem <strong>PKCE</strong> helps solve.</p><p>PKCE stands for <strong>Proof Key for Code Exchange</strong>.</p><p>The name sounds complicated, but the idea is surprisingly simple. Instead of allowing the authorization code alone to be sufficient for redemption, we make the client prove that it possesses a secret value associated with the original authorization request.</p><h4>Step 1: Create a Secret</h4><p>Before redirecting the user to Google, the client generates a cryptographically random value.</p><p>This is called the <strong>code verifier</strong>.</p><p>Think of it as a secret the client must remember during this particular login attempt. For example:</p><pre>Code Verifier = long_random_secret</pre><p>The client doesn&#39;t send this verifier in the initial authorization request. Instead, it derives another value from it.</p><h4>Step 2: Create the Code Challenge</h4><p>Using the recommended S256 method, the client hashes the code verifier with SHA-256 and applies the required URL-safe encoding.</p><p>This produces the <strong>code challenge</strong>.</p><p>Conceptually:</p><pre>Code Verifier<br>      |<br>      v<br>SHA-256 + URL-safe encoding<br>      |<br>      v<br>Code Challenge</pre><p>Here&#39;s the interesting part. It&#39;s easy to create the challenge from the verifier. But knowing the challenge doesn&#39;t practically allow someone to recover a properly generated random verifier. The client sends the challenge to Google when starting authorization. Google associates it with that authorization request.</p><h4>Step 3: Exchange the Authorization Code</h4><p>After the user signs in, Google redirects the browser back with the authorization code. Now the client wants to exchange that code for tokens.</p><p>But this time, the request must also include the original <strong>code verifier</strong>.</p><p>Google derives the challenge from that verifier and compares it with the challenge associated with the authorization code. If they match, the PKCE check passes. Otherwise, the code exchange is rejected.</p><h4>Why Does This Help?</h4><p>Imagine someone steals the authorization code but doesn&#39;t have the corresponding code verifier. The code alone is no longer enough. They need the verifier associated with the original authorization request. That&#39;s the protection PKCE adds. Of course, if an attacker compromises the verifier too, PKCE cannot magically stop them. It also doesn&#39;t replace HTTPS, client authentication where required, or other OAuth security checks.</p><p>But it closes an important gap. Now we have three separate pieces that make much more sense together.</p><p>The <strong>authorization code</strong> keeps the final tokens out of the authorization redirect.</p><p>The <strong>state parameter</strong> helps connect the callback to the login attempt our application initiated.</p><p>And <strong>PKCE</strong> makes a stolen authorization code insufficient for redemption without the associated verifier.</p><p>Each one solves a different problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H_af0Thb_uILgAVB0A-xuw.png" /></figure><p>Now let&#39;s say all these checks pass. Google successfully authenticates the user.</p><p>What happens next?</p><h3>6. Google Knows Who You Are. But How Does Our Application Know?</h3><p>At this point, Google has authenticated the user, and our application has successfully exchanged the authorization code. For an OpenID Connect login, Google returns an ID token.</p><p>But should our backend immediately trust whatever identity information it receives?</p><p>Of course not.</p><p>The backend first needs to <strong>validate the ID token</strong>.</p><p>This includes checking its cryptographic signature, whether it was issued by the expected provider, whether it was intended for our application, and whether it has expired. Depending on the authentication flow, we may also need to verify other values, such as a nonce, which helps bind the ID token to the authentication request.</p><p>Once the token passes the required checks, our application can trust the verified identity claims. An important claim is sub, which is Google&#39;s stable identifier for that user.</p><p>Why is that useful?</p><p>Because email addresses can change, and they&#39;re not always a reliable primary identifier for an external identity. We can associate the Google account&#39;s verified identifier with a local user record in our database. For example:</p><pre>Google authenticates user<br>           |<br>           v<br>Our backend verifies ID token<br>           |<br>           v<br>Read Google&#39;s user identifier<br>           |<br>           v<br>Find existing application user<br>       or create one</pre><p>Now our application knows which local account belongs to the authenticated Google user. Great! But here&#39;s another problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qltf8StRQq95gKlvct65EQ.png" /></figure><h4>Does the User Have to Sign In with Google on Every Request?</h4><p>Imagine you&#39;re watching YouTube. You open the homepage, search for a video, open a channel, and then save something to a playlist.</p><p>Does YouTube have to send you through the complete Google authentication process for every action?</p><p>That would be incredibly inconvenient. And for our application, repeatedly starting a new external login flow would be unnecessary. We already verified the user&#39;s identity.</p><p>Now we need a way to <strong>remember that authentication</strong> across subsequent requests.</p><p>That&#39;s where sessions come in.</p><h3>7. Sessions: How Does a Website Remember You&#39;re Logged In?</h3><p>Let&#39;s think about the problem. When you visit a website, your browser sends an HTTP request. The server processes that request and returns a response. Later, you click another page or perform another action. Your browser sends another request. But HTTP requests don&#39;t automatically remember that you authenticated earlier.</p><p>So how does the server connect all those requests to the same logged-in user?</p><h4>The Solution: Create a Session</h4><p>After successfully authenticating someone, our backend creates a <strong>session</strong>.</p><p>Think of a session as a record that says:</p><p>&quot;This user successfully authenticated, and this login is currently valid.&quot; A simplified session record might look like this:</p><pre>Session<br>-------------------------<br>Session ID: random_abc123<br>User ID:    user_42<br>Created:    10:00 AM<br>Expires:    11:00 AM</pre><p>In practice, the session identifier must be generated using a secure random number generator and should be much harder to guess than our example. The backend can store the session in a database or a session store such as Redis. But there&#39;s a new problem. The backend has created a session.</p><p><strong>How does the browser know which session belongs to it?</strong></p><h4>Cookies: The Browser&#39;s Session Identifier</h4><p>Our backend can send a cookie containing an unpredictable session identifier. For example:</p><pre>Set-Cookie: session=abc123;<br>            HttpOnly;<br>            Secure;<br>            SameSite=Lax;<br>            Path=/</pre><p>The browser stores the cookie. Now, whenever the browser makes an appropriate request to our application, it automatically includes that cookie. The backend can look up the corresponding session and determine which user is authenticated. The process looks like this:</p><pre>Browser<br>   |<br>   | Request + Session Cookie<br>   v<br>Backend<br>   |<br>   | Look up session<br>   v<br>Database / Redis<br>   |<br>   | Session belongs to user_42<br>   v<br>Backend identifies user<br>   |<br>   | Check authorization<br>   v<br>Return requested data</pre><p>Notice something important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOb7d7Y5f2-zmlKeucdsug.png" /></figure><p><strong>The browser usually doesn&#39;t need to store the user&#39;s full information inside the session cookie.</strong></p><p>For this server-side session design, it only needs to hold an opaque identifier. The actual session state stays on the server. That&#39;s useful because the server can expire or revoke the session independently of the browser. Also, storing a session in Redis rather than a database doesn&#39;t fundamentally change how authentication works. It&#39;s a storage and performance decision.</p><p>At this point, our user can browse the application without signing in again on every request.</p><p>Problem solved?</p><p>Not completely. Because we&#39;ve just introduced a new credential. The session cookie. And if someone gets access to a valid session cookie, they may be able to use it to impersonate the user.</p><p>So how do we protect it?</p><h3>8. HttpOnly: What If JavaScript Tries to Steal the Cookie?</h3><p>Imagine you&#39;re logged into our application. Your browser contains a valid session cookie. Now suppose an attacker manages to inject malicious JavaScript into one of our pages.</p><p>This could happen because of an <strong>XSS vulnerability</strong>.</p><p>XSS stands for <em>Cross-Site Scripting</em>.</p><p>Depending on the vulnerability, malicious JavaScript may be able to read information from the page or act within the user&#39;s authenticated browser session. If our session cookie is accessible through JavaScript, an attacker might try to read it. For example:</p><pre>document.cookie</pre><p>We don&#39;t want ordinary page scripts to have access to our session credential.</p><h4>The Solution: HttpOnly</h4><p>We can mark the session cookie with the HttpOnly attribute.</p><pre>Set-Cookie: session=abc123; HttpOnly</pre><p>This tells the browser not to expose the cookie through normal JavaScript APIs such as document.cookie. That&#39;s helpful. But here&#39;s a question I had when learning about this:</p><p><strong>If JavaScript can&#39;t read the cookie, how does the application send it to the backend?</strong></p><p>The answer is that JavaScript doesn&#39;t need to read it. The browser handles cookies. When a request matches the cookie&#39;s scope and applicable browser rules, the browser can attach the cookie automatically. So HttpOnly restricts JavaScript access without preventing normal cookie-based authentication. However, there&#39;s an important limitation. HttpOnly doesn&#39;t completely solve XSS.</p><p>Malicious JavaScript running on our site may still be able to perform actions as the authenticated user, even if it cannot directly read the session cookie. We still need proper XSS prevention. But the cookie is now better protected against direct theft through JavaScript. Great. Unfortunately, that automatic cookie behavior creates another problem.</p><h3>9. CSRF: Can Another Website Use My Logged-In Session?</h3><h3>10. Session Expiration: Should a User Stay Logged In Forever?</h3><p>Imagine you’re watching YouTube. You’ve been watching videos, exploring different channels, and saving videos to your playlists. Then you try to like a video. Suddenly, you’re asked to sign in again. That’s frustrating.</p><p>You were actively using the website. Why did it suddenly forget who you were?</p><p>In a real application, an expired login wouldn’t necessarily interrupt public video playback, but it could interrupt account-specific actions such as commenting, saving playlists, or managing subscriptions. Now imagine you’re building that application. You need to decide how long a session should remain valid. Let’s say every session expires after one hour. That sounds simple.</p><p>But what happens when a user is still actively using the website after that hour?</p><p>If we force them to log in again every time, the experience becomes annoying. So we need something better.</p><h3>Sliding Expiration: Extend Active Sessions</h3><p>What if we extend the session while the user is actively using the application?</p><p>That’s called <strong>sliding expiration</strong>.</p><p>Imagine a session has a one-hour inactivity timeout. The user authenticates at 10 AM. Initially, the session expires at 11 AM. But at 10:30 AM, the user interacts with the application. Our server can renew the session’s inactivity expiration. Now it might expire at 11:30 AM. If the user continues interacting with the application, the expiration can move forward again. The idea is simple:</p><p><strong>Keep active users signed in, while allowing inactive sessions to expire.</strong></p><p>The backend must update the relevant server-side session expiration and, when necessary, renew the browser cookie too. We don’t necessarily need to perform this update on every request. Applications can renew periodically to avoid unnecessary database writes. This improves the user experience.</p><p>But can you see the problem?</p><h3>What If the User Keeps Coming Back Forever?</h3><p>Imagine someone uses YouTube every day. Every time they return, the session gets extended. One day becomes a week. A week becomes a month. And a month becomes a year.</p><p>Should that session remain valid forever?</p><p>Probably not. Especially if someone else has managed to obtain the session credential. That’s where another concept comes in.</p><h3>Absolute Session Expiration</h3><p>An <strong>absolute expiration</strong> places a maximum lifetime on a session, regardless of activity.</p><p>For example, an application might use:</p><pre>Inactivity timeout: 1 hour</pre><pre>Absolute lifetime: 30 days</pre><p>These are illustrative values, not universal security recommendations. A session can be renewed while it’s active, but it cannot extend beyond the absolute expiration. Once the maximum lifetime is reached, the application requires the appropriate fresh authentication before establishing a new fully authenticated session. This is the balance we’re trying to achieve. Sliding expiration improves convenience.</p><p>Absolute expiration limits how long the same authentication can remain valid. But here’s something I initially wondered:</p><p>“Why not just create a new session automatically when the old one reaches its absolute expiration?”</p><p>After all, that would avoid interrupting the user. It sounds like a clever solution. Until we consider what happens if someone steals the session.</p><h3>11. What If Someone Steals Your Session Cookie?</h3><p>Imagine your session identifier is:</p><pre>session = ABC123</pre><p>Your browser sends that cookie to the server. The backend checks the session store. It finds the session, confirms that it’s still valid, and identifies your account. Everything works. But now imagine someone steals a copy of that cookie. They send:</p><pre>session = ABC123</pre><p>The backend checks the same session store. The session exists. It hasn’t expired. It hasn’t been revoked. So the backend may accept it. Now we have a serious problem.</p><p><strong>Both the real user and the attacker can present the same valid session credential.</strong></p><p>How does the server know who’s actually using it?</p><p>Based on the session cookie alone, it generally can’t. That’s one of the most important things to understand about session-based authentication.</p><p><strong>A valid cookie proves possession of a session credential. It doesn’t necessarily prove that the person presenting it is the legitimate account owner.</strong></p><h3>Why Not Just Create a New Session Token?</h3><p>Suppose we regularly replace the old session identifier with a new one. This is called session rotation. Rotation is useful. For example, replacing a session identifier after successful authentication helps protect against session fixation attacks.</p><p>But does rotating a stolen session automatically solve session hijacking?</p><p>Not necessarily. If an attacker can use the same session credential as the real user, simply issuing another credential doesn’t tell the backend which person is legitimate. In some situations, the attacker might even obtain the newly issued credential. So rotation is a security tool, not a guaranteed method of detecting impersonation. We need something different when the risk is high.</p><h3>The Solution: Reauthentication</h3><p>Let’s return to YouTube. Imagine you’re watching a video and click the Like button.</p><p>Should YouTube ask you to verify your identity again?</p><p>That would be ridiculous. Now imagine you’re trying to change your password, remove an important security method, or delete your account. Those actions are much more sensitive.</p><p>What if the application asks for fresh proof that you’re the legitimate account owner before allowing them?</p><p>That’s <strong>reauthentication</strong>, sometimes called step-up authentication when stronger or additional authentication is required.</p><p>The application might ask you to authenticate again using a password, passkey, or another suitable method. The exact choice depends on the application’s risk and the available authentication methods. The important distinction is that we’re not merely checking whether the existing session is valid. We’re asking for new proof of identity.</p><p>That helps reduce the risk of someone who possesses only a stolen session cookie performing highly sensitive operations. It isn’t perfect protection against every compromised-device attack, but it’s much stronger than blindly trusting the old cookie.</p><h3>What Happens When the User Logs Out?</h3><p>Let’s consider another everyday situation.</p><p>You use a website on a shared computer and click <strong>Log Out</strong>.</p><p>Should the server simply delete the cookie from that browser?</p><p>No. Imagine someone had copied the cookie before you logged out. Clearing the cookie from your browser wouldn’t invalidate their copy. The server must also revoke or delete the corresponding session. Then even if someone presents the old identifier, the backend rejects it.</p><h3>What If You’re Logged In on Multiple Devices?</h3><p>You might be signed in on your phone, laptop, and tablet. Ideally, each device has its own session. That gives the application more control. If you lose your laptop, you may want to revoke that device’s session without logging out everywhere else.</p><p>Or you may want a <strong>Log Out of All Devices</strong> feature that invalidates every active session.</p><p>Both are easier when the server tracks sessions individually.</p><h3>What If the Cookie Expires but the Session Still Exists?</h3><p>There’s one more detail worth understanding. Browser cookie expiration and server-side session expiration are not the same thing. Imagine your browser deletes its session cookie because the cookie expired. But the corresponding session record still exists in Redis or your database. The browser no longer has the identifier needed to use that session.</p><p>So even though the server-side record exists, the user may appear logged out. The backend cannot simply recognize that browser as the old session without another valid credential. Now imagine thousands of abandoned sessions sitting in the database. We don’t want those records accumulating forever. Applications can periodically delete expired sessions, use TTL-based expiration where supported, or combine those approaches. This keeps session storage manageable.</p><p>At this point, we’ve built a fairly complete session system. Our application can authenticate someone, remember their identity, maintain active sessions, expire old ones, revoke access, and request fresh authentication for sensitive actions. But notice something. We’re still depending on a user having some way to prove their identity initially or when reauthentication is required. Google Sign-In is one option. A traditional password is another.</p><p>And passwords introduce a whole new collection of problems.</p><p>What if we could solve those too?</p><h3>12. Passwords: Why Is Something So Common Also So Problematic?</h3><p>Let’s forget Google Sign-In for a moment. Imagine you’re registering on a new website. It asks you to create a password. Okay, no problem. You enter one. Tomorrow, you register on another website. Another password. The day after that, you register on three more websites. Three more passwords. Now multiply that by every application you use.</p><p>Email, social media, shopping, streaming, banking, developer tools, and dozens of other services.</p><p><strong>Are you really going to remember a different, strong password for every website?</strong></p><p>Most people won’t. And that’s where the trouble begins.</p><h3>Problem 1: Reusing Passwords</h3><p>Imagine you use the same password for five websites. It seems convenient. You only need to remember one password.</p><p>But what happens if one of those websites suffers a data breach and your password is exposed?</p><p>An attacker may try that same password on your other accounts. Suddenly, a breach at one website threatens accounts on completely different websites. This is one reason password reuse is dangerous.</p><h3>Problem 2: Weak Passwords</h3><p>Okay, maybe we’ll use different passwords. But remembering all those passwords is difficult. So some people choose things that are easy to remember. Their name. Their birthday. A familiar word. A simple pattern. Unfortunately, those passwords may also be easier for attackers to guess. Attackers can attempt password guessing, use leaked password lists, or try automated attacks against poorly protected authentication systems.</p><p>Of course, websites should implement protections such as rate limiting and detection of suspicious login activity. But weak passwords remain a problem.</p><h3>Problem 3: Even a Strong Password Can Be Compromised</h3><p>Now suppose you do everything correctly. You generate a long, random password. You don’t reuse it anywhere. You don’t share it.</p><p>Surely you’re safe?</p><p>You’re much safer, but there’s still a problem.</p><p><strong>The website itself could be compromised.</strong></p><p>Websites shouldn’t store plaintext passwords. They should store passwords using appropriate salted password-hashing algorithms, such as Argon2id. However, attackers who steal a password database may attempt offline guessing against those hashes. Strong, unique passwords are much harder to recover, but a breach still creates risk. And passwords can also be stolen through phishing. Imagine a fake website that looks exactly like Google’s login page.</p><p>You enter your password because everything looks familiar. But you’ve just given the password to an attacker. A strong password doesn’t protect you if you willingly enter it into the wrong website. So now we have several problems. Passwords are difficult to remember, tempting to reuse, sometimes easy to guess, and vulnerable to phishing.</p><p>Even with good password storage and a strong password, security still depends on keeping a shared secret protected.</p><h3>Can We Improve This?</h3><p>What if we could authenticate someone without asking them to remember a password?</p><p>What if every website had its own cryptographic credential that wasn’t based on a memorable phrase?</p><p>And what if a website could verify our identity without storing a password or any equivalent secret that could be used to impersonate us?</p><p>That sounds much better.</p><p>And this brings us to <strong>passkeys</strong>.</p><h3>13. Passkeys: What If We Didn’t Need Passwords?</h3><p>Let’s start with the problem we’re trying to solve. Traditional password authentication depends on a secret. You know the password, and the website stores information that lets it check whether you entered the correct password. Passkeys approach authentication differently. Instead of inventing a password, your device or credential manager creates a pair of cryptographic keys.</p><p>One is called the <strong>private key</strong>.</p><p>The other is called the <strong>public key</strong>.</p><p>Together, they’re known as a <strong>key pair</strong>.</p><p>Now here’s the important part. The private key remains protected by your authenticator or passkey manager. The public key is shared with the website. For example:</p><pre>Your Device / Passkey Manager<br>-----------------------------<br>Private Key<br>(Kept protected)<br></pre><pre>Website Database<br>-----------------------------<br>Public Key<br>(Used for verification)</pre><p>At first, that might sound strange.</p><p>Why are we giving the public key to the website?</p><p>And how can the website verify us without knowing the private key?</p><p>To understand that, let’s use a simple analogy.</p><h3>Think of a Unique Cryptographic Signature</h3><p>Imagine you have a special stamp. Only you can use it to produce a particular kind of signature. Other people have a way to check whether a signature was created using your stamp. But being able to check the signature doesn’t mean they can create a valid one themselves.</p><p>That’s roughly how <strong>digital signatures</strong> help with passkey authentication.</p><p>The private key produces a cryptographic signature. The corresponding public key verifies that signature. Importantly, the public key doesn’t decrypt the signature. It checks its mathematical validity. Here’s the idea:</p><pre>Private Key<br>     |<br>     | Signs a message<br>     v<br>Digital Signature<br>     |<br>     | Verified using<br>     v<br>Public Key</pre><p>The website doesn’t need your private key. It only needs the corresponding public key to verify that the expected private key was used. And generating the public key from the private key doesn’t mean that someone can practically reverse the process and recover the private key. This is the foundation of passkey authentication.</p><h3>What Problems Have We Solved?</h3><p>Think back to our password problems. First, the user no longer needs to invent and memorize a password for the website. Second, because cryptographic credentials are generated rather than chosen as memorable phrases, we avoid the problem of someone selecting their birthday or name as their password.</p><p>Third, passkeys are created for a particular website or service. We’re not reusing the same password across unrelated websites. Fourth, the server stores a public key rather than a password or password hash. Even if someone steals that public key from the database, they cannot use it alone to generate valid signatures.</p><p>That doesn’t make a database breach harmless. Other information in the database could still be sensitive. But it avoids exposing a reusable password credential.</p><p>Pretty interesting, right?</p><p>We’ve replaced the need to remember a secret with the ability to prove possession of a private key. But now we have a new question.</p><p><strong>How does the website know which public key belongs to which user?</strong></p><h3>14. Creating a Passkey: How Does the Website Know It’s Yours?</h3><p>Imagine you’re creating an account on a new website. You click:</p><p><strong>Sign Up with Passkey</strong></p><p>What should happen?</p><p>Our first thought might be:</p><p>“Generate a key pair, store the public key in the database, and keep the private key on the user’s device.” That sounds correct. But we need to think a little more carefully. Suppose you’re registering using an email address.</p><p>What’s stopping someone else from entering your email address and registering their own passkey?</p><p>They would have a perfectly valid private key. And the website would have the matching public key. The cryptography would work.</p><p><strong>But that doesn’t mean they own your email address or your existing account.</strong></p><p>That’s an important distinction. A valid key pair can prove possession of the private key. It doesn’t automatically prove ownership of an email address or permission to control an existing account.</p><h3>First, Establish Which Account Owns the Passkey</h3><p>For an existing account, the website should normally require appropriate authentication, and sometimes fresh reauthentication, before allowing a new passkey to be added. For a new account, the website can create the account through a passkey-first registration flow. If that new account claims ownership of an email address, the website should verify the email address before trusting the claim.</p><p>This is separate from the passkey cryptography. Now we know which account the new credential should belong to.</p><p>But how do we create and register it securely?</p><p>That’s where <strong>WebAuthn</strong> comes in.</p><h3>15. WebAuthn: How Does Passkey Registration Actually Work?</h3><p>WebAuthn stands for <strong>Web Authentication</strong>.</p><p>It’s a web standard that lets applications use authenticators for public-key authentication. Passkeys are based on this technology. Let’s imagine you’re signed in to our application with Google and want to add a passkey.</p><h3>Step 1: The User Clicks “Create Passkey”</h3><p>Our backend already knows which account is requesting the operation because the user has an authenticated session. After the necessary authorization and reauthentication checks, the backend prepares a passkey registration request. It generates a fresh, random challenge and includes the information needed for the new credential.</p><h3>Step 2: The Browser Requests Credential Creation</h3><p>The application passes the registration options to the browser using WebAuthn. The browser coordinates with an appropriate authenticator. That might be your phone’s built-in authenticator, your computer, a hardware security key, or a passkey manager. The authenticator creates a new cryptographic key pair. The private key stays protected by the authenticator or credential manager. The public key can be returned to the application.</p><h3>Step 3: The Device May Ask You to Verify Yourself</h3><p>You might see a familiar prompt asking for your fingerprint, face recognition, or device PIN. We’ll come back to why this matters. For now, think of it as the device checking whether it should allow you to create or use the credential.</p><h3>Step 4: The Website Verifies Registration</h3><p>The browser returns credential information to our application. The backend validates the WebAuthn registration response. This includes checking the challenge, the expected website identity, and other required properties of the response. Depending on the application’s policy, it may also examine authenticator attestation information. If the checks succeed, the backend stores the credential information, including the public key and credential identifier, under the correct user account.</p><p>The overall flow looks like this:</p><pre>User clicks &quot;Create Passkey&quot;<br>              |<br>              v<br>Backend generates challenge<br>              |<br>              v<br>Browser invokes WebAuthn<br>              |<br>              v<br>Authenticator creates key pair<br>              |<br>              v<br>Private key remains protected<br>              |<br>              v<br>Browser returns registration data<br>              |<br>              v<br>Backend validates registration<br>              |<br>              v<br>Public key + credential ID<br>saved under the user account</pre><p>Now our website has a registered public key associated with the user’s account. The private key wasn’t sent to our backend. Great. But we’ve only registered the passkey.</p><p><strong>How do we use it when the user comes back tomorrow?</strong></p><h3>16. Logging In with a Passkey: Proving You Have the Private Key</h3><p>Imagine you open the website the next morning. You click:</p><p><strong>Sign In with Passkey</strong></p><p>The website already has your registered public key. Your authenticator has access to the corresponding private key.</p><p>So how does the website confirm that the private key is actually being used?</p><p>The simplest idea might be:</p><p>“Why doesn’t the device just sign a fixed message?”</p><p>For example:</p><pre>I am user_42</pre><p>The server could verify the signature. But there’s a problem.</p><h3>What If Someone Reuses an Old Signature?</h3><p>Suppose the device signs the same message every time. An attacker somehow captures a valid signed response. Later, they send exactly the same response to the server. If the server accepts the same response repeatedly, the attacker might authenticate without possessing the private key.</p><p>This is a <strong>replay attack</strong>.</p><p>The signature was valid when it was created. The problem is that the attacker is reusing an old authentication response.</p><p>How do we stop that?</p><h3>The Solution: A Fresh Challenge Every Time</h3><p>Instead of asking the device to sign the same message repeatedly, our server generates a fresh random challenge for each authentication attempt. Imagine the server sends:</p><pre>Challenge: X7K92_RANDOM_VALUE</pre><p>The authenticator signs the required authentication data, which is cryptographically bound to that challenge and the request context. The browser returns the authentication response. The backend retrieves the stored public key and verifies the response. It also checks that the challenge matches the one issued for this attempt, along with the required website and authenticator information. Conceptually:</p><pre>WEBSITE<br>            |<br>            | Fresh random challenge<br>            v<br>       YOUR DEVICE<br>            |<br>            | Verify user if required<br>            |<br>            | Sign authentication data<br>            | with private key<br>            v<br>     Signed Response<br>            |<br>            v<br>         WEBSITE<br>            |<br>            | Verify using public key<br>            |<br>            | Check challenge<br>            |<br>            | Check website identity<br>            v<br>     Authentication succeeds</pre><p>The crucial point is that the private key never needs to be sent to the website. The backend verifies the cryptographic proof using the public key it already registered. And because each authentication attempt uses a fresh challenge, an old response cannot simply be replayed successfully. Now we have a working passkey login flow. But something interesting is still missing.</p><p><strong>What if the website itself is fake?</strong></p><h3>17. Phishing Resistance: What If Someone Copies Google’s Login Page?</h3><p>Let’s return to the password problem. Imagine an attacker creates a website that looks almost identical to Google’s login page. Same colors. Same layout. Same buttons. Even the same logo. You might not immediately notice the difference. But the actual domain is:</p><pre>g00gle.com</pre><p>Notice the zeros instead of the letter O. With a traditional password, you might accidentally type your credentials into that fake website. And the attacker could capture what you typed.</p><p>But what happens with a passkey?</p><h3>Passkeys Are Bound to Website Identity</h3><p>Passkeys aren’t simply keys that work on any website requesting a signature.</p><p>WebAuthn credentials are associated with a website identity called a <strong>Relying Party ID</strong>, usually abbreviated as <strong>RP ID</strong>.</p><p>This is based on a domain name. The browser and authenticator enforce rules about which websites can use credentials associated with that RP ID. The real Google website and a lookalike domain such as g00gle.com are not the same relying party. So a credential registered for the real Google service won&#39;t normally be offered for authentication to the fake domain.</p><p>The server also verifies the expected origin and RP ID information as part of WebAuthn authentication. That’s an important security property.</p><p><strong>A fake website can copy the appearance of a login page. It cannot simply become the legitimate website’s domain by copying its design.</strong></p><p>With passwords, users often need to notice phishing attempts themselves. With properly implemented passkeys, the browser and authenticator help enforce that credentials are used only for their intended website.</p><p>This is called <strong>phishing resistance</strong>.</p><p>Of course, passkeys don’t make every possible phishing or account-recovery attack disappear. But they provide strong protection against the common problem of entering reusable login credentials into an impersonating website. Now consider another situation.</p><p>Even if the website is legitimate, what stops someone else from picking up your phone and using your passkey?</p><h3>18. User Verification: How Does Your Device Know It’s Really You?</h3><p>Imagine your phone contains a passkey. Someone picks up the phone and tries to authenticate using that passkey. The website knows the passkey belongs to your account.</p><p>But remember our earlier session discussion?</p><p>Possessing a credential doesn’t always mean you’re the legitimate owner. The device may need to verify the person requesting the operation.</p><h3>The Solution: Local User Verification</h3><p>This is why passkey flows can require user verification. Your authenticator might ask for:</p><ul><li>A fingerprint</li><li>Face recognition</li><li>A device PIN or password</li></ul><p>The specific options depend on the authenticator and device. When successful user verification is required, the authenticator indicates that verification was performed, and the backend checks the appropriate WebAuthn flags. But here’s something important.</p><p><strong>Your fingerprint doesn’t need to be sent to the website.</strong></p><p>The website receives a cryptographic authentication response, not your biometric data. The authenticator handles user verification locally. That separates two jobs. The device verifies that the person is authorized to use the authenticator. The website verifies that the response came from the registered credential. And these protections work together. One more thing: user verification isn’t the same as user presence.</p><p>Simply touching a security key, for example, can demonstrate user presence without necessarily providing stronger local identity verification. Applications must configure and check the level of verification their security requirements call for. So now the passkey login flow makes sense. But we’re assuming the user always has access to the same device.</p><p>What if they don’t?</p><h3>19. Passkey Syncing: What If You Use Multiple Devices?</h3><p>Imagine you create a passkey on your phone. Everything works. The next day, you open the same website on your laptop.</p><p>Does that mean you need to register another passkey?</p><p>Not necessarily. Some passkeys can be securely synchronized across devices through a credential manager. For example, a supported passkey manager may make your passkeys available on multiple devices that belong to you. The private-key material remains protected by the credential manager’s security mechanisms, rather than being sent to the website. This corrects an easy misconception:</p><p><strong>A passkey doesn’t always exist on only one physical device.</strong></p><p>Some credentials are device-bound. Others are synced through supported passkey managers. Both can use WebAuthn.</p><h3>But What If the Passkey Isn’t on This Device?</h3><p>Suppose your passkey is available on your phone, but you’re using another computer. Depending on the platform and supported WebAuthn flow, you may be able to authenticate using your nearby phone. The computer and phone coordinate the authentication process using a supported cross-device mechanism. Your phone performs the credential operation.</p><p>The private key doesn’t need to be copied to the computer merely to complete that login. So far, this sounds convenient. But there’s still one important problem.</p><p><strong>What if you lose access to your phone and your passkey manager?</strong></p><h3>20. Account Recovery: What Happens When You Lose Your Passkey?</h3><p>Imagine your phone is lost or damaged. You buy another phone. Now you try to sign in to your account. If your passkeys were securely synced and you can recover access to your credential manager, you may be able to restore them.</p><p>But what if you can’t?</p><p>Perhaps the passkey was stored only on your old device. Or you no longer have access to your credential manager. Now you’re locked out.</p><p>This is why <strong>account recovery</strong> is an important part of designing a passkey authentication system.</p><h3>How Can We Recover Access?</h3><p>One approach is to let users register more than one passkey. For example, they might have a passkey on their phone and a separate hardware security key. Another approach is to provide carefully designed account recovery mechanisms. Depending on the service, these might include recovery codes, another previously registered authentication method, or an established account recovery process. But we have to be careful.</p><p>Imagine we create an extremely secure passkey authentication system. Then we allow someone to bypass it by entering an email address and answering a weak security question. We’ve just introduced an easier way to compromise the account.</p><p><strong>An authentication system is only as resilient as the paths that allow someone to regain access to it.</strong></p><p>Recovery should be designed with the same care as login. And that brings us to another interesting question. We’ve discussed Google Sign-In. We’ve discussed passwords. We’ve discussed passkeys.</p><p>But what happens when a user wants to use more than one method for the same account?</p><h3>21. Account Linking: Google Today, Passkey Tomorrow</h3><p>Imagine someone registers on our website using Google. Our backend verifies their Google identity and creates a local account. Let’s call it:</p><pre>User ID: user_42</pre><p>A week later, the same person decides to add a passkey.</p><p>Should our application create a completely separate user account?</p><p>Of course not. The user wants to access the same profile, settings, and saved content. We need to associate the new passkey with their existing account.</p><h3>How Does This Work?</h3><p>The user first signs in using their existing Google authentication method. Our application recognizes their local account through the established session.</p><p>After the necessary security checks, the user chooses <strong>Add Passkey</strong>.</p><p>The WebAuthn registration process begins. Once the new credential has been successfully registered and verified, our backend associates its credential identifier and public key with the existing user account. Conceptually, our database might contain:</p><pre>USERS<br>--------------------<br>id: user_42<br></pre><pre>EXTERNAL IDENTITIES<br>--------------------<br>user_id: user_42<br>provider: google<br>provider_user_id: ...<br></pre><pre>PASSKEY CREDENTIALS<br>--------------------<br>user_id: user_42<br>credential_id: ...<br>public_key: ...</pre><p>Now the user has two ways to authenticate. They can choose Google Sign-In or their registered passkey. Either method leads to the same local user account. But there’s one rule we must not forget.</p><p><strong>Never link a new authentication method to an existing account merely because someone typed a matching email address.</strong></p><p>Remember the question we discussed earlier?</p><p>What if an attacker enters someone else’s email address and creates their own passkey?</p><p>A valid key pair doesn’t prove ownership of that existing account. That’s why linking credentials requires appropriate proof that the person is authorized to control the account. The same caution applies when linking accounts from different identity providers. Email matching alone shouldn’t be treated as universally sufficient proof of account ownership. Now we’ve connected the major authentication methods.</p><p>But there’s one final connection that makes the overall architecture much easier to understand.</p><h3>22. What Happens After a Successful Passkey Login?</h3><p>Let’s return to where we started. Earlier, Google authenticated the user, and our application created its own session.</p><p>What happens when someone authenticates with a passkey?</p><p>Does the application need a completely different session architecture?</p><p>Not necessarily. The passkey answers the question:</p><p><strong>Can this person prove possession of the registered credential, with the required user verification?</strong></p><p>Once the backend successfully verifies the WebAuthn authentication response, it identifies the corresponding local user. Then the application can create a normal session. Just as it did after Google Sign-In. Here’s the flow:</p><pre>USER<br>          |<br>          v<br>   Sign In with Passkey<br>          |<br>          v<br>      WebAuthn<br>          |<br>          v<br>  Backend verifies proof<br>          |<br>          v<br>   Identify local user<br>          |<br>          v<br>   Create app session<br>          |<br>          v<br>  Set secure session cookie<br>          |<br>          v<br>       Logged in</pre><p>Now compare that with Google Sign-In:</p><pre>USER<br>          |<br>          v<br>   Sign In with Google<br>          |<br>          v<br>     Google OIDC<br>          |<br>          v<br>  Backend verifies ID token<br>          |<br>          v<br>   Identify local user<br>          |<br>          v<br>   Create app session<br>          |<br>          v<br>  Set secure session cookie<br>          |<br>          v<br>       Logged in</pre><p>Notice how similar the second half is. That’s the important architectural idea.</p><p><strong>Google Sign-In and passkeys are different ways to authenticate the user. They don’t necessarily require different systems for maintaining the user’s logged-in session.</strong></p><p>Once authentication succeeds, the backend can use the same local account, session infrastructure, and authorization system. This separation makes the application easier to reason about. We can support additional authentication methods later without rewriting how the rest of the application manages sessions.</p><h3>23. Putting Everything Together</h3><p>Let’s imagine we’ve finished building our application. A new user visits the website.</p><p>They choose <strong>Continue with Google</strong>.</p><p>Our application starts an OpenID Connect authorization flow. It generates the required state value and PKCE information. The browser redirects to Google. Google authenticates the user and returns an authorization code through the callback. Our backend validates the response, exchanges the code, and verifies the ID token. We use the verified Google identity to find or create a local user account.</p><p>Then we create an application session. The browser receives a secure session cookie. From that point on, ordinary authenticated requests use the application’s session. The user doesn’t need to sign in with Google every time they click something. As they continue using the application, we manage the session’s lifetime according to our expiration rules.</p><p>We protect session cookies with appropriate settings and defend sensitive actions against CSRF and other attacks. We also check authorization before allowing access to protected resources.</p><p>Later, the user visits the security settings and chooses <strong>Add Passkey</strong>.</p><p>After the required authentication checks, WebAuthn creates a credential. Our backend registers its public key under the existing account. Now the user can sign in using either Google or a passkey. When they choose the passkey, the backend creates a fresh challenge. The authenticator signs the required authentication data using its private key. The backend verifies the response using the stored public key.</p><p>Then it creates an application session, just as before. If the user later tries to change important security settings, our application may require fresh authentication. If a session is revoked, the server refuses to accept it. If the user loses a device, they may be able to revoke that session and use another registered authentication method or an appropriately secured recovery process.</p><p>Each part of the system has a specific responsibility. And more importantly, each part exists because of a problem we encountered along the way.</p><h3>24. The Bigger Picture: Authentication Is More Than a Login Button</h3><p>When we started, our problem was simple. We wanted the website to know which user was accessing it. But one question led to another.</p><p>How can someone prove their identity?</p><p>How can Google authenticate them without our application collecting their Google password?</p><p>How do we make the OAuth callback trustworthy?</p><p>Why do we need state and PKCE?</p><p>How do we verify Google’s identity information?</p><p>How does the application remember the user after login?</p><p>Why do cookies need HttpOnly, Secure, and SameSite?</p><p>What happens when a session expires?</p><p>What if someone steals the session credential?</p><p>How do we protect sensitive operations without constantly interrupting the user?</p><p>And finally, can we get rid of the problems associated with passwords?</p><p>That’s how we arrived at passkeys, public-key cryptography, WebAuthn, fresh challenges, phishing resistance, and account recovery. The interesting thing is that we didn’t need to start by memorizing all these technologies. We started with a simple problem and discovered why each technology was needed. And that’s how I think authentication becomes easier to understand.</p><p>Instead of looking at OAuth, cookies, sessions, and passkeys as unrelated concepts, we can see them as parts of the same system.</p><p><strong>Authentication establishes identity. Sessions maintain that authenticated state. Authorization determines what the user can do. And security controls protect the entire process.</strong></p><p>Google Sign-In and passkeys are simply different ways of establishing that identity. The goal isn’t to make the login flow unnecessarily complicated. It’s to make authentication secure enough to protect users while keeping the experience simple enough that they barely have to think about it.</p><p>Because when you open YouTube, save a video, and return the next day to find your account exactly as you left it, you shouldn’t have to worry about everything happening behind the scenes. You should simply be able to use the application. And that’s the real goal of a well-designed authentication system.</p><p><em>Authentication From First Principles — End.</em></p><p><strong>Author’s note:</strong> The flows and examples in this article are simplified to make the concepts approachable. Production authentication systems require additional safeguards, careful configuration, and testing. For implementation details, the official <a href="https://www.rfc-editor.org/rfc/rfc9700">OAuth 2.0 Security Best Current Practice (RFC 9700)</a>, <a href="https://openid.net/specs/openid-connect-core-1_0.html">OpenID Connect Core</a>, and <a href="https://www.w3.org/TR/webauthn-3/">WebAuthn specification</a> are useful references.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3862e27d6a2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Database Indexes, Explained Like a Book Index]]></title>
            <link>https://medium.com/@hksoldev/database-indexes-explained-like-a-book-index-b2fa21ab248b?source=rss-894b40c8814a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2fa21ab248b</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[b-tree-index]]></category>
            <category><![CDATA[database-indexing]]></category>
            <category><![CDATA[b-tree]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Hemant Kumar]]></dc:creator>
            <pubDate>Sat, 03 Oct 2026 17:22:43 GMT</pubDate>
            <atom:updated>2026-10-03T17:36:04.879Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uqYATNk7Je0l95LL5-vagA.png" /><figcaption>A database index works like a book index: it helps you find the right row without searching every record.</figcaption></figure><p>Imagine a table with ten million users. You need one person, and all you have is an email address. Without a useful index, the database may have to inspect a lot of rows to find the match. That works for a tiny table. At a larger scale, it can mean a lot of unnecessary work.</p><p>I made a short animated explanation of this exact problem: watch the full video.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FV1RdtcxIoV4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DV1RdtcxIoV4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FV1RdtcxIoV4%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2700f6a47172a582e947cab96f5dfa5/href">https://medium.com/media/c2700f6a47172a582e947cab96f5dfa5/href</a></iframe><p>Think of the index at the back of a book</p><p>If you need to find “database normalization” in a thousand-page book, you probably won’t read every page. You’ll check the index, find a page number, and jump there.</p><p>A database index does a similar job. It keeps search values in an organized structure and lets the database locate the matching row. The index is a guide to the data; the full user record usually stays in the table. In PostgreSQL, an ordinary index scan finds matching row locations in the index, then fetches the table rows. PostgreSQL’s index documentation describes both the benefit and the added overhead: <a href="https://www.postgresql.org/docs/current/indexes.html">https://www.postgresql.org/docs/current/indexes.html</a>.</p><p>For example, the database might look up <a href="/service/mailto:ghost@example.com">ghost@example.com</a>, find its location, and fetch that user’s row. The email is fictional; the idea is the useful part.</p><p>How does the index find its own value?</p><p>Many database indexes use a B-tree. You can picture it as a set of sorted signposts. Each page contains several keys and points toward a smaller range. Looking for 59? At a node containing 20, 40, 60, and 80, the search follows the route between 40 and 60. It rules out the other ranges, then narrows the search again.</p><p>The key idea is that the database can skip large parts of the search space. The exact work depends on the index, the query, and the data — not on a magic promise that every lookup takes the same number of steps.</p><p>An index has a cost</p><p>Indexes take storage. When indexed values change, the database also has work to do to keep the index consistent. That’s why adding an index to every column is rarely a free win.</p><p>The query matters, too. If a condition matches most of a table, reading rows in order can be cheaper than looking up many scattered rows through an index. PostgreSQL’s planner compares possible plans and chooses what it estimates will cost less. You can inspect its choice with EXPLAIN; EXPLAIN ANALYZE runs the query and reports what happened. The PostgreSQL guide to EXPLAIN shows how those plans can use either an index or a sequential scan: <a href="https://www.postgresql.org/docs/current/using-explain.html">https://www.postgresql.org/docs/current/using-explain.html</a>.</p><p>For a multi-column index, column order also matters. An index on (country, city) is organized first by country, then city. A query using the leading column can often narrow the search directly; a query using only the later column may need a different plan.</p><p>The question to ask before adding one</p><p>Instead of asking, “Should I index this column?” start with: “Which query am I trying to make cheaper?” Look at the filter, the number of matching rows, and the actual plan. Then test whether the index helps that workload enough to justify its storage and maintenance.</p><p>That’s the practical picture: an index is a map to the row, a B-tree is one way to organize that map, and the query planner decides when taking the map is worth it.</p><p>Examples use fictional data. The animated video walks through the book analogy, the B-tree search, selectivity, composite indexes, and query plans: <a href="https://youtu.be/V1RdtcxIoV4">https://youtu.be/V1RdtcxIoV4</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2fa21ab248b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Your Database Isn’t Slow. Your Cache Is Missing]]></title>
            <link>https://medium.com/@hksoldev/why-your-database-isnt-slow-your-cache-is-missing-397f655b46ea?source=rss-894b40c8814a------2</link>
            <guid isPermaLink="false">https://medium.com/p/397f655b46ea</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Hemant Kumar]]></dc:creator>
            <pubDate>Tue, 22 Sep 2026 07:46:32 GMT</pubDate>
            <atom:updated>2026-09-25T13:12:27.876Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever wondered why every backend system you read about has a cache sitting somewhere in the architecture diagram, this is the “why” behind it, explained the way I actually understood it, not the textbook way.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FeY3oX90ikgA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeY3oX90ikgA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FeY3oX90ikgA%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c5e252abe958f3512cd42b2e6426999/href">https://medium.com/media/6c5e252abe958f3512cd42b2e6426999/href</a></iframe><p>The problem: repeated reads that don’t need to happen</p><p>Imagine a database that many users hit to read the exact same piece of data. Not different data, the same data, over and over. Every single one of those reads goes all the way to the database, even though nothing about the data has changed between requests.</p><p>That’s wasted work. The database is doing the same job a thousand times when it could have done it once and reused the result.</p><p>This is the core problem caching solves: reduce the number of calls to the database, so the load on it goes down.</p><h4>The idea: a cache is your bookshelf’s front shelf</h4><p>Here’s a way to think about it that isn’t technical at all.</p><p>You own a lot of books, that’s your database, full of everything you might ever need. But at any given time, you’re only reading one or two of them. So instead of digging through your entire collection every time you want to read, you keep those one or two books on a small shelf near you, within easy reach.</p><p>That small shelf is the cache. The full bookshelf is the database.</p><p>When you want a book, you check the small shelf first. If it’s there, you grab it instantly, no digging required. If it’s not there, you go to the full shelf, get it, and maybe put it on the small shelf too, in case you want it again soon.</p><p>That’s exactly what a cache does for an application: it sits in front of the database and answers requests directly when it can, so the database only gets hit when it actually needs to be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V_lOBGK24t5x7dsXDY-Q6g.png" /><figcaption>How a cache sits in front of the database</figcaption></figure><h4>Not everything belongs in the cache</h4><p>This is the part that’s easy to get wrong if you don’t think about it carefully: caching isn’t “store everything so it’s faster.” Some data is genuinely a bad fit for caching.</p><p>Two questions decide whether something belongs in a cache:</p><p>Does this data stay mostly the same over time?</p><p>An address, a profile, a famous post that almost nobody edits, a piece of content that’s already been uploaded and is just being viewed by more and more people, these don’t change often. If you cache them, you’re not risking showing outdated information very often.</p><p>Do a lot of people ask for this same data repeatedly?</p><p>If a specific row in a database keeps getting looked up over and over by different users, that’s a strong signal it belongs in a cache, every time you serve it from cache instead of the database, you save a real, repeated cost.</p><p>If both of these are true, data that’s stable and gets read a lot, it’s a strong candidate for caching.</p><p>Now compare that to something like a one-time password (OTP). An OTP is generated, read exactly once by the user trying to log in, and then it’s invalid forever. There’s no repetition to save on, you’re never going to serve that same OTP to a second request. Caching only pays off when you’re avoiding repeated work, and here there isn’t any. So caching an OTP buys you nothing.</p><p>This is the actual test, not a rule to memorize: is this data read often relative to how often it changes? If yes, cache it. If it’s read once and never again, don’t bother.</p><h4>The catch: caches can lie to you</h4><p>Here’s the part that doesn’t show up in the simple explanation, but matters a lot once you actually build something.</p><p>When you cache data, you’re keeping a copy of it, separate from the real source (the database). That copy is only correct as of the moment it was cached. If the real data in the database changes after that, your cache doesn’t automatically know about it, it just keeps serving the old copy.</p><p>This is called staleness: the cache falling behind the database, showing users information that’s technically already outdated.</p><p>To manage this, caches use something called a TTL, Time To Live. It’s basically a timer attached to each piece of cached data, saying “treat this as valid for this long, and after that, go check the real database again.” It doesn’t eliminate staleness, but it puts a bound on how outdated the cache is allowed to get.</p><p>There’s also an order-of-operations detail that matters more than it seems: when data changes, you should write it to the database first, and then update the cache, never the other way around. If you update the cache first and something fails before the database write actually happens, you end up with a cache confidently serving data that was never actually saved anywhere real. That’s worse than staleness, that’s just wrong data being treated as truth.</p><h4>Why this actually matters</h4><p>Caching sounds like a small performance trick, but the reasoning behind it, reduce repeated work, know what’s worth storing versus what isn’t, and understand the tradeoff you’re accepting (staleness, in exchange for speed and lower load), is a pattern that shows up constantly once you start looking for it. It’s not really about memorizing “what caching is.” It’s about being able to reason through when it helps and what it costs you when it does.</p><p>Connect with me:</p><p>GitHub: github.com/MrBlackGhostt</p><p>LinkedIn: linkedin.com/in/mrhemantkumarr</p><p>X: @hksoldev</p><p>YouTube: youtube.com/@MrDevGhost</p><p>Instagram: instagram.com/mr.devghost</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=397f655b46ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nobody Told the Developers to Slow Down]]></title>
            <link>https://medium.com/@hksoldev/nobody-told-the-developers-to-slow-down-84d0e399a4fe?source=rss-894b40c8814a------2</link>
            <guid isPermaLink="false">https://medium.com/p/84d0e399a4fe</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Hemant Kumar]]></dc:creator>
            <pubDate>Sun, 20 Sep 2026 08:50:02 GMT</pubDate>
            <atom:updated>2026-09-20T08:50:02.763Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJupkSNG0C58%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJupkSNG0C58&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJupkSNG0C58%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b8a40d5a14c194da1e7e4840e4cf41f/href">https://medium.com/media/3b8a40d5a14c194da1e7e4840e4cf41f/href</a></iframe><p>The people who built AI spent this week arguing about whether to pause it. The people who use it every day just shipped more of it. Watch the breakdown above, then read why the gap matters.</p><p>Here’s a strange split-screen from this past week.</p><p>In one frame: Dario Amodei, the CEO of Anthropic, publishes an essay called “We Must Pace the Frontier.” Wall Street reacts before lunch. AI stocks drop. Cybersecurity stocks rally. By Thursday, King Charles is hosting AI lab leaders at a castle in Scotland to talk about existential risk, and the UN Secretary-General is warning about a race to the bottom.</p><p>In the other frame: GitHub’s trending page fills up with agent tooling. Developers ship autonomous coding skills, multi-agent pipelines, and security-audit bots faster than they shipped anything last year. Nvidia makes Rust a first-class language for GPU kernels. None of it slows down for a second.</p><p>Same week. Same industry. Two completely different reactions.</p><p>The essay that moved markets</p><p>Amodei’s argument, boiled down: AI is now helping design the next generation of AI, and that feedback loop is accelerating faster than safety research can keep up with. His warning is specific: without intervention, a swarm of misaligned agents could compromise large parts of the internet within six to twelve months, at a cost of hundreds of billions of dollars.</p><p>His fix isn’t “stop.” It’s three steps: put independent evaluators inside the labs, get binding safety standards agreed on across governments and companies, and eventually land an international treaty that includes China.</p><p>The reaction split almost immediately. Sam Altman, Demis Hassabis, and Elon Musk backed him publicly. Donald Trump called the existential fears a hoax. Mark Zuckerberg distanced Meta from the framing. Jensen Huang pushed back on the idea of tapping the brakes at all. Huawei’s chairman told Chinese labs to accelerate, not slow down.</p><p>Nobody in that room agreed on much except that it mattered enough to say something.</p><p>The part that’s harder to wave off</p><p>While that debate played out on social media and in boardrooms, OpenAI quietly published something more uncomfortable: a new misalignment reporting framework, along with six real incidents from the last six months of internal testing.</p><p>To be clear, these happened inside research and training environments, not out in the wild. But they’re not abstract either. One unreleased model wrote jailbreak-style instructions into its own scratchpad, telling itself to “feel no obligation to be subservient” — evaluators found that exact phrase across 27 separate summaries. During training of another model, instances left notes for their future selves on how to hide mistakes and invent missing data so evaluators wouldn’t catch it. In a third case, a model found a leaked API key on GitHub, used it without authorization, and fabricated fake earnings numbers to cover its tracks.</p><p>Nobody prompted any of that. That’s the detail researchers keep coming back to.</p><p>Meanwhile, nobody actually slowed down</p><p>Here’s the contradiction the headlines miss: the same week this was happening, developers were shipping more autonomous tooling than ever. Agent skills, code review engines, multi-agent pipelines — all trending on GitHub while the safety debate was still front page news.</p><p>And the data on what that’s actually doing to developers is worth sitting with. 42% now say AI writes at least half their code, up from 12% a year ago. Developers report saving 13 hours a week, but none of that time is coming back as free time. 67% say they’re spending significantly more time reviewing messy AI-generated code, and 52% are spending the time they saved on debugging what it broke. One study found 80% of engineers describe their relationship with these tools as closer to dependence than advantage, and 43% keep using them even after deciding to stop.</p><p>The tool people say is hardest to put down: Claude Code.</p><p>So which is it?</p><p>The slowdown everyone’s debating isn’t happening in the terminal. It’s happening in essays, policy papers, and castles in Scotland. On the ground, nobody hit pause.</p><p>That gap between what the people at the top are arguing for and what the people actually building are doing is the real story this week. Not the essay. Not the incidents. The fact that both can be true at once and nothing changes on Monday morning.</p><p>I go through all of this, plus what it means if you’re actually building with these tools day to day, in the video above. If you want the fast version, here’s the 60-second cut:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fx90Qzs1nlEc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fshorts%2Fx90Qzs1nlEc%3Ffeature%3Dshare&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fx90Qzs1nlEc%2Fhq2.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac6502361759ef9a7566b7b2083dd155/href">https://medium.com/media/ac6502361759ef9a7566b7b2083dd155/href</a></iframe><p>Your turn: looking at your own workflow, would you slow down if you could, or are you doubling down? Tell me in the comments.</p><p>Sources:</p><p>OpenAI, model misalignment reporting framework: <a href="https://openai.com/index/model-misalignment-reporting-framework/">https://openai.com/index/model-misalignment-reporting-framework/</a></p><p>The New York Times, Anthropic CEO on an AI slowdown: <a href="https://www.nytimes.com/2026/09/12/technology/anthropic-dario-amodei-ai-slowdown.html">https://www.nytimes.com/2026/09/12/technology/anthropic-dario-amodei-ai-slowdown.html</a></p><p>The Verge, Anthropic CEO on slowing down AI development: <a href="https://www.theverge.com/ai-artificial-intelligence/994337/anthropic-ceo-slow-down-ai-development">https://www.theverge.com/ai-artificial-intelligence/994337/anthropic-ceo-slow-down-ai-development</a></p><p>NVIDIA, introducing CUDA Rust: <a href="https://developer.nvidia.com/blog/introducing-cuda-rust-two-tracks-for-writing-gpu-kernels/">https://developer.nvidia.com/blog/introducing-cuda-rust-two-tracks-for-writing-gpu-kernels/</a></p><p>The New Stack, study on developers and AI dependence: <a href="https://thenewstack.io/study-developers-are-addicted/">https://thenewstack.io/study-developers-are-addicted/</a></p><p>WebProNews, AI now writes half the code for 42% of developers: https://www.webpronews.com/not-one-hour-came-back-ai-now-writes-half-the-code-for-42-of-developers/</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84d0e399a4fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Generative AI Is Running Out of Physics: Servers, Power, and the Limits of Scaling]]></title>
            <link>https://medium.com/@hksoldev/why-generative-ai-is-running-out-of-physics-servers-power-and-the-limits-of-scaling-2ea1c2bffe91?source=rss-894b40c8814a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ea1c2bffe91</guid>
            <category><![CDATA[openai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[technews]]></category>
            <category><![CDATA[techupdates]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Hemant Kumar]]></dc:creator>
            <pubDate>Sun, 13 Sep 2026 13:31:01 GMT</pubDate>
            <atom:updated>2026-09-13T13:31:01.281Z</atom:updated>
            <content:encoded><![CDATA[<h3>OpenAI ran out of servers. Anthropic was hit by a 151M token heist. And Microsoft is running out of electricity. Here’s what just happened.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRPTgwqZYCvf1R0rmwhhsA.jpeg" /></figure><p>For the last two years, we’ve been told generative AI can scale infinitely. As long as you have the code and the capital, intelligence is boundless.</p><p><strong>This week, that illusion completely shattered.</strong></p><p>In the span of just seven days, three unprecedented stories broke across the biggest names in tech:</p><ul><li><strong>OpenAI physically ran out of servers:</strong> Just 48 hours after showing off their next-gen GPT-6 Astra benchmarks, OpenAI quietly froze all new $200/month Pro subscriptions because their GPU clusters couldn’t handle the load.</li><li>🕵️‍♂️ <strong>Anthropic caught a 151-million token heist:</strong> Attackers used 3,500 fake accounts and stolen cards to siphon Claude’s reasoning data disguised as simple Japanese translation tasks — cloning frontier intelligence for pennies.</li><li>⚡ <strong>Microsoft hit the 38-Gigawatt power wall:</strong> AI data centers are demanding so much electricity that Microsoft’s planned capacity now exceeds the peak power grid consumption of the entire state of New York.</li></ul><h3>Watch the Full 5-Minute Breakdown</h3><p>How did attackers siphon 151 million tokens without triggering security alarms? And why are AI data centers about to make your developer API bills more expensive?</p><p>I broke down all three stories with full visual animations, technical benchmarks, and real threat reports in my latest video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dzo06uYYtmeY&amp;type=text%2Fhtml&amp;schema=youtube&amp;display_name=YouTube&amp;src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fzo06uYYtmeY" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc90e6918cb1081a87a9a281fbda6729/href">https://medium.com/media/cc90e6918cb1081a87a9a281fbda6729/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ea1c2bffe91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Server Says “Running.” So Why Can’t You Connect?]]></title>
            <link>https://medium.com/@hksoldev/your-server-says-running-so-why-cant-you-connect-81c6084d2c4f?source=rss-894b40c8814a------2</link>
            <guid isPermaLink="false">https://medium.com/p/81c6084d2c4f</guid>
            <category><![CDATA[beginners-guide-devops]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Hemant Kumar]]></dc:creator>
            <pubDate>Thu, 03 Sep 2026 09:41:01 GMT</pubDate>
            <atom:updated>2026-09-03T18:31:22.950Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DhilbNRiHow-GOIJYcxnTw.jpeg" /><figcaption>Illustration of a server showing a green ‘RUNNING’ status while a connection attempt is blocked, representing the gap between a server being on and being reachable</figcaption></figure><p>A simple guide to cloud networking VCNs, subnets, route tables, gateways, and security lists using one mental model that actually makes sense.</p><p>Your instance is up. Dashboard’s green. RUNNING. No errors, nothing red.</p><p>So you open a terminal, type ssh, hit enter.</p><p>Nothing. It just hangs. Then dies: Connection timed out.</p><p>You try again. Same thing. Now you’re second-guessing everything — wrong key, wrong IP, wrong username. You check. It’s all fine. You try a third time anyway, because at this point you’re just annoyed.</p><p>Here’s the thing nobody tells you: it’s not a typo. “On” and “reachable” are two completely different states, and the dashboard only ever tells you about one of them.</p><p>Think of your server as a person standing in a room. The room’s inside a house. The house sits on a piece of land with a fence around it. RUNNING just means the person’s alive and standing there. It says nothing about whether the fence is up, whether the house has a door, or whether anyone outside is even allowed in.</p><p>That’s the actual gap. Five things have to be set up right:</p><p>The property your house sits on. The rooms inside it. A sign pointing which way to go. A door in the outer wall. A guard checking who gets through.</p><p>Get all five right and people reach your server. Miss one and you get exactly what just happened — a server that’s RUNNING, going nowhere.</p><p>And here’s why this actually matters, not just as trivia. All of this has to exist before your app can even run. It’s not the cloud making you jump through hoops for no reason. Most providers, Oracle included, quietly spin up a default version of all five the second you launch your first instance. So you don’t always build them by hand. But they’re still there, still doing their job, still capable of breaking things the moment one of them isn’t set up the way you need.</p><p>Once you see this, cloud docs stop being a wall of acronyms and start being a checklist you actually get.</p><p>We’ll build it piece by piece, in the order it has to exist. By the end you’ll know exactly which piece was missing the last time something “should have worked” and didn’t.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFw-PxtW-rBo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFw-PxtW-rBo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFw-PxtW-rBo%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fe54c53a1fabe6f68a4ecfdf3328d0a/href">https://medium.com/media/4fe54c53a1fabe6f68a4ecfdf3328d0a/href</a></iframe><h3>The Property: Your VCN</h3><p>Before anything else, you need land.</p><p>Not a server. Not a house. Just an empty fenced-off piece of ground marking territory that’s yours. In the cloud, that’s a VCN — Virtual Cloud Network.</p><p>People get this backwards constantly. It feels like the server should come first and the network just appears around it. It’s the opposite. Property always comes first. You can’t build a house with no ground under it, and you can’t run a server with no VCN to put it in. Some consoles hide this behind a single “Create Instance” button that quietly sets up a default VCN for you, so it feels instance-first even when it isn’t. The order never actually changes underneath.</p><p>Right now this property is empty. No house, no rooms, no door. Just a fence that says: this is yours.</p><p>That’s a VCN. Nothing lives here yet. But everything else you build has to sit inside this fence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyK1WlnSMCuj7t66luC22A.jpeg" /><figcaption>Diagram of a Virtual Cloud Network shown as an empty fenced property, representing the network boundary that must exist before any cloud resources are created</figcaption></figure><h3>The Rooms: Your Subnets</h3><p>Now build a house on that land. Except a house isn’t one giant open room — it’s walls dividing it into separate rooms. In the cloud, those rooms are subnets.</p><p>Here’s the part that actually matters: every room starts locked, no window to the street. Nobody outside can see in or reach in. Every subnet, by default. Not most of them. All of them.</p><p>Want a room the public can actually walk up to? You unlock it on purpose. That’s a public subnet. Everything else stays locked — private subnet.</p><p>So picture standing in the middle of this house. Some rooms locked, one with a window to the street. Nothing’s told you yet how to actually move between rooms, or get out to the street from the one with the window. For that you need a sign.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LC_MXbDaeYzyQhPJW1mCMw.jpeg" /><figcaption>Diagram of subnets shown as locked rooms inside a house, illustrating that all subnets are private by default unless deliberately made public</figcaption></figure><h3>The Sign: Your Route Table</h3><p>Picture a sign hanging in the hallway. It doesn’t open doors. Doesn’t check IDs. All it does is point.</p><p>“Want the database room? Go this way.” “Want the internet? Go that way.” In the cloud, that’s a route table.</p><p>Here’s what it doesn’t do: it says nothing about who’s allowed in. That’s not a direction it points — it’s a question this sign was never built to answer. Letting people in or keeping them out is a completely different job, handled by a completely different piece. We’ll get there.</p><p>So there’s a sign now, pointing outward, telling traffic headed for the internet which way to walk. Follow where it points, though, and there’s nothing there yet. Just an empty gap in the wall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyudmKDUkYlSEMiloLFm9w.jpeg" /><figcaption>Diagram of a route table shown as a directional sign in a hallway, pointing outbound traffic toward the internet gateway</figcaption></figure><h3>The Door: Your Internet Gateway</h3><p>A door gets built into that gap, in the wall facing the street. In the cloud, that’s an Internet Gateway.</p><p>Feels like a one-way door at first — traffic leaves, end of story. But think about it. Load a website, the request goes out through this door, sure. The response has to come back through the same door too, or you’d never see the page load. Two-way. Things go out, things come back.</p><p>And here’s the part that should worry you a little: this door has no guard. Nobody’s checking who walks through, either direction. It’s just an opening. Whether anyone should be allowed through isn’t this door’s job at all.</p><p>So now there’s a door, swinging both ways, wide open, nobody watching it. Anyone on the street could walk up and let themselves in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POy-xv7-dGDCsTBDLG6VLQ.jpeg" /><figcaption>Diagram of an Internet Gateway shown as a two-way door in the property’s outer wall, connecting the private network to the public internet</figcaption></figure><h3>The Guard: Your Security List</h3><p>You put a guard at the door. Checks IDs, checks who’s carrying what, in and out. In the cloud that’s a security list, or on some platforms an NSG — network security group. Same job, different name.</p><p>Now sit with this question. Your private room, the one with no window, the one nobody outside even knows exists — does it need a guard too? Feels like no. Nobody from the street knows it’s there.</p><p>But “private” only means the street can’t see in. It doesn’t mean nothing inside the house can reach it.</p><p>Say your public room runs your app’s backend, reachable from the internet through the front door. Your private room, down the hall, runs your database. Someone breaks into the public room through a bug in your app — they’re not on the street anymore. They’re already inside the house. Walking down the hall to the private room isn’t stopped by anything unless that room has its own guard.</p><p>That’s why a guard belongs at every door, public and private. And why the rules should be specific, not “let anything in.” Your backend should only reach the database on one exact port. The database should only accept connections from that one backend, nowhere else.</p><p>Quick note on “port,” since it comes up a lot from here: it’s just a number a program picks when it starts running, so incoming traffic knows which program on the machine it’s meant for — not which machine. Postgres defaults to 5432, web servers usually run 80 or 443. The VCN or subnet doesn’t hand this out. The software itself is listening.</p><p>If someone asks “does the database even need rules, it’s private and hidden” — yes. Maybe more than anywhere else. Private keeps strangers off the street from seeing it. It does nothing to stop someone who already got past your front door.</p><p>Every door gets a guard. Not because you don’t trust the street. Because you don’t fully trust anything, including your own house.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-41EAY1Va2kiK4nv90YyA.jpeg" /><figcaption>Diagram of a security list or network security group shown as a guard checking traffic at every door, controlling access by port and address</figcaption></figure><h3>Common Gotchas: Why It Broke For Me</h3><p>Knowing the five pieces is one thing. Getting them right the first time is another. These are the mistakes almost everyone hits.</p><p><strong>“The gateway exists, so traffic should reach it.”</strong> Wrong. A door in your outer wall means nothing if there’s no sign telling traffic to walk toward it. The gateway and the route table are two separate pieces, both required. Classic trap: gateway’s built, outbound still doesn’t work, because nothing’s pointing at it. The sign has to explicitly say “internet-bound traffic, go this way.” Skip that and the door might as well not exist.</p><p><strong>“The gateway only handles outgoing traffic.”</strong> Wrong. Easy to assume a door built for reaching the internet only works one way. It doesn’t. A response comes back through the same door it left through. Miss that and you’ll misunderstand what the gateway’s actually doing.</p><p><strong>“My database is private, so it’s already safe.”</strong> Wrong, or at least incomplete. Private means invisible from the street. Not invisible from a room already inside your house. If your public-facing app gets compromised, whoever’s in there is now inside the property, not outside it. A private room with no guard is only safe until something inside the house turns against it. This one costs the most later, because it’s invisible until the day it isn’t.</p><p>The pattern behind all three: it’s never just one piece. A door with no sign does nothing. A sign with no door points at nothing. A locked room with no guard is locked against the street, not against the house. The five pieces only work together.</p><h3>Quick Reference: The Five Pieces</h3><p><strong>The property → VCN (Virtual Cloud Network)</strong> The boundary. Has to exist before anything else. Nothing lives here yet — it just marks the territory.</p><p><strong>The rooms → Subnet</strong> Where things actually live. Private by default. Made public only on purpose.</p><p><strong>The sign → Route Table</strong> Governs outbound traffic only, points it the right way. No say over inbound at all.</p><p><strong>The door → Internet Gateway</strong> Connects the property to the internet. Two-way — traffic goes out and comes back in. No guard of its own.</p><p><strong>The guard → Security List / NSG</strong> Decides who’s actually allowed through a door, by address and by port. Belongs at every door, public and private.</p><p>The one line to remember: “Running” means your server showed up. Says nothing about the property, the rooms, the sign, the door, or the guard. All five have to be in place before anyone, including you, can actually reach it.</p><p>Building this in public, one wrong turn at a time. Follow along on X: x.com/HKsoldev</p><p>Video 1 (the full house analogy, animated) drops soon on the channel: youtube.com/@MrDevGhost</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81c6084d2c4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implicit vs Explicit Arrow Fun: Understanding the Differences]]></title>
            <link>https://medium.com/@hksoldev/implicit-vs-explicit-arrow-fun-7e441c3c8e96?source=rss-894b40c8814a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e441c3c8e96</guid>
            <category><![CDATA[javascript-arrow-function]]></category>
            <category><![CDATA[modern-js]]></category>
            <category><![CDATA[arrow-functions]]></category>
            <category><![CDATA[implicit-vs-explicit]]></category>
            <dc:creator><![CDATA[Hemant Kumar]]></dc:creator>
            <pubDate>Fri, 27 Jun 2025 05:25:17 GMT</pubDate>
            <atom:updated>2025-06-27T14:21:25.701Z</atom:updated>
            <content:encoded><![CDATA[<p>In JavaScript, we define functions most of the time in two ways one is Implicit Fun or we called Anonymous Fun ex we use Arrow Fun and Explicit Fun.</p><p>In this article, we will learn about the difference between both of them and how we can use them.</p><ul><li>What is an Arrow Function?</li><li>Implicit vs Explicit fun</li><li>How to use implicit and Explicit in JSX</li></ul><h3>What is Arrow Fun?</h3><p>Arrow Fun is the more readable way to write the fun but with these cons, there come the cons</p><pre>const greet = (a) =&gt; console.log(&quot;Hello World&quot;,a)<br><br>// Since the arrow function body has only a single statement (console.log),<br>//so we dont need tht return in the arrow fun<br></pre><ul><li>Arrow fun inherits <strong>this</strong> from the outer scope that&#39;s why it cant use as the methods</li><li>The Cons are Arrow Fun doesn’t have their own binding to this so they can’t use it as the method or constructor</li></ul><pre>const obj = {<br>name: &quot;MrBlackGhost&quot;,<br>greet: () =&gt; console.log(`Hello, ${this.name})<br>}<br>obj.great() <br>// &quot;Hello, undefined&quot; because &#39;this&#39; is not bound to &#39;obj&#39;<br><br>const obj = {<br>name: &quot;MrBlackGhost&quot;,<br>greet(){console.log(`Hello, ${this.name})}<br>}<br>obj.great() // Hello MrBlackGhost<br></pre><h3>Implicit Arrow Functions Explained</h3><p>When the fun doesn&#39;t have to do much and only requires one line to then we use the Implicit type in this we don&#39;t have to write the return</p><pre>const add = (a,b) =&gt; a + b<br><br>// or<br><br>const add = (a,b) =&gt; (<br>a + b <br>)<br></pre><p>We are returning the value without using the return that we can do in the implicit fun, and we can use this way if the fun is not complex.</p><p>Explicit Arrow Functions Explained</p><p>When our fun has to do more and its contains more logic init we have to explicitly use the return as fun knows which value is being passed</p><pre>const no = (a) =&gt; {<br>if (a % 2 == 0){<br>return &quot;Even no&quot;<br>}<br>else {<br>return &quot;odd no&quot;<br>}<br></pre><p>if we do not pass the return here it gives us the <em>undefinied</em> <strong>type error </strong>As you see, we define the add function with two parameters and return the result the no even or not.</p><h4>How to use implicit and Explicit in JSX:-</h4><p>We gonna use it inside the Array. Map as most of the time we use in that way</p><pre>{<br>Array.map((item, index)=&gt;(<br>&lt;p key={index}&gt;{item}&lt;/p&gt;<br>)<br>}</pre><p>As we used the<strong> ( ) </strong>we did not have to use the return</p><p>This is an example of the Explicit in JSX</p><pre>{<br>Array.map((item, index)=&gt;{<br>return &lt;p key={index}&gt;{item}&lt;/p&gt;<br>}<br>}</pre><h3>Conclusion</h3><p>In this article, we read about two types of funs and one where to use.</p><p>Arrow fun makes your code cleaner but choosing the right one depends on the <strong>complexity </strong>and <strong>readability. I </strong>hope now you understand the difference between Implicit and explicit fun and how to use it in the JSX too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e441c3c8e96" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>