{"id":75,"date":"2019-04-17T18:14:36","date_gmt":"2019-04-17T18:14:36","guid":{"rendered":"https:\/\/r0b3rt.com\/andr-web\/?p=75"},"modified":"2019-04-17T18:14:36","modified_gmt":"2019-04-17T18:14:36","slug":"url-short","status":"publish","type":"post","link":"http:\/\/r0b3rt.com\/andr-web\/url-short\/","title":{"rendered":"URL Short"},"content":{"rendered":"<p>In simple words, URL shortener maps an arbitrary long sequence of character ( original, long crappy url ) into a short and slick sequence of characters. This is nothing but Hashing, which is most commonly used to create lookup tables, HashMap, md5 Hash for cryptographic purposes etc.<\/p>\n<p>To understand the URL-Shortening process I have created a demo project on GitHub and also a blog post. Do refer to this and let me know if it was helpful.<\/p>\n<hr \/>\n<h2 id=\"url-shorteners-\">URL Shorteners :<\/h2>\n<p>Well, so you are tweeting about this amazing video which you think would be a big hit on the social media. You open your twitter account, copy the URL and paste it to tweet, but wait ! The URL itself is 140+ characters, let alone your quirky comments.<\/p>\n<p>And then you hear about these amazing tools called &#8211; URL Shorteners. They convert the dirty looking urls into short, sweet and slick urls, which can not only be easily shared on twitter and other media but they also provide you a hell lot of analytics and user information.<\/p>\n<p><strong>Here are some commonly used URL shorteners :<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/bitly.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">bit.ly<\/a><\/li>\n<li><a href=\"https:\/\/goo.gl\/\" target=\"_blank\" rel=\"noopener noreferrer\">goo.gl<\/a><\/li>\n<li><a href=\"http:\/\/ow.ly\/url\/shorten-url\" target=\"_blank\" rel=\"noopener noreferrer\">ow.ly<\/a><\/li>\n<\/ol>\n<p>Let us paraphrase what URL shortening tools do. They convert a long arbitrary length of string into a short and compact combination of characters, which has much smaller length than the original URL. So if we understand this, we also understand that essentially these tools are just mapping one set to another, but where one set is very large, probably infinite where as the other is a smaller and finite set. Does this sound a bit familiar to the computer science guys ? Yes this is <code class=\"highlighter-rouge\">Hashing<\/code> ! It has wide usage from designing a HashMap, Lookup tables to creating a md5 hash for cryptographic purpose.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/anandjoshi.me\/img\/hashing.PNG\" alt=\"hashing\" \/><\/p>\n<h2 id=\"but-why-hash-when-you-can-use-random-short-strings-\">But why hash when you can use random short strings ?<\/h2>\n<p>Yes. This is a valid approach. The original long url would be mapped to a short sequence of random strings. One reason where hashing would have advantage over random strings is, if for some reason my database crashes and I do not have a backup then I would not be able to recover the short url even if I managed to pull the old long url (say from some other user account data, app logs etc). Hashing will guarantee me that it will reproduce the same old short url for the original url. Just a design perspective we might consider while building this app.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In simple words, URL shortener maps an arbitrary long sequence of character ( original, long crappy url ) into a short and slick sequence of characters. This is nothing but Hashing, which is most commonly used to create lookup tables, HashMap, md5 Hash for cryptographic purposes etc. To understand the URL-Shortening process I have created &hellip; <a href=\"http:\/\/r0b3rt.com\/andr-web\/url-short\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;URL Short&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-computer-it"],"_links":{"self":[{"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":1,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":76,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/posts\/75\/revisions\/76"}],"wp:attachment":[{"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/r0b3rt.com\/andr-web\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}