![]() Like most URL shorteners, our application is expected to encounter high reads but relatively low writes. As a result, our constraints depend largely on Cloudflare Worker’s pricing and platform limits.Īt the time of writing this, the constraints per account to host our service for free are: The aim is simple - I want to be able to host this service for free. The short URL generated should never expire.The length of our UUID should be ≤ 8 characters as 62⁸ would give us about ~218 trillion possibilities.In this POC, we will not be supporting custom short links A digit '0' to '9', a total of 10 charactersĤ. An upper case alphabet 'A' to 'Z', a total of 26 charactersģ. A lower case alphabet 'a' to 'z', a total of 26 charactersĢ. The UUID (I sometimes call it URL key because it is the key of our storage object) should adhere to the Base62 encoding scheme (26 + 26 + 10):ġ.Whenever a user tries to access s./UcFDnviQ, the user would be directed back to the original URL.Given a URL, our service should return a unique and short URL of it.Like any system design interview, let’s start by defining some functional and non-functional requirements. I hope you will find this post insightful and entertaining to read! So, throw “scalability”, “partitioning”, “replicas”, etc. Building a commercial-grade URL shortener like TinyURL or Bitlyīut, rather a proof of concept (POC) of how one builds an actual URL shortener service using serverless computing.How to tackle an actual system design interview.Project requirements and limitations planningīefore we begin, do not get your hopes up too high.Building a URL shortener for free with Cloudflare Worker and KV. ![]() If you would like to follow through, you would need a Cloudflare account and use the Wrangler CLI. What follows is my thought process with code examples on how we can create a URL shortener using Cloudflare Worker. While meddling around with Cloudflare Worker to sync the Daily LeetCode Challenge to my Todoist, it gave me an idea to build an actual URL shortener that can be used by anyone. We can ignore these keys given that we have a huge number of them.Designing a URL shortener such as TinyURL and Bitly is one of the most common system design interview questions in software engineering. If KGS dies before using all the keys loaded in memory, we will be wasting those keys. As soon as KGS loads some keys in memory, it can move them to the used keys table, this way we can make sure each server gets unique keys. KGS can always keep some keys in memory so that whenever a server needs them, it can quickly provide them. As soon as KGS give some keys to an application server, it can move these to the used keys table. KGS can use two tables to store keys, one for keys that are not used yet and one for all the used keys. KGS will make sure all the keys inserted in key-DB are unique. This approach will make things quite simple and fast since we will not be worrying about duplications or collisions. Whenever we want to store a new paste, we will just take one of the already generated keys and use it. Another solution of the above problem could be to run a standalone Key Generation Service (KGS) that generates random six letters strings beforehand and stores them in a database (let’s call it key-DB).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |