<?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 Rajat Sharma on Medium]]></title>
        <description><![CDATA[Stories by Rajat Sharma on Medium]]></description>
        <link>https://medium.com/@rajat901cx?source=rss-7319c5c2bb2e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*f0tgk_DlPcybHjZkwXnENQ.jpeg</url>
            <title>Stories by Rajat Sharma on Medium</title>
            <link>https://medium.com/@rajat901cx?source=rss-7319c5c2bb2e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:23:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajat901cx/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[QUIC: The brand new protocol of the Internet]]></title>
            <link>https://rajat901cx.medium.com/quic-the-brand-new-protocol-of-the-internet-32843269858e?source=rss-7319c5c2bb2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/32843269858e</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[future]]></category>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[web]]></category>
            <dc:creator><![CDATA[Rajat Sharma]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 22:20:45 GMT</pubDate>
            <atom:updated>2021-06-06T22:20:45.679Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Quic Protocol" src="https://cdn-images-1.medium.com/max/300/1*ntE-yUymOHlgE-kw3Attlg.png" /></figure><p>Before I start throwing out some technical jargon related to <strong>QUIC</strong> I would like to take some time to put simply, <strong>How the internet works now and where exactly QUIC comes in.</strong></p><p>Although its name was initially proposed as the acronym for <strong>“Quick UDP Internet Connections”</strong>. IETF’s use of the word QUIC (pronounced <strong>“quick”</strong>) is not an acronym, it is simply the name of the protocol.</p><p><strong>NOTE: IETF is the principal technical development and standards-setting body for the Internet.</strong></p><h3><strong>THE CURRENT WORKINGS OF THE INTERNET</strong></h3><p>The internet works on what is popularly known as the <strong>TCP/IP Protocol.</strong></p><p>The <strong>TCP (Transmission Control Protocol) handles the data transmission part</strong> between two computers in a network whereas <strong>IP (Internet Protocol) is the set of rules which gives identity to these two computers</strong> among millions of computers in a network.</p><p>Next, let us talk about the <strong>World Wide Web (WWW) or simply the web. </strong>Although the internet and web are used interchangeably. Technically Web works on top of the Internet. The Internet is a connection of computers and is responsible for the transfer of data between these computers whereas the web is the platform that serves this data in form of pages.</p><blockquote><strong>So whatever you see is the Web and whatever happens in the background is the Internet.</strong></blockquote><p>The web is governed by what is called the <strong>HTTP (Hypertext Transfer) Protocol). </strong>All the data transfer we just talked about does not happen on its own. There is typically a <strong>Client (Your PC)</strong> and a <strong>Server (The Website).</strong></p><p>The client makes an HTTP request to a server which in turn sends a response. For <strong>transporting data</strong> we need to establish a connection between the Client and the Server. To establish this connection HTTP uses TCP as a standard protocol. <strong>It is this connection process we are most interested in.</strong></p><p>There are different versions of the HTTP protocols. The most popular and widely used being <strong>http/1.1 (plain HTTP</strong>) and <strong>http/2 (HTTPS) </strong>with the latter being the current standard for websites and web applications<strong>. </strong>Both of these versions use<strong> TCP as the standard protocol for data transport and connection.</strong></p><h3>QUIC v/s TCP</h3><p>Let us talk about QUIC now.</p><p>QUIC is an <strong>encrypted </strong><a href="https://en.wikipedia.org/wiki/OSI_model#Layer_4:_Transport_Layer"><strong>Transport Layer</strong></a><strong> Network Protocol</strong>. QUIC was designed to make HTTP traffic more <strong>secure, efficient, and faster.</strong></p><p>Its initial development<strong> started at Google</strong> and was implemented and deployed internally as early as in the year <strong>2012</strong>.</p><p>QUIC makes use of <strong>UDP (User Datagram Protocol) </strong>which is another Transport Layer Protocol that can be used for data transportation and is <strong>often an alternative to TCP for applications where data transfer speed is the top priority.</strong></p><p>Let us now discuss some of the drawbacks of using TCP as a Transport Layer Protocol (Layer 4 Protocol, Ref. <a href="https://medium.com/theleanprogrammer/osi-model-layers-explained-ee1d43058c1f">OSI Model</a>).</p><p><strong>DRAWBACKS OF USING TCP AT LAYER 4</strong></p><ol><li><strong>The major drawback with TCP is its initial setup time before the data transfer can even begin.</strong></li></ol><p>TCP involves what is called a <strong>3 way TCP Handshake</strong> which is all about setting the initial connection between the Client and the Server. It is then followed by a <strong>TLS Handshake </strong>which is responsible for the encryption of data and is a feature of the more popular http/2 (HTTPS) version of the HTTP protocol. This all happens before the actual data can be transferred and is a <strong>time-costly operation.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*EiwfvYlKP4xAqhaWIry-ow.png" /><figcaption><strong>TCP 3 Way Handshake</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*PSUCu0GBnYjPmXFHnP1Hvg.png" /><figcaption><strong>TLS Handshake in http/2</strong></figcaption></figure><p>2. The next major problem is the<strong> Head of Line Blocking problem.</strong></p><p>So the number of TCP connections per client to a server is limited. In <strong>http/1.1</strong> this limit is usually around 6. The problem with this is if all the 6 connections are blocked no more requests can be sent over any TCP Connection.</p><p>This problem was solved by a concept of <strong>pipelining</strong> however it caused more problems so it was not widely accepted. This was finally solved in <strong>http/2 which helped multiplexed multiple requests over the same TCP Connection.</strong></p><p>The http/2 however suffers from another type of Head of Line Blocking at Layer 4 which is mainly due to the TCP feature of <strong>Congestion Control. </strong>TCP’s guarantee of ordered delivery and congestion control can <strong>block TCP stream if a packet is lost during transmission.</strong> The current and all other streams will have to wait for the packet to be re-transmitted and received again to continue transmission.</p><p>These were the 2 major drawbacks QUIC intended to solve as mentioned in QUIC’s <strong>IETF (Internet Engineering Task Force) </strong>draft.</p><h3><strong>What does QUIC do differently?</strong></h3><p>At the heart of QUIC is the use of <strong>UDP (User Datagram Protocol).</strong></p><p>UDP happens to be a <strong>connectionless protocol</strong> with minimum protocol mechanisms (No Handshakes) which makes the Packet Size in UDP much smaller than that of a TCP’s which is a <strong>connection-based protocol. </strong>The very definition of UDP sheds some light <strong>on solving the initial set-up time problem.</strong></p><p>Also, UDP does not guarantee delivery, ordering, congestion control, duplication control, etc. which seems to solve the <strong>Head of Line Blocking Problem.</strong></p><p>It has never been like TCP is the more popular protocol and should be used everywhere. Applications such as <strong>games, streaming, VoIP based services</strong> use some <strong>UDP-based implementation in Layer 4</strong> for their Servers. The common string being all the above-mentioned applications require low latency hence the speed of the service is the number one priority and certain TCP procedures are not required. <strong>Time-sensitive applications often use UDP because dropping packets is preferable to waiting for packets delayed due to retransmission, which may not be an option in a real-time system.</strong></p><p>Having talked about UDP so much let me also clarify that <strong>QUIC is not simply UDP</strong> as if we replace TCP with UDP and we get QUIC. That is not the case.</p><p>QUIC as mentioned does use UDP in its implementation and the features of UDP are good enough to explain the working of QUIC on a high level.</p><p><strong>All in all, QUIC has taken all the best qualities of TCP connections and TLS encryption and implemented them on UDP.</strong></p><h3><strong>Does anyone really use QUIC?</strong></h3><p>QUIC is backed by <strong>Google</strong> and <strong>Cloudflare</strong>. It would not be wrong to say Google is the parent to QUIC as the most early-stage developments with QUIC started at Google. <strong>All the connections to google servers are made through QUIC.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZ17Kb2cydQoM2dMBYZx2A.jpeg" /><figcaption><strong>Wireshark trace of packets transferred using QUIC, These are the initial packets when I started Google Chrome. If you type in 172.217.167.164 in your browser and press enter you would reach google.com</strong></figcaption></figure><blockquote>The above image demonstrates that how Google has <strong>http/3 using QUIC</strong> already in action.</blockquote><p><strong>Microsoft </strong>also uses its own version of QUIC for certain applications.</p><p><strong>Facebook</strong> also has its own implementation of QUIC, called<a href="https://github.com/facebookincubator/mvfst"> <strong>mvfst</strong></a><strong>.</strong></p><p><strong>Cloudflare</strong> claims to detect detect “<strong>around 12% of Internet traffic using QUIC with HTTP/3</strong>” which can be partly due to people using google chrome, youtube, blogger, and other Google offerings.</p><h3>Recent Developments with QUIC and why talk about it all of a sudden</h3><p>As mentioned at the start of the article<strong> IETF</strong> is the principal technical development and standards-setting body for the Internet.</p><p>Most of the protocols we use for the Internet are already standardized by IETF hence leading to widespread adoption.</p><p>QUIC has been one of the IETF’s most high-profile activities in recent years.</p><blockquote>The IETF on <strong>May 27, 2021</strong>, published QUIC as <a href="https://www.rfc-editor.org/info/rfc9000"><strong>RFC 9000</strong></a>, supported by <a href="https://www.rfc-editor.org/info/rfc9001"><strong>RFC 9001</strong></a>, <a href="https://www.rfc-editor.org/info/rfc9002"><strong>RFC 9002</strong></a>, and <a href="https://www.rfc-editor.org/info/rfc8999"><strong>RFC 8999</strong></a><strong>.</strong></blockquote><p>An RFC stands for <strong>Request for Comments </strong>and in our case is like a technical document authored by Engineers and Computer Scientists working heavily on QUIC. It is published both for peer review and to convey new concepts and information.</p><blockquote><strong>This simply means QUIC version 1 is officially formalized, and QUIC deployments will now move away from using temporary draft versions to the recently arrived version 1.</strong></blockquote><p>The bottom line being this development will speed up the adoption of the QUIC by many organizations and the Internet in general who might have been skeptical until now.</p><p><a href="https://datatracker.ietf.org/doc/html/draft-ietf-quic-http-34"><strong>HTTP/3</strong></a>, the version of HTTP that runs on QUIC is expected to be published soon.</p><p>The adoption of QUIC and replacing TCP might not be an overnight process but it does have a lot of promise and it would be interesting to see how this development progresses.</p><p>QUIC is all about faster Internet and is already being used by tech giants like <strong>Google, Facebook, </strong>and<strong> Microsoft. </strong>It<strong> </strong>would be nice to see<strong> websites, applications, and networking libraries</strong> start offering QUIC for general use in the near future unlocking new dimensions for the Internet.</p><blockquote>Congrats! on making it to the end, I can guarantee that your knowledge about the Internet just went a notch higher.</blockquote><blockquote>The motivation to write this is due to May 27, 2021, RFC 9000 that gives the first formalized version of QUIC. I think everyone should know about this as this will effect internet directly in the near future, <strong>so do share it with your peers.</strong></blockquote><blockquote>Feel free to connect with me about technical stuff,<br><a href="https://www.linkedin.com/in/devrajat/">https://www.linkedin.com/in/devrajat/</a></blockquote><p><a href="https://github.com/RajatSvN">RajatSvN - Overview</a></p><blockquote><a href="https://twitter.com/RajatSvN">https://twitter.com/RajatSvN</a></blockquote><blockquote><strong>References</strong></blockquote><ul><li><a href="https://datatracker.ietf.org/doc/html/rfc9000">rfc9000</a></li><li><a href="https://medium.com/theleanprogrammer/osi-model-layers-explained-ee1d43058c1f">OSI Model Layers — “Explained”</a></li></ul><blockquote><a href="https://community.akamai.com/customers/s/article/How-does-HTTP-2-solve-the-Head-of-Line-blocking-HOL-issue?language=en_US#:~:text=Head%20of%20Line%20blocking%20(in,connection%20to%20complete%20before%20the">https://community.akamai.com/customers/s/article/How-does-HTTP-2-solve-the-Head-of-Line-blocking-HOL-issue</a></blockquote><ul><li><a href="https://www.theregister.com/2021/05/31/quic_becomes_standard/">TCP alternative QUIC reaches IETF&#39;s Standards Track after eight years of evolution</a></li><li><a href="https://www.fastly.com/blog/quic-is-now-rfc-9000">QUIC is now RFC 9000</a></li></ul><blockquote><a href="https://engineering.fb.com/2020/10/21/networking-traffic/how-facebook-is-bringing-quic-to-billions/">https://engineering.fb.com/2020/10/21/networking-traffic/how-facebook-is-bringing-quic-to-billions/</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32843269858e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My learning experience at Crio Winter of Doing]]></title>
            <link>https://rajat901cx.medium.com/my-learning-experience-at-crio-winter-of-doing-b53776fb3e0a?source=rss-7319c5c2bb2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b53776fb3e0a</guid>
            <dc:creator><![CDATA[Rajat Sharma]]></dc:creator>
            <pubDate>Fri, 15 Jan 2021 06:14:00 GMT</pubDate>
            <atom:updated>2021-01-15T06:14:00.006Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Crio Winter of Doing" src="https://cdn-images-1.medium.com/max/800/1*a31uHfRxc6Mx6jLbKwiIfQ.png" /></figure><p>In this post, I would be sharing my experience at the <strong>Tech Externship</strong> program named <strong>Crio Winter of Doing.</strong></p><p><strong>Crio </strong>is<strong> </strong>a developer-friendly learning platform that focuses on <strong>learning by doing</strong> making them a unique organization in the EdTech domain.</p><h3><strong>What the heck is a Tech Externship? </strong>🙋</h3><p>Tech externships are experiential learning opportunities, <strong>similar to internships, but shorter and part-time,</strong> provided in partnership with tech companies. Crio Winter of Doing externships are a great opportunity for you to <strong>solve real-world problems</strong> in an actual<strong> tech startup setting</strong>, and learn key skills that will help you advance your dev career.</p><h3><strong>A bit about my background</strong></h3><p>Talking about my background might sound unnecessary but trust me it will give you a better perspective about this experience and why it is <strong>one of those programs every up and coming Developer should be looking forward to.</strong></p><p>Hi! My name is Rajat. I am a final year engineering undergraduate and a Full Stack Developer(not really, more of a backend guy 😛). I am someone whom you would not consider an absolute beginner to programming and development 👨‍💻 and for proof of concept you can check <a href="https://linkedin.com/in/devrajat"><strong>here</strong></a></p><p>That being said I can definitely point out some of the more interesting stuff during this learning experience which would have been hard to identify if I were at the start of my dev journey.</p><p><strong>Note:</strong> The program is divided into 3 stages, I am going to share the experience of stage 1 for now. This stage is more of a warm-up round in which you learn about concepts like <strong>HTTP</strong>, <strong>REST</strong>, <strong>Linux Basics</strong>, <strong>App Deployment in AWS</strong>, and <strong>Git</strong>.</p><p>Enough of the boring talk, now let’s get started with the real stuff.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*-Buvz9zN-9zTRdsWtKkHJQ.gif" /><figcaption>Source: Tenor</figcaption></figure><h3><strong>Learning about HTTP</strong></h3><p><strong>What I thought I would learn?</strong></p><p>Get to learn the basics of HTTP and a little something about requests.</p><p><strong>What I actually ended up doing and learning….</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*sRHsmH2tTfzvbSDIRDboNw.png" /><figcaption>Learn about http by using Dev Tools</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p482ZT7INDbb4kWidHSYNg.png" /><figcaption>No boring definitions on requests, get hands-on with requests and <strong>understanding response headers</strong> and <strong>request payloads</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*tjSmNQ1z39FR_S7WYr_J7A.png" /><figcaption>Composing an<strong> HTTP request over TCP</strong>, Got to the bottom of understanding TCP (Cool stuff right 😎)</figcaption></figure><h3><strong>Learning about REST</strong></h3><p><strong>What I thought I would learn?</strong></p><p>learn that REST stands for Representational State Transfer (we all expect this don’t we 😂), How GET has request parameters visible and POST does not (this one too 😅)</p><p><strong>What I actually ended up doing and learning….</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hLJPjafH0NKlchhhP8Du2g.png" /><figcaption>How <strong>REST requests</strong> happen all the time.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ti718hEZuYd9Sd5TPyrn2g.png" /><figcaption><strong>Dissecting REST in the browser</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1whzNC1MK7Bl_xMvWJQGw.jpeg" /><figcaption>Building and making requests to REST APIs using <strong>Java and Python </strong>(BTW I know how you are thinking that Python 🐍 is so cool, so less code to write 🤨)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*HGX1YCAYFftKO1F2N3CNNg.png" /><figcaption>Making a <strong>Linkedin POST through Terminal</strong> using Linkedin’s REST API, Pretty cool I know!</figcaption></figure><h3><strong>Learning Linux</strong></h3><p><strong>What I thought I would learn?</strong></p><p>Do a bunch of basic commands like cd, ls, mkdir, rmdir, rm, rm -rf, etc.</p><p>P.S. did all of this too, but early on</p><p><strong>What I actually ended up doing and learning….</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*cjErgVYddqXQV2YLyFycWQ.jpeg" /><figcaption><strong>Piping</strong> and <strong>Redirection</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*ezNHrk_xQwPkPJdZAf9NCA.jpeg" /><figcaption><strong>OpenSSH</strong> Log analysis using the command line (Full Hacker feels 👨‍💻) Check the script <a href="https://gist.github.com/RajatSvN/54c3aefbbb321ac727303a7963539e0f"><strong>here</strong></a><strong> </strong>👈</figcaption></figure><h3><strong>Learning about AWS</strong></h3><p><strong>What I thought I would learn?</strong></p><p>Create an AWS account, create an EC2 instance.</p><p><strong>What I actually ended up doing and learning….</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*NqrPHaR8nBBMZJcOvollhQ.jpeg" /><figcaption><strong>SSH</strong> into the EC2 instance</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*QlxeX9PftmLzEWQ9bEaxUA.png" /><figcaption>Setting up and running QEats app using <strong>Docker</strong>🐳 (Yeah Docker, you heard it right! 😇)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*jgv6PBwzMmw4ytXztUCIcg.png" /><figcaption><strong>Accessing the App Server</strong> from the Android App</figcaption></figure><h3><strong>Learning GIT</strong></h3><p><strong>What I thought I would learn?</strong></p><p>Create a Github repository, adding a Readme file with the commit message “Add Readme” (C’mon we all did this 😂)</p><p><strong>What I actually ended up doing and learning….</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*EQojZe0pviVMv9eDfsBKnA.png" /><figcaption>Creating a <strong>Merge Conflict</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEPRsXXMekIH7U9x3ZURnQ.png" /><figcaption>Handling <strong>Merge Conflict</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*6JohqItB8pa2iMF31TjksA.jpeg" /><figcaption>Using <strong>git log</strong> efficiently</figcaption></figure><p>You might be thinking that’s it. But….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*2U5cnm2eGFy3jLsq-bEWgA.gif" /><figcaption>Source: Tenor</figcaption></figure><p>Yes, there is more to <strong>Crio Winter of Doing.</strong></p><h3><strong>BIG VARIABLE SERIES TALK</strong></h3><p>Chat with the most inspirational Indian entrepreneurs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*osdZk7YqryjkpBscls1UcA.jpeg" /><figcaption>Fireside Chat with <strong>Mr. Binny Bansal, Co-Founder, Flipkart.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J6ob4FkEw_4BpwwGWxnILA.jpeg" /><figcaption>Fireside Chat with <strong>Mr. Vivek Ravisankar, Co-Founder and CEO, HackerRank.</strong></figcaption></figure><h3><strong>HANDS-ON SESSION WITH THE EXPERTS</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1fHmc0YMODDLQylVEVTHGA.jpeg" /><figcaption>REST Hands-on Session with <strong>Mr. Sridher Jeyachandran, Co-founder, Crio.do</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fIMc3QbQCzziAoC48S5T9w.jpeg" /><figcaption>Linux Hands-on Session with <strong>Mr. Kiran Suresh, Lead Product Engineer, Crio.do</strong></figcaption></figure><h3><strong>The Community</strong></h3><p>For any long-term program, if you have a good community of fellow developers to support you, your life becomes very easy. It has been amazing seeing people pushing hard to complete their tasks and at the same time helping their peers. Anyone part of this community definitely feels lucky 😇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*_zREtDZkGG0pg86Mq7O4lg.png" /><figcaption><strong>Helping others and getting help is totally divine</strong></figcaption></figure><p>When I started I thought about what new can I learn in a basics class. However, Crio’s modules definitely surprised me! Its approach is pretty hands-on and developer-centric. Think of it as reading well-written software documentation which is definitely the developer’s way.</p><p>Overall my learning experience has been amazing till now and would definitely suggest you to look out for all future Crio programs.</p><p>If you liked this post please show some ❤️ and do not forget to 👏🏻</p><p>P.S. This happens to be a part of the #shareyourlearning challenge. The most liked post’s author gets goodies. So yes please help me win. (Yeah I am goody greedy 😏)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b53776fb3e0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a custom URL shortening service for your website?]]></title>
            <link>https://rajat901cx.medium.com/how-to-build-a-custom-url-shortening-service-for-your-website-2f89817ec615?source=rss-7319c5c2bb2e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f89817ec615</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[full-stack-development]]></category>
            <category><![CDATA[url-shorteners]]></category>
            <category><![CDATA[custom-url-shortener]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Rajat Sharma]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 12:36:49 GMT</pubDate>
            <atom:updated>2020-06-10T12:41:42.260Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to build a custom URL shortening service ?</h3><figure><img alt="title image showing a long url to be shortened" src="https://cdn-images-1.medium.com/max/500/1*_m0IrLr0pnYeYr63MoCNJg.gif" /><figcaption>URL Shortener Service</figcaption></figure><p>If you are a full-stack developer then chances are that at some point in time you would need to build a URL shortening service for your product. You might want to use 3rd party URL shorteners like tinyurl.com, bitly.com, rebrandly.com, etc. which are great but at certain times creating your own service would be far more suitable for many reasons including cost, workloads, etc. So, in this post, we will learn how to create a basic URL shortening service.</p><p><strong>What is a Short URL?</strong></p><p>A short URL is a redirect URL with very few characters compared to the URL it redirects to. The image in the section below tells you exactly the same.</p><p><strong>Breaking the Short URL</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_xAZ969gjRiOPjp-Nli69Q.png" /><figcaption>What it looks like at the end</figcaption></figure><p>Above is a glimpse of what our service actually looks like in the end.</p><p>There are generally two parts to any short URL:-</p><ol><li><em>A small domain name</em></li></ol><p><em>2. A unique identification string</em></p><p>In our case the small domain name is <strong><em>smlr.ml</em></strong> .The choice of a small domain name is implicit because the ultimate goal is to reduce the number of characters in the query URL. The unique identification string here is <strong><em>9qpy </em></strong>which acts as a key to a particular Long URL in the database i.e. whenever a particular key is present it fetches the corresponding URL from the database and redirects to it. This will become more clear in the next sections.</p><p><strong>Following Along</strong></p><p>If you want to follow along then you would need a domain name and a hosting service provider. If you already use some form of hosting services then you should try getting a free domain name from <a href="https://freenom.com/">freenom.com</a>. However, if you want it to build it in some professional capacity then please purchase a domain as free domains can be taken down any time. If you want to follow along for practice then you can build it in your local environment too, your small domain name, in that case, would be localhost :) I would be using PHP and MySQL here but you can use any language of your choice as it is only a matter of semantics :)</p><p><strong>Coding the Service</strong></p><p>We would be creating 5 files here,</p><ol><li><strong>service.php</strong>:- This file will have the frontend of our URL shortening service and will do an ajax request to urlshort.php</li><li><strong>urlshort.php</strong>:- This file is responsible for making entries in the database based upon the request made from service.php. It contains the database entry logic.</li><li><strong>index.php</strong>:- All the redirects to the original long URL happen from this page. Whenever a short URL is clicked it goes to the index page with the unique identification string. At the index page, we extract this string and redirect to the corresponding long URL by fetching from the Database.</li><li><strong>.htaccess</strong>:- This is essentially a configuration file and may already be present. We will add some rules to it, to give a cleaner look to our short URL.</li><li><strong>connection.php</strong>:- This is just a simple connection file to the database.</li></ol><p><strong>Setting up the MySQL Database and connection file</strong></p><p>Go to PHPMyAdmin or corresponding Database Management Service in your backend of choice and create a database. Create a table with the name <strong><em>urlshort </em></strong>and make it have the following structure,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IXbXtUw6GyXDAL5Z9QFa-Q.png" /><figcaption>Structure for table urlshort</figcaption></figure><p>The table should essentially have an Auto Incremented <strong>ID</strong>, a <strong>url</strong> column of type text to store the long url where we will redirect to, and an <strong>identifier</strong> column for the unique identification string.</p><pre>&lt;?php</pre><pre>$mysqli = new mysqli(&quot;localhost&quot;,&quot;db_username&quot;,&quot;db_password&quot;,&quot;db_name&quot;);</pre><pre>if ($mysqli -&gt; connect_errno) {<br>    echo &quot;Failed to connect to MySQL: &quot; . $mysqli -&gt; connect_error;<br>    exit();<br>  }</pre><pre>?&gt;</pre><p>The <strong>connection.php</strong> file should look like above.</p><p><strong>Creating service.php</strong></p><p>The service.php file essentially has our little URL submission form and code for an ajax request. You are free to beautify your form using the framework of your choice. I will discuss only the <strong>ajax request</strong> here to keep the post<strong> concise and to the point</strong>. The <strong>complete project files</strong> can be found at <strong>the end of the post</strong>.</p><pre>$.ajax({</pre><pre>method:&quot;POST&quot;,<br>url:&quot;urlshort.php&quot;,<br>data:{<br>url:url<br>}</pre><pre>}).done(function(response){</pre><pre>// convert JSON string to JSON using parse()</pre><pre>response = JSON.parse(response);</pre><pre>if(response.hasOwnProperty(&#39;success&#39;)){</pre><pre>/* if urls shortening was successful then it will have key of success */</pre><pre>$(&quot;.error&quot;).html(&quot;&lt;p class=&#39;text-muted&#39; style=&#39;color:green !important;&#39;&gt;&quot;+response[&#39;success&#39;]+&quot;&lt;/p&gt;&quot;+&quot;&lt;p class=&#39;text-muted&#39; style=&#39;color:green !important;&#39;&gt;The shortened url is : &lt;a href=&#39;http://&quot;+response[&#39;short_url&#39;]+&quot;&#39;&gt;&quot;+response[&#39;short_url&#39;]+&quot;&lt;/a&gt;&lt;/p&gt;&quot;);</pre><pre>}else{</pre><pre>$(&quot;.error&quot;).html(&quot;&lt;p class=&#39;text-muted&#39; style=&#39;color:red !important;&#39;&gt;&quot;+response[&#39;error&#39;]+&quot;&lt;/p&gt;&quot;);<br>                        <br>if(response.hasOwnProperty(&#39;short_url&#39;)){<br>                            <br>// this error is that shortened url already exsist<br>                            <br>$(&quot;.error&quot;).append(&quot;&lt;p class=&#39;text-muted&#39; style=&#39;color:green !important;&#39;&gt;The shortened url is : &lt;a href=&#39;http://&quot;+response[&#39;short_url&#39;]+&quot;&#39;&gt;&quot;<br>+response[&#39;short_url&#39;]+&quot;&lt;/a&gt;&lt;/p&gt;&quot;);<br>                        <br>                                         }<br>                        <br>      }</pre><pre>});</pre><p>Let us understand this ajax in two parts. The first part is fairly simple in which we send <strong>POST</strong> data to <strong>urlshort.php, </strong>the data consists of the URL entered by the user and is processed by urlshort.php. How it is processed would be discussed in the next section. The second part is more about understanding the response<strong> string</strong> sent by the script. The following cases arise,</p><ol><li>The URL entered shortened successfully, the response would be, Let us call this <strong>Response type 1</strong>.</li></ol><pre>{</pre><pre>&quot;success&quot;:&quot;The URL was successfully shortened!&quot;,<br>&quot;short_url&quot;:&quot;smlr.ml/&lt;some-unique-identifier&gt;&quot;</pre><pre>}</pre><p>2. The URL entered is already shortened before, the response would be, Let us call this <strong>Response type 2</strong>.</p><pre>{</pre><pre>&quot;error&quot;:&quot;The URL is already shortened&quot;,<br>&quot;short_url&quot;:&quot;smlr.ml/&lt;some-unique-identifier&gt;&quot; /* short_url is the previously shortened url stored in database */</pre><pre>}</pre><p>3. Some Server Side Error, the URL is not shortened in this case. Let us call this <strong>Response type 3.</strong></p><pre>{</pre><pre>&quot;error&quot;:&quot;We are having trouble shortening your URL!&quot;</pre><pre>}</pre><p>These are the responses generated by <strong>urlshort.php</strong> and information from these responses are simply taken and printed in the frontend.</p><p><strong>Creating and understanding urlshort.php</strong></p><p>This file contains all the logic for how the entries are to be made into the database.</p><p>The Script functions in the following manner:</p><ol><li>First of all, it checks that there is some POST data sent to it.</li><li>If it is sent then it checks whether the URL sent already exists in the database? If it is already shortened then we give back <strong>Response type 2</strong>.</li></ol><pre>// URL to be shortened<br>$url = $_POST[&#39;url&#39;];</pre><pre>// check if url is already shortened</pre><pre>$res = $mysqli-&gt;query(&quot;SELECT * from urlshort WHERE url = &#39;$url&#39; LIMIT 1&quot;);</pre><pre>/* the following if statement checks wether URL already present in the database */</pre><pre>if($res-&gt;num_rows == 1){</pre><pre>    // the url is already shortened , generating Response type 2</pre><pre>    $response[&quot;error&quot;] = &quot;The URL is already shortened&quot;;<br>            <br>    // send the exsisting short url in response too.<br>            <br>    $row = $res-&gt;fetch_assoc();<br>            <br>    $short_url = &quot;smlr.ml/&quot;.$row[&#39;identifier&#39;];<br>            <br>    $response[&quot;short_url&quot;] = $short_url;</pre><pre>    echo json_encode($response);</pre><pre>}</pre><p>3. If URL is not shortened we generate a random 4 letter unique identification string. If this string is not already present in the database then <strong>we insert URL and unique identification in our table created earlier. </strong>If the string already exists we keep on generating the string until we get a unique string. After we get a new string we simply enter the database. In both of the given cases, we send a <strong>Response type 1. </strong>If somehow the entry to the database fails we send a <strong>Response type 3</strong>. The logic for same is given in the snippet:-</p><pre>// take a random aplha numeric string</pre><pre>$randomString = &quot;1092837465qazwsxedcrfvtgbyhnujmikolp4509876wsdfvhn&quot;;</pre><pre>/* shuffle the string randomly, use equivalent function for your backend */</pre><pre>$shuffle =  str_shuffle($randomString);</pre><pre>/* create a 4 letter identifier for your shortened URL using substring function */</pre><pre>$identifier = substr($shuffle,0,4);</pre><pre>// check if given identifier is already in use</pre><pre>$rows = $mysqli-&gt;query(&quot;SELECT identifier from urlshort WHERE identifier=&#39;$identifier&#39; LIMIT 1&quot;)-&gt;num_rows;</pre><pre>// if identifier is in use keep finding until we get a unique identifier</pre><pre>while($rows == 1){</pre><pre>$shuffle =  str_shuffle($randomString);</pre><pre>$identifier = substr($shuffle,0,4);</pre><pre>$rows = $mysqli-&gt;query(&quot;SELECT identifier from urlshort WHERE identifier=&#39;$identifier&#39; LIMIT 1&quot;)-&gt;num_rows;</pre><pre>}</pre><pre>// at this point we have found out a unique identifier</pre><pre>// make entry in the table</pre><pre>$insert = $mysqli-&gt;query(&quot;INSERT INTO urlshort(url,identifier) VALUES(&#39;$url&#39;,&#39;$identifier&#39;)&quot;);</pre><pre>if($insert){</pre><pre>/* if the entry in table was successful, return success message with shortened URL i.e. Response Type 1 */</pre><pre>$response[&quot;success&quot;] = &quot;The URL was successfully shortened!&quot;;</pre><pre>$response[&quot;short_url&quot;] = &quot;smlr.ml/&quot;.$identifier;</pre><pre>echo json_encode($response);</pre><pre>}else{</pre><pre>// for failing to make entry in table we send Response Type 3 </pre><pre>$response[&quot;error&quot;] = &quot;We are having some troubles shortening your URL. Please try again later!&quot;;</pre><pre>echo json_encode($response);</pre><pre>}</pre><p>After successful entry, our table would look like this,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gw-kdDhFGfjkwtoMDvxvsg.png" /><figcaption>Table after Entry</figcaption></figure><p>This was all to it for urlshort.php. Now we can proceed to the final part of this post to write the logic for redirection.</p><p><strong>Creating and understanding index.php</strong></p><p>Before creating index.php we need to understand what <strong>clean URLs</strong> are? If you already know what they are you might skip this part. Let us take an example to understand this.</p><p>A normal URL with a get request would look like this,</p><pre>smlr.ml/?r=9qpy</pre><p>A <strong>clean</strong> and equivalent URL for the above URL would look like this,</p><pre>smlr.ml/9qpy</pre><p>Essentially what we need to do for our <strong>index.php </strong>file is to do a get request to the page and pull out the original URL from the database so that we can redirect from the index page. Either we can use the original normal URL however we can do better using a clean URL by adding some code to our .htacess file.</p><p>If you already have a .htaccess file then add the following code or create a new file with the name <strong>.htaccess</strong> and add the code to it.</p><pre>RewriteEngine on</pre><pre>RewriteRule ^([a-zA-Z0-9]+)$ index.php?r=$1 [NC,L]</pre><p>The above is called a rewrite rule and is used to get clean URLs by telling the browser how to interpret URLs. We will not get into the details of Clean URLs today and keep the topic for some other day.</p><p>Now let us see what our <strong>index.php</strong> file looks like and understand what it does</p><pre>&lt;?php</pre><pre>    // include database connection file <br>    include(&quot;connection.php&quot;);</pre><pre>   // get the unique identifier from the Clean URL <br>   $identifier = preg_replace(&#39;#[^0-9a-z]#i&#39;,&#39;&#39;,$_GET[&#39;r&#39;]);</pre><pre>   // take out url from table corresponding to identifier<br>    $res = $mysqli-&gt;query(&quot;SELECT url from urlshort WHERE identifier = &#39;$identifier&#39; LIMIT 1&quot;);<br>    <br>    if($res-&gt;num_rows==1){<br>        // if given url is a valid shortened url <br>        // convert record to array<br>        $row = $res-&gt;fetch_assoc();</pre><pre>        // get url from array<br>        $url = $row[&#39;url&#39;];</pre><pre>        // Redirect to desired url using header function<br>        header(&quot;Location:&quot;.$url);<br>        <br>    }else{</pre><pre>        /* If request URL has invalid identifier then move it back   to url shortening page */<br>        <br>        header(&quot;Location:<a href="http://smlr.ml/service.php">http://smlr.ml/service.php</a>&quot;);<br>        <br>    }</pre><pre>?&gt;</pre><p>The working of the above file is quite simple. It takes out the unique identifier from the request URL and for this unique identifier finds from the table created earlier the corresponding URL it needs to redirect to. Yes! as simple as that. Congratulations! on creating your very own URL Shortening Service.</p><p><strong>Concluding Remarks</strong></p><p>As told initially this is a very basic URL shortener intended to give a basic understanding of how this system works and how to implement it. Better versions of URL Shortening Services for higher workloads can be made for higher workloads by using methodologies like hashing, Caching, Apache Zookeeper Service, and building a distributed system in general. Yes, this is not the best URL Shortener in the world but will definitely be helpful when you create the best one :)</p><p>As promised you can check all the files for the project here and also check out the working of my URL-Shortener live in the link given in ReadME.</p><p><a href="https://github.com/RajatSvN/URL-Shortener">https://github.com/RajatSvN/URL</a></p><p>If you enjoyed building the URL Shortening Service then, please support and share this post. It is my first post on Medium, Hoping to get a great response from you all and come up with more of these tutorials later.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f89817ec615" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>