<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gaurav Sethi</title>
    <description>The latest articles on DEV Community by Gaurav Sethi (@gaurav0s).</description>
    <link>https://dev.to/gaurav0s</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4092856%2Fb449ad75-2409-490f-8edb-4a7ab7f700f6.png</url>
      <title>DEV Community: Gaurav Sethi</title>
      <link>https://dev.to/gaurav0s</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gaurav0s"/>
    <language>en</language>
    <item>
      <title>Building LinkCut: A Sub-20ms URL Shortener with Next.js, FastAPI, and Redis</title>
      <dc:creator>Gaurav Sethi</dc:creator>
      <pubDate>Mon, 24 Aug 2026 19:29:42 +0000</pubDate>
      <link>https://dev.to/gaurav0s/building-linkcut-a-sub-20ms-url-shortener-with-nextjs-fastapi-and-redis-52a1</link>
      <guid>https://dev.to/gaurav0s/building-linkcut-a-sub-20ms-url-shortener-with-nextjs-fastapi-and-redis-52a1</guid>
      <description>&lt;p&gt;Hi, i'm Gaurav. This is my first post to dev.to&lt;/p&gt;

&lt;h2&gt;
  
  
  What is LinkCut?
&lt;/h2&gt;

&lt;p&gt;LinkCut is a free, open-source URL shortener with no signup required — paste a link, cut it, share it. No accounts, no tracking cookies, no dashboard bloat.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔗 Live app: &lt;a href="https://linkcut-nine.vercel.app/" rel="noopener noreferrer"&gt;https://linkcut-nine.vercel.app/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💻 Repo: &lt;a href="https://github.com/Gaurav5189/url-shortener" rel="noopener noreferrer"&gt;https://github.com/Gaurav5189/url-shortener&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why I built it
&lt;/h2&gt;

&lt;p&gt;I wanted to design a system where redirect latency actually mattered, not just a CRUD app with a UI wrapper. That meant thinking about caching, write-amplification, and decoupling reads from writes — not just "shorten a string and save it to a DB."&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;The core idea: &lt;strong&gt;separate the fast path from the slow path.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Fast path (Edge Middleware):&lt;/strong&gt; checks Redis first, returns a 302 redirect directly from the edge, and fires a non-blocking &lt;code&gt;INCR&lt;/code&gt; for click tracking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Slow path (Backend fallback):&lt;/strong&gt; on a cache miss, FastAPI decodes the Base62 short code to an integer ID for an O(1) indexed lookup in SQLite, then repopulates Redis with a 12-hour TTL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Background path (Cron):&lt;/strong&gt; flushes Redis click counters into SQLite periodically using an atomic Lua script — read-and-delete in a single Redis transaction, so counts never get double-counted or lost.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This keeps redirects fast (sub-20ms) while analytics writes stay off the hot path entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tech stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frontend/Edge:&lt;/strong&gt; Next.js (App Router) on Vercel Edge Middleware&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache/Counter:&lt;/strong&gt; Redis&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend:&lt;/strong&gt; FastAPI&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database:&lt;/strong&gt; SQLite&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encoding:&lt;/strong&gt; Base62, 5-character codes from auto-incrementing IDs (~916M capacity)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;I underestimated this going in. The URL shortening part is trivial — the interesting engineering is in the caching strategy, avoiding database write-amplification on every click, and making sure the analytics counter flush is atomic so nothing gets lost or double-counted under concurrent traffic.&lt;/p&gt;

&lt;p&gt;Feedback on the caching strategy or architecture decisions welcome — always looking to improve it.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>fastapi</category>
      <category>nextjs</category>
      <category>redis</category>
    </item>
  </channel>
</rss>
