TinyURL System Design | URL Shortner System Design Interview Question | Bitly System Design

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 มิ.ย. 2024
  • Solution for the most common System Design Interview Question - "Design a URL Shortener like TinyURL".
    This is probably the most common design interview question being asked in almost every other company.
    Prerequisites:
    How to select the right Database for a Large Scale System: • Database Design Tips |...
    Summary of the video: www.codekarle.com/system-desi...
    Architecture diagram: github.com/codekarle/system-d...
    Author: / sandeep1904
    If you like this video, please help us grow by sharing this video with your friends on Facebook, connections on LinkedIn and anyone who can benefit from this.
    PS: This is not the real architecture of any such platform. This is my take on how I would answer that problem.
    #codekarle #systemdesign #tinyurlsystemdesign #system #design #interview #amazon #faang #tinyURL

ความคิดเห็น • 231

  • @jivanmainali1742
    @jivanmainali1742 3 ปีที่แล้ว +59

    I feel enlightened watching your videos.

    • @codeKarle
      @codeKarle  3 ปีที่แล้ว +3

      Thanks!! Glad to hear that :)

    • @g_pazzini
      @g_pazzini 6 หลายเดือนก่อน

      true.. this channel is a treasure chest 👍👍

  • @mahorasanli
    @mahorasanli 2 ปีที่แล้ว +11

    I watched 4 different Tiny URL System Design Video. This one is by far the best

  • @alianwar2857
    @alianwar2857 2 ปีที่แล้ว +4

    Very informative and the way you show the simple way to design first and then discard it again telling the problems and how we could tackle that, is really great.

  • @annafalvello8138
    @annafalvello8138 2 ปีที่แล้ว +4

    "in technical terms it's called a collision, but for us it's a problem" made me laugh. thanks for the great content

  • @aakashgyl
    @aakashgyl 2 ปีที่แล้ว +16

    I read many different ways this can be designed. But this design looks the best of all as it is highly scalable, very efficient and something that can easily work on a global scale. Thanks Sandeep for so much of hard work at your end to come up with such wonderful designs. I am watching your entire playlist.

    • @aman1893_
      @aman1893_ ปีที่แล้ว

      Hey do you want to study system design together? I have a lot of exp but I feel most of the online resources are incorrect or incomplete. We can make a solid understanding of the common designs in next 10-15 days by brainstorming everything together.

    • @rahular4596
      @rahular4596 ปีที่แล้ว

      @@aman1893_ I would be happy to learn from you😀

  • @vozone10
    @vozone10 3 ปีที่แล้ว +13

    A diagram with Kafka for Analytics would be a cherry on the cake. Overall great job!

  • @dongiveajack
    @dongiveajack 3 ปีที่แล้ว +3

    One of the best video i found out on youtube for url shortening.

  • @bablushaw6856
    @bablushaw6856 ปีที่แล้ว

    I had this video in watch recommendation but always skipping it thinking shortening URL, how hard it could be. But going through this video I started realize nothing is easy at scale. Your way of explaining is so awesome that at the same time I understood depth of problem and its solutions. Please keep it up.

  • @Arjun-tg1go
    @Arjun-tg1go 2 ปีที่แล้ว +7

    Just a thought- instead of using the token service we can generate unique tokens per service within the service itself.
    Steps could be as follows
    1. When service node starts, it will registers itself with DB and gets itself an ID and it’s sequence will start with 1
    2. Now, a particular node can generate token based on its ID+Today’s date+sequence
    3.When a particular node goes down, new node will spin up and performs step 1
    4. This will avoid complexity of calling token service totally

    • @alpitanand20
      @alpitanand20 8 หลายเดือนก่อน

      You are talking about Zookeeper here.

    • @Arjun-tg1go
      @Arjun-tg1go 8 หลายเดือนก่อน

      @@alpitanand20 use anything (db/zk) that is a singleton service.

    • @KingKingSofa
      @KingKingSofa 8 หลายเดือนก่อน +1

      MD5 Hash of the user IP Address + Time Stamp encoded to base 62 would also be valid. Both these approaches save us from the complexity of managing another set of services and their connections to a DB. We can more easily scale horizontally.

  • @ersinerdem7285
    @ersinerdem7285 3 ปีที่แล้ว +11

    There is another approach which pre-calculates the short urls, and use when requested. This way, there will not be range loses when servers go down. Your way is also very good, thank you!

    • @anonymousgod2006
      @anonymousgod2006 ปีที่แล้ว

      Ya I think if Token Service layer is removed and Url shortener service simply do what Token service is doing, that will be your case, and it seems fine to me

  • @theSDE2
    @theSDE2 2 ปีที่แล้ว +44

    It would be great if you build up slowly for the tech/tool to pick up for the design rather than directly putting the cassandra or redis or kafka. There can be possibility that the Interviewer is highly good at those tools and will start digging deep into that as soon as we name a stack which can surely bring us in trouble sometimes.

    • @debasish2332
      @debasish2332 2 ปีที่แล้ว

      Which make sense

    • @AlbertoRodriguez-oe6jo
      @AlbertoRodriguez-oe6jo ปีที่แล้ว +4

      As an alternative, you can read about the tool being discussed in video after watching it. It will keep the videos shorter and packed with more relevant content.

    • @isachinq
      @isachinq ปีที่แล้ว

      Isn't a token service a single point of failure? Even if we use multiple token service, how will we synchronise all of them? Please answer 🙏

    • @ANILKHANDEI
      @ANILKHANDEI ปีที่แล้ว

      @@isachinq i think the token service is being load balanced to avoid a single point of failure. Having miltiple tokenservices will not impact the design as it is only used to get the next range from same mysql cluster.

    • @isachinq
      @isachinq ปีที่แล้ว +1

      @@ANILKHANDEI how will you synchronise all the MySQL in MySQL cluster? By definition, horizontal scaling will bring down the consistency

  • @VibeWithSingh
    @VibeWithSingh 2 ปีที่แล้ว +3

    Great video. Thanks for putting all the effort and explaining different choices and corresponding trade offs. 👍

  • @prashantsingh-yx4yh
    @prashantsingh-yx4yh 2 ปีที่แล้ว

    What a calm and composed thoughts/teaching for each and everything
    Hate off bhai...one of the best tech youTubers!!!

  • @AnshumanDwivedi5988
    @AnshumanDwivedi5988 2 ปีที่แล้ว

    One the best I have seen so far on this topic. Keep making videos on systems design. I just subscribed and tunned in for every upcoming video now. 👍🎉💐

  • @sharadkumar3823
    @sharadkumar3823 2 ปีที่แล้ว

    Even after 1 year this material is gold !

  • @gowsank
    @gowsank 2 ปีที่แล้ว

    Love it!! Thanks for sharing multiple options of implementing a solution. Keep posting more videos

  • @AlbertoRodriguez-oe6jo
    @AlbertoRodriguez-oe6jo ปีที่แล้ว

    You're highly articulate, I love that.

  • @duzgunkenan
    @duzgunkenan หลายเดือนก่อน

    great energy, honest intention, a beatiful human being. thank you

  • @manojkp80
    @manojkp80 2 ปีที่แล้ว +5

    Great video, as always very helpful. If you could 1) add custom key support - user can specify their own tiny url 2) talk more about what could be other ways like, md5(main url) -> base2_encode, and their drawbacks etc 3) add diagram on a analytics part, that would really be helpful. Do you also feel a cache can be added in front of Cassandra to serve hot urls?
    Thanks, keep helping.

  • @earthpligrim5757
    @earthpligrim5757 ปีที่แล้ว

    this is the first video im waching on your channel and i just loved the explanation. im sure its gonna help me with my interivew. the very first thing i did post watching the video is subscribing. thanks alot for the detailed information.

  • @g_pazzini
    @g_pazzini 6 หลายเดือนก่อน

    wow.. you are a world class system architect

  • @Legendary-Akshit
    @Legendary-Akshit 3 ปีที่แล้ว +4

    Amazing video with possibly the best explanation so far on this use case. I had watched several videos on TinyURL but none could explain in the first 5 mins so lucidly the need for 7 characters based shortened URL. Good job

    • @isachinq
      @isachinq ปีที่แล้ว

      Isn't a token service a single point of failure? Even if we use multiple token service, how will we synchronise all of them? Please answer 🙏

    • @mirrorps
      @mirrorps ปีที่แล้ว

      @@isachinq Sandeep already answered your question in the video and it's a common approach to scaling mysql - the token service (by default) will be not overloaded with massive amount of requests, but if somehow it is then the solution would be to utilise the MySql horizontal scaling / sharding between multiple servers / instances.

    • @isachinq
      @isachinq ปีที่แล้ว

      @@mirrorps but horizontal scaling won't ensure the consistency between different MySQL nodes. So it may assign the same range of values

    • @mirrorps
      @mirrorps ปีที่แล้ว

      @@isachinq there are some hashing algos to distribute the data between the nodes, so the ranges may be based on similar hashing algorithms

  • @sergiim5601
    @sergiim5601 ปีที่แล้ว

    Thanks, amazing explanation of TinyURL system design !

  • @chaitanyawaikar382
    @chaitanyawaikar382 3 ปีที่แล้ว +3

    Excellent explanation !!! Even though there are a bunch of system design videos out there, your videos stand apart from them by discussing various situations and pitfalls of using a certain tool/ database.
    Just one quick suggestion from my side regarding upcoming videos - can you please create any video that explains capacity estimation of a database. For example how much space will a users table with let's say 6 attributes having almost 100 million records take is postgres or mongodb or any other database. This is also commonly asked in interviews now a days and given your breadth of experience, I think you would be able to create awesome content in this space also.
    Once again Thanks for videos :)

    • @codeKarle
      @codeKarle  3 ปีที่แล้ว +1

      Thanks Chaitanya!
      We'll put this in some smaller video that comes out in the future.
      Just that it's a time taking thing to go over the calculations so we skipped it in all the videos till now :)

  • @darshanpandya8978
    @darshanpandya8978 2 ปีที่แล้ว

    all the video you have made are awesome and really easy to understand. If you can make more videos regarding technologies that being used in system design. Having more deeper dive and comparison of difference tech is helpful.

  • @ashokkumarmaniraj1250
    @ashokkumarmaniraj1250 3 ปีที่แล้ว

    Great Job Sandeep!!! I have seen all your system design videos. Waiting to see a video on cloud system design.

  • @andreadiotallevi5780
    @andreadiotallevi5780 ปีที่แล้ว

    Excellent presentation skills!! Thank you

  • @godolsss2139
    @godolsss2139 4 ปีที่แล้ว +1

    Keep posting..love your vids...very simple and understandable content...

    • @codeKarle
      @codeKarle  4 ปีที่แล้ว

      Glad you like them :)

  • @vidhanchandra3997
    @vidhanchandra3997 3 ปีที่แล้ว

    Crystal clear explanation.......

  • @rishikeshmpawar
    @rishikeshmpawar 2 ปีที่แล้ว

    Really cool content. Analytics/Observability is generally mised; thanks for taling about it. Provided html page link in description for the content would definitely help to revise.

  • @BestURLShortenerBioPageQRCode
    @BestURLShortenerBioPageQRCode 9 หลายเดือนก่อน +1

    Oh, it's very detailed and easy to understand. Thank you for video. It is very useful❤❤

  • @deepanshunagpal7587
    @deepanshunagpal7587 9 หลายเดือนก่อน +2

    One issue is that sequentially generating shortcode could be security threat as it would be predictable either we should append a random number at starting or end before converting base 62 conversion

  • @user-vq6yi7se2r
    @user-vq6yi7se2r ปีที่แล้ว

    Excellent. Thank you!

  • @midhunthomson4135
    @midhunthomson4135 3 หลายเดือนก่อน

    Very informative. Thankyou!

  • @PradeepSingh-vm1gl
    @PradeepSingh-vm1gl 3 ปีที่แล้ว

    Maza aa gya bhai. Thank You so much. ❤

  • @jasper5016
    @jasper5016 9 หลายเดือนก่อน

    Bhai thanks so much. I got your course on Udemy as well. There is not better channel than this on System Design.

  • @yogaranjansingh504
    @yogaranjansingh504 3 ปีที่แล้ว

    please create more system design videos, love your work

  • @nikitasinghchauhan6239
    @nikitasinghchauhan6239 4 ปีที่แล้ว +2

    You explained so well. nice video .

    • @codeKarle
      @codeKarle  4 ปีที่แล้ว

      Thanks a lot 😊

  • @ManojKumar-bk7bj
    @ManojKumar-bk7bj 2 ปีที่แล้ว

    Nice explanation!!

  • @Mohamed-uf5jh
    @Mohamed-uf5jh 3 ปีที่แล้ว

    excellent video , Thanks sir

  • @SantoshSunagar-iv8fb
    @SantoshSunagar-iv8fb 16 วันที่ผ่านมา

    Very informative videos

  • @akfsx
    @akfsx ปีที่แล้ว

    It's also possible to use distributed RNG (another topic for SD interview) or just hash long URLs with extra steps for hash collisions.

  • @l.oleksandr
    @l.oleksandr 2 ปีที่แล้ว

    Thank you for this information

  • @rakeshgupta8901
    @rakeshgupta8901 3 ปีที่แล้ว

    you are amazing !!.

  • @foodfan4512
    @foodfan4512 3 ปีที่แล้ว +6

    Amazing explanation! Can you please provide pdf or image format of the architecture like you provided for other videos? It really helps to see everything all together in 1 place to digest everything. Thank you.

    • @codeKarle
      @codeKarle  3 ปีที่แล้ว

      Sure, we'll get it done in a few days :)

    • @samirhere4341
      @samirhere4341 3 ปีที่แล้ว

      Was looking for the same. Thank you

    • @codeKarle
      @codeKarle  3 ปีที่แล้ว +10

      There you go: www.codekarle.com/system-design/TinyUrl-system-design.html
      You'll find the architecture & summary here :)

  • @chiragkothari278
    @chiragkothari278 2 ปีที่แล้ว

    Nice video. I think there can be another functional requirement of payment option for number of times a url gets used. Also we should have. a rate limiting also.

  • @ajaysaxena9697
    @ajaysaxena9697 2 ปีที่แล้ว

    hats off man.. awsm

  • @kasalaashraf6968
    @kasalaashraf6968 2 ปีที่แล้ว

    Really cool content

  • @riteshsrivastava7227
    @riteshsrivastava7227 2 ปีที่แล้ว

    I love your videos buddy...

  • @Zaika96
    @Zaika96 ปีที่แล้ว

    nicely expained

  • @p111calcutta1
    @p111calcutta1 7 หลายเดือนก่อน +1

    @codeKarle how do you handle the case when token service goes down and we wait for data to persist in sql db before token service return the ranges to short url service ? what if sql db goes down ? if we keep replica of db then do we want data to be synced before we return range to user ?

  • @domicio1577
    @domicio1577 ปีที่แล้ว

    Awesome video! Lots of insights. As a piece of feedback, I would change microphones. Thank you.

  • @PriyaSarkar-ly4nw
    @PriyaSarkar-ly4nw 10 หลายเดือนก่อน

    Nice video

  • @sankarsattari5921
    @sankarsattari5921 ปีที่แล้ว +4

    I think there is still a possibility of duplicates because we are using a substring of length 6 or 7 of the base62 encoding of the numbers, which can collide. for example base62(0000001) is 107Zzj5ex0 and base62(0000002) is 107Zzj5ex0 as you can see the prefixes are the same.

    • @sagardafle
      @sagardafle ปีที่แล้ว

      Hey, how is base62(0000001) = 107Zzj5ex0?

    • @MegaBelltone
      @MegaBelltone 11 หลายเดือนก่อน

      @@sagardafle Doesn't matter. The thing is that there is always possibility of collision if we do substring. I can't find any explanation of it anywhere, as how to resolve.

  • @SachinVerma-xo4fj
    @SachinVerma-xo4fj 2 ปีที่แล้ว

    Thanks!

  • @andreadiotallevi5780
    @andreadiotallevi5780 ปีที่แล้ว

    Great video! I have just one question. For the short url service to be able to keep track of the current range, does it need to be stateful? And how / where would you store that info?

  • @lalitagedam6399
    @lalitagedam6399 ปีที่แล้ว

    Nice 👍

  • @KumarRajLE
    @KumarRajLE ปีที่แล้ว

    Super

  • @foodfan4512
    @foodfan4512 3 ปีที่แล้ว

    Amazing clear content!! Can you please help me with the following questions:
    1. How are spam and malicious links handled?
    2. How might we be able to track and display traffic stats to users?

    • @codeKarle
      @codeKarle  3 ปีที่แล้ว

      Thanks!
      For Spam and Malicious content, I'll be doing another video. That's a fairly complex system in itself.
      Tracking I have covered as part of this video, and once it is tracked it can be shown in the same UI where we show all the Short URLs that the user has created.

  • @jdr3808
    @jdr3808 10 หลายเดือนก่อน

    Thanks, I have seen many solutions talking about Event based decoupled systems. However I never encountered a robust way of making sure there is no Consistency and Integrity being effected due to any failures during those Async processing of the Event. What are various techniques for ensure Decoupled systems ensures no loss

  • @hanspeterpfister2253
    @hanspeterpfister2253 4 ปีที่แล้ว +3

    Great work. Can you also upload a video for Dropbox/Google Drive like service? In case of Dropbox, most videos drop the ball at, there will be a Notification service and it will communicate with clients asynchronously using Queues and every client will have its own Queue. They don't talk about, if there are billions of clients, do we expect to have a billion queues? Is that scalable? Do focus on this as well if you make the video.

    • @codeKarle
      @codeKarle  4 ปีที่แล้ว +1

      Sure, we'll try to make that in a few weeks

  • @ujjwaldave8646
    @ujjwaldave8646 ปีที่แล้ว

    You could have given some more thought on the short url to long url flow. Fetching data from Cassandra for each and every request could be very time consuming an latency needs may not be met. May be we can use caching in that flow to reduce the fetch latency.

  • @seelamrameshreddy702
    @seelamrameshreddy702 ปีที่แล้ว

    It is really nice video. I have couple questions.
    1. Is duplicates URLs would be stored in DB every time when we hit a request ?
    2. Why would you consider caching during GET ?

  • @maheshnavani5294
    @maheshnavani5294 ปีที่แล้ว

    Great Video, would appreciate if you can do
    1. Elevator System
    2. Discount System at SuperMart

  • @user-kz7xj3it3w
    @user-kz7xj3it3w 3 หลายเดือนก่อน

    Are you going to maintain the mappings from counter range to its availability in an extra datastore, or a table so that your token service could handle them?

  • @rohitrangera8766
    @rohitrangera8766 ปีที่แล้ว

    Awesome video, can you share system design on Voting Machine (EVM)?

  • @edwardteach2
    @edwardteach2 2 ปีที่แล้ว

    U a System Design God

  • @bowang1825
    @bowang1825 3 ปีที่แล้ว

    Very good way to handle token service. Finished all your video, when do you plan to have new videos?

    • @codeKarle
      @codeKarle  3 ปีที่แล้ว

      Thanks!!
      A bit busy with work these days, soon there would be more videos coming.
      Do share these in your circle if you liked them :)

  • @sushmitagoswami7320
    @sushmitagoswami7320 2 ปีที่แล้ว

    THE BEST

  • @hemantagrawal25
    @hemantagrawal25 2 ปีที่แล้ว +1

    can we use instance id and utc time to generate token instead of taking separate token generation service and maintain token range as per different instance.

  • @gauravradioactive
    @gauravradioactive 10 วันที่ผ่านมา

    Thank you for the great content !
    It looks like the Token Service is a single point of failure as well. And if we create multiple instances of the Token Service, how do they ensure that each instance provides a unique URL range, and no 2 instances provide overlapping ranges? If the Token Services are supposed to communicate each other before deciding the range for an incoming request, this would again add to overhead and slow down the process. Can someone please share their thoughts on this ?

  • @hokayantra_
    @hokayantra_ 3 ปีที่แล้ว +2

    Custom shorlink support is also most of the user wants plus its not good to have incremental shorlink ... better to have something randomized nature of shortlink.. share your thoughts

    • @codeKarle
      @codeKarle  3 ปีที่แล้ว +1

      Custom Shortlink is a good feature, that can be implemented easily I believe.
      You are right about the incremental shortlinks, that's a trade-off you need to choose.
      Random is good, but you'll end up in high collisions and higher latencies. If the NFR's are okay with some high latency/less throughput, then a randomized solution would be a much better choice since it's hard to predict the next short URL.

    • @anandratn8339
      @anandratn8339 3 ปีที่แล้ว

      @@codeKarle another possibility is to add salt in the incremented number being used by shortener service that will maintain the uniqueness as well as hard to guess

  • @akagragupta9968
    @akagragupta9968 2 หลายเดือนก่อน

    If I generate multiple instances of token service it can also send same range to multiple services....?

  • @luqmansen
    @luqmansen 2 ปีที่แล้ว

    Very well explained, except you can get better microphone, that would be great, many thanks

  • @neerajramachandran4647
    @neerajramachandran4647 8 วันที่ผ่านมา

    Does this approach assume that we do not care about idempotency? In this model, if the long to short URL service receives multiple requests of the same long URL, the token service will assign that request to different short URLs.

  • @Bb-cz3fq
    @Bb-cz3fq ปีที่แล้ว

    HI
    I have a question regarding the Collision it this case is avoided if we have two same shortURL ,because it uses tokens right?

  • @kritikajain6677
    @kritikajain6677 18 วันที่ผ่านมา

    Let's say we have scenarios where one url U1, is called from two different users for the first time, and both the request R1 and R2 come at the same time, but being sent to different nodes, since all the server nodes have different range of tokens being given to them, same url will be using two tokens, it can also result in decreasing the amount of tokens we have?

  • @weightwatcher221
    @weightwatcher221 3 ปีที่แล้ว +1

    1 of the best system design video. Might not be reasonable question but possible. How do we scale it to some arbitrary large(billion) of txns per day?

    • @codeKarle
      @codeKarle  3 ปีที่แล้ว +2

      Thanks!!
      I believe that with this exact same architecture, you can scale it to not just billions, but potentially even trillions of transactions per day.
      All you need to change is - Modify the range of token service to now return a larger range thereby reducing the hits on token service, increase the length of the short URL, serve this service out of even more Data centers that are spread across the globe based on your traffic patterns, and throw in more hardware.

    • @weightwatcher221
      @weightwatcher221 3 ปีที่แล้ว

      @@codeKarle thank you for the quick response

  • @srinivasanvk57
    @srinivasanvk57 2 ปีที่แล้ว +1

    Great job on your side. A big thank you from my end. Can you please answer the query on handling duplicate requests? Same URL requested 3 times generates 3 tinyURL? How to handle it in this design?

    • @srinivasanvk57
      @srinivasanvk57 2 ปีที่แล้ว +1

      Ok I just verified in bitly and found that they generate different short URL everytime the same long URL is passed. So this is not a concern apparently. Thanks anyways

  • @antrapurohit8010
    @antrapurohit8010 ปีที่แล้ว

    for base62 hashing, is it ensured that for different hash key, we will get different value?

  • @LifeWithSeb99
    @LifeWithSeb99 หลายเดือนก่อน

    How can you request a number from Redis Cluster? Isn't that just a in-memory database? Would you need to program some kind of a logic into redis cluster?

  • @mehrdadshademan1873
    @mehrdadshademan1873 ปีที่แล้ว +1

    what are the tables rows contains information you keep in the cassandra?

  • @arghyasen9682
    @arghyasen9682 หลายเดือนก่อน

    One question - Whenever the user asks for a short URL do we check in the DB if there is an existing short url for the same? If so, will that not again slow down the application?

  • @yashendragoyal
    @yashendragoyal 3 ปีที่แล้ว +2

    A small doubt here, let's say we pick n as 6 for short URL chars and we use base 64 instead of 62. If you are starting the range from 1000 to 9999, then the base64 encoding will contain 6 chars, but as soon as you move to 10000 the chars will be 7. Doesn't it diverge from the initial design to keep the short URL chars as 6 only, also we are only using 9000 URLs in this range? If we follow this route, we might have to go to a very high range to convert to base64 and create a short URL (which will not be short anymore)

    • @santoshgupta1745
      @santoshgupta1745 2 ปีที่แล้ว

      6^64 can contains
      6.3340287e+49 unique numbers

  • @rajgupta3043
    @rajgupta3043 4 ปีที่แล้ว +1

    I am having trouble understanding, that let's say there are two datacenters. Each datacenter has its own token service and DB. How do you make sure that token service in two different data centers don't end up assinging same range to the SHORTTOLONGURL service? I am assuming DB contains the range and token service simply gets the range from DB, and it's an atomic transaction. But how do you manage ranges in DB across data centers? Would you have another service for doing so?

    • @codeKarle
      @codeKarle  4 ปีที่แล้ว +2

      The main idea of two DCs for token service is for redundancy. Let's say if you have Token Service in DC1 and DC2, the Master of DB can be in DC1 and it can have a Slave in DC2. if Master goes down, or DC1 is not available, then slave in DC2 can become the master, but for all other transactions it can make a cross DC call to the Database in DC1 thus making sure that the range is always unique. Latency is not a concern here because it's once in a few hours kind of an API call to assign tokens.

  • @andriylytvynskyy8359
    @andriylytvynskyy8359 ปีที่แล้ว

    How we can make sure that we don't "shorten" urls which have already been "shortened" - probably with some cache... otherwise we would need to query Cassandra and find out but is it not a cheap operation?

  • @devashish1026
    @devashish1026 4 ปีที่แล้ว

    If the token service is making a transaction everytime it assings a token, then horizontally scaling it wouldnt help as your database is the choke point in this case. Having said that, I guess it's okay to breach the SLA at the time of token assignment which can be made infrequent based on token range .

    • @codeKarle
      @codeKarle  4 ปีที่แล้ว +1

      true, but it's a very low throughput service so wouldn't be too much of an issue

  • @ShubhamAgarwaliiitm
    @ShubhamAgarwaliiitm 3 ปีที่แล้ว

    Since GUIDa are statistically unique globally as they are based on both hardware and time, plus a few extra bits to make sure it's unique. We can just convert these hexadecimal GUIDs to base64 to generate our short URLs. It will make system less complex.

    • @aman1893_
      @aman1893_ ปีที่แล้ว

      Guid is 128bit but we need around 7 chars strings. If you hash it, it’ll result in collisions. Tackling collisions is hard in distributed system. I liked the approach of using MySQL db to generate unused ranges. It makes everything so easy.

  • @navdeep3469
    @navdeep3469 12 วันที่ผ่านมา

    how will you build optimized short->long url search for such scale ?

  • @amitagrawal4660
    @amitagrawal4660 ปีที่แล้ว

    Why two different cassandra DB is used.. one for Long to short url request and other short to long url ? How will the second DB get those information via replication?

  • @shubhampandey668
    @shubhampandey668 2 ปีที่แล้ว

    Should not we be using a cache for doing the redirects since it is pretty static data?

  • @abhinee
    @abhinee 2 ปีที่แล้ว +1

    how is redis is single point of failure, most cloud providers support HA for redis clusters?

  • @navyathamarreddy2807
    @navyathamarreddy2807 ปีที่แล้ว

    Can someone please explain how collisions are handled? I did not understand the counter approach. The tiny URLs are generated using hash on Long URL and a Base62 as per the initial discussion

  • @user-fw1hj3vv2k
    @user-fw1hj3vv2k ปีที่แล้ว

    I am thinking what's the maximum of base10 unique number that could be generated and could be hold by variable in languague like java. Though we have capacity to hold 62^^7 unique URL , it could be limited by the maximum base10 unique number that could be stored in the applicaiton.

  • @ajaytiwary5798
    @ajaytiwary5798 ปีที่แล้ว

    Token service can also be single point of failure.If we will use multiple instances then again will same issue of duplication.

  • @Uppathebest
    @Uppathebest 2 หลายเดือนก่อน

    great explanation Karle. Pity you stopped making videos! If you resume, you may want to invest in a better microphone for the benefit of your viewers :)

  • @sameerforyou01
    @sameerforyou01 2 ปีที่แล้ว

    Please make some video on real life multithreading application architecture

  • @pawansaggu5787
    @pawansaggu5787 3 วันที่ผ่านมา

    Can anyone how will the Shortner Service or the Token service handle ranges that cannot be represented by any integer types in a language?
    Do we need to represent numbers in strings here?

  • @integralCalculus
    @integralCalculus 2 ปีที่แล้ว +3

    Great video! Regarding scaling the token service, how are we going to keep the state information regarding the next available range of IDs consistent across multiple data centres? I assume the next available range info is going to be maintained in a single record (sort of a sequence number) which now needs to be globally replicated across data centers. At the cost of significant latency, this could be addressed by having the URL service request the range from the token service in a background thread (as the current range on the URL server approaches depletion), so that the token service can then return the next available range ONLY after synchronously replicating the updated record across data centers. Basically we are trying to handle the problem of a globally consistent sequence number. Let me know your thoughts.

    • @smalldog3001
      @smalldog3001 ปีที่แล้ว +1

      excellent question.. was about to post it but read this. I also like your proposed solution!

    • @anonymousgod2006
      @anonymousgod2006 ปีที่แล้ว

      Doesnt the token service simply get an entry with F or T flag corresponding to a range. If there are multiple token service, it will be fine right as its single DB or are you suggesting if we want multiple DBs as well to avoid SPOF and geography based quick responses

    • @integralCalculus
      @integralCalculus 2 หลายเดือนก่อน

      @@anonymousgod2006we could take a hybrid approach. We can have the tokens DB geographically distributed across data centers while the service in a given DC backed by a single DB.We can assign large non overlapping ranges to each data center. So may be 0-1Billion can be assigned to DC1, 1B+1 - 2B to DC2 and so on. And within a DC, we just have multiple nodes in the token service backed by a single DB.

  • @harinimurali8724
    @harinimurali8724 ปีที่แล้ว

    What if the token service is down due to some reason? Is that not a single point of failure? When it comes up, it would again send indexes from beginning