<?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: Jeevan Joshi </title>
    <description>The latest articles on DEV Community by Jeevan Joshi  (@jeevanjoshii).</description>
    <link>https://dev.to/jeevanjoshii</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1446575%2F853beabe-5959-4e6d-841e-310cefb48789.jpg</url>
      <title>DEV Community: Jeevan Joshi </title>
      <link>https://dev.to/jeevanjoshii</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jeevanjoshii"/>
    <language>en</language>
    <item>
      <title>What URL Shortener is and how does it work?</title>
      <dc:creator>Jeevan Joshi </dc:creator>
      <pubDate>Sat, 19 Jul 2025 11:16:49 +0000</pubDate>
      <link>https://dev.to/jeevanjoshii/what-url-shortener-is-and-how-does-it-work-1j3f</link>
      <guid>https://dev.to/jeevanjoshii/what-url-shortener-is-and-how-does-it-work-1j3f</guid>
      <description>&lt;p&gt;Have you ever wondered how the URL shortener or tiny url works? The Engineering behind it upholds the efficiency, scalability and security of the system we often take for granted.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5a8o05jt5xrqc6x9ok2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq5a8o05jt5xrqc6x9ok2.png" alt="Stickman trying to understand the logic of URL Shortener" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From generating a shorten version of a url to fetching and redirecting it to its actual destination, the engineering behind it beautifully showcases the elegance of simplicity backed by powerful systems.&lt;/p&gt;

&lt;p&gt;To understand the Engineering behind it, let’s start with the crucial component of it called compression or Encoding. To achieve the compression the system uses the Base-62 or Base-64 encoding, and what Base-62 or Base-64 encoding is?&lt;/p&gt;

&lt;p&gt;Many of us know how to convert a &lt;strong&gt;Decimal Number&lt;/strong&gt; to a &lt;strong&gt;Binary Number&lt;/strong&gt;, it is called the Base-10 to Base-2 conversion, where we basically use the LCM logic to convert the Base-10 number to Base-2 number, for reference have a look at the image below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqe6hdbltalfvgywkd33.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqe6hdbltalfvgywkd33.png" alt="Illustration of Base 2 conversion" width="388" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above image shows how A Base 10 digit gets converted to Base 2, where we divide the Base 10 digit with 2 repeatedly (with the base), and if reminder becomes greater than 0 then corresponding bit/number becomes 1 else 0.Finally, we read the number in bottom to up (reverse order), which gives us the Base 2 representation of the number.&lt;/p&gt;

&lt;p&gt;e.g. 32 Base-10 represented as 100000 in Base-2&lt;/p&gt;

&lt;p&gt;Now imagine having a Base 10 number as 100 Billion, Representing such large numbers in base-10 becomes cumbersome, not just in storage but also in readability and transmission. To make it more manageable, readable we encode the number to a Base-64/Base-62 number, in base-64 each digit can be represented as 64 possible values, resulting in the significant length compression.&lt;br&gt;
Base-10: 100000000000 (100 Billion)&lt;/p&gt;

&lt;p&gt;Base-2: 01011101001000011101101110100000000000&lt;/p&gt;

&lt;p&gt;Base-64:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe9f6fza0rsalg91jggzq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe9f6fza0rsalg91jggzq.png" alt="Illustration of the calculation of Base 64 length of 100 billion" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The length will be 7, now let’s see how we use it in the URL Shortening.&lt;/p&gt;

&lt;p&gt;A URL can be of any length, to make a tiny URL or short URL for the corresponding URL, we have Base-64 encoding, which consist of Numbers from 0 to 9, Uppercase and Lowercase character from A to Z and a to z, and two special characters underscore and hyphen (_, -).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now how does we compress the URL?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A URL directly does not get compressed to a tiny URL but it’s index or id (Unique Identifier) of database entry gets compressed to a Base-64 from Base-10. Have a look at the below JSON Object:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6w9lzl3sbizwu0l44q71.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6w9lzl3sbizwu0l44q71.png" alt="Object with Base 10 ID" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here in this above JSON block the unique Identifier is 10032, which can be converted to 2sM, and then this ID will be used to make the URL tiny, for example: &lt;a href="https://example.com/2sM" rel="noopener noreferrer"&gt;https://example.com/2sM&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwuzwemqsw1ucllwfchg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwuzwemqsw1ucllwfchg.png" alt="Object with Base 64 ID" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the question arise that how it gets converted to “2sM”, so it is so basic that we have an array/String of all the allowed Base-64 characters and some mathematical logic of getting the reminders, where we get reminder of the integer id with 64, and add its corresponding index character to the resulting string, and then we divide the original number to 64 repeatedly until it become ≤ 0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2b9pvvehxi4qperxumz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2b9pvvehxi4qperxumz.png" alt="JavaScript code snippet of Base64 Encoding" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now by converting the database id into shorter, encoded string, we create a tiny representation of that document or entry. this tiny string act as a Key that maps back to the original URL stored in the database. The entire tiny URL system fundamentally relies on this logic beneath. (this logic is also used by YouTube to create their platform videos unique IDs)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now let’s understand how the Entire Working Happens.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;when you hit a tinyurl (e.g. &lt;a href="http://example.com/xyz" rel="noopener noreferrer"&gt;http://example.com/xyz&lt;/a&gt;) it first requests the server to check the cache (Redis or any other) database, if there exist any entry with the id &lt;strong&gt;“xyz”&lt;/strong&gt; if cache hits, it sends back the original URL with the redirect command, otherwise the server then checks its databases, if still there is no entry then 404 will be responded otherwise the server sends back the Original URL and also updates the cache (if bulk query comes) and tracks the clicks, IP and other information of the user through the Headers of the packet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgcnbna0blyrtk6cu251g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgcnbna0blyrtk6cu251g.png" alt="Flowchart of Process" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now after fetching the Original URL the website/App simply redirects you to the corresponding website or provides a button to redirect you to the website.&lt;/p&gt;

&lt;p&gt;Even wondered what we can craft with this logic, we can create a TTL (Time to Live) based mechanism for a particular link giving database an advantage to have more links with a single identifier, where the server redirects to the only link which is currently is not expired. Or also we can craft a Location based URL maybe give your ideas in the comment section.&lt;/p&gt;

&lt;p&gt;With that I bind my words, and I hope you understand the logic behind URL shortener, I’ll soon be releasing an article entitled “The High-level and Low-level system design behind the Tiny URL”.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>urlshortener</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
