System Design Mock Interview: Design a Rate Limiter (with Meta Engineering Manager)

Поделиться
HTML-код
  • Опубликовано: 11 янв 2025

Комментарии •

  • @tryexponent
    @tryexponent  2 года назад +1

    Don't leave your engineering management career to chance. Sign up for Exponent's EM interview course today: bit.ly/3wQmHQu

  • @mahesh23343
    @mahesh23343 Год назад +54

    I have given HLD interviews and they are not just about making high-level boxes. What kind of boxes (type of cache, type of DB) and how will they solve the problem (how will cache and rate limiter interact to decide how many requests have come for a user in a window). This definitely needed a more elaborate discussion. Informative otherwise, thanks!

  • @mayursonowal
    @mayursonowal 2 года назад +37

    straight outta the alex xu book. Is this scripted? Doesn't feel like a conversation at all. All rote learning. Just my two cents here, still a good video.

    • @francisngo
      @francisngo 2 года назад +8

      almost word for word...especially when it mentions the pros and cons of each rate limiter algorithm and why one would chose to implement rate limiter on server side versus client side. Regardless, its helpful to see how someone would communicate these concepts in an interview scenario :D

    • @bigk9000
      @bigk9000 2 месяца назад

      I was actually reading along with the video, more or less. XD

  • @siddhantsingh3411
    @siddhantsingh3411 Год назад +58

    This feels very scripted. It's almost like he is reading out of a reference book.

    • @raghavpatidar1070
      @raghavpatidar1070 Год назад +18

      and reference book is alex xu book chapter 6 word to everything from that book
      and it's complete one sided

    • @ashwin81088
      @ashwin81088 7 месяцев назад

      He’s probably built rate limiters before !

  • @UpBanarasWala
    @UpBanarasWala Год назад +4

    The sliding window approach explained seems the same as token bucket. I think in time sliding window, each request will have timestamp and whatever requests are within the window will be eligible to process unless if there is new request and the time window slide towards the new request timestamp removing any older requests (if) out of the window and for those removed requests 423 will be sent. Or else, the window won't be sliding at all unless it can to accommodate the new request other wise it will send 423 for new requests. Either approach is fine depending on requirements.

    • @oakvillian5
      @oakvillian5 9 месяцев назад

      It's not quite the same. Particularly in accuracy, how much memory they use (Token Bucket uses more than windows) and how well they deal with bursty traffic. Token bucket handles bursts implicitly, but bursts cause overthrottling when using a fixed window. Sliding window or improvements of it like sliding window log (very accurate due to timestamp alignment, uses tons of memory) or sliding window counter (technically an approximation, saves on memory and smoothes request rate). So depending on the problem statement one may very well be a better choice than the other. These tradeoffs are discussed in chapter 4 of Alex Xu's System Design book vol. 1

    • @Damian-cd2tj
      @Damian-cd2tj 8 месяцев назад

      ⁠@@oakvillian5what do you even mean? If your bucket has 100 tokens and it gets replenished every minute and you get 100 requests when it gets replenished, then you’ll be an entire minute dropping requests. Fixed window and simple bucket are exactly the same, the difference is that one counts from 0 to quota and the other from quota to 0 haha

    • @oakvillian5
      @oakvillian5 8 месяцев назад

      @@Damian-cd2tjbuckets are refilling continuously there’s more overhead. They are also more accurate when you want to throttle based on consistent usage like X MB / s. If requests don’t line up with your window you could throttle customers unnecessary and increase load on the system due to retries so it does matter

  • @mutlucansever4367
    @mutlucansever4367 Год назад +9

    I would wanna hear the discussion of locking or not locking the high throughput cache while writing. Great video overall!

  • @linc008
    @linc008 2 года назад +11

    I think the part of making the rate limiter distributed could be explained better. What does "one common cache" mean? Also the "read cache" and "write cache" were quite confusing, but the interviewer didn't do her job to dig through.

    • @tryexponent
      @tryexponent  2 года назад

      Hey Linchuan! Thanks for the valuable feedback!

    • @avindersingh3390
      @avindersingh3390 Год назад +2

      Yes. I was thinking if we can have multiple cache servers and use hashing on IP address to select the right cache for data related to this user.

  • @jackkohnjj
    @jackkohnjj Год назад +3

    Did the candidate even design the rate limiter? The most important part of the design is the actual rate limiter component and they just put two boxes called "API Rate Limiter". Maybe interviewer would get enough signal on this, maybe not. Definitely could have been better.

  • @Shibumi1979
    @Shibumi1979 2 года назад +8

    How does it come that this vid has only 2k views? Awesome content!!

    • @suryapTalks
      @suryapTalks 2 года назад

      Felt same.

    • @scuderia6272
      @scuderia6272 6 месяцев назад +1

      It doesn't feel like a real interview

  • @yzhan004
    @yzhan004 Год назад +5

    Rate limiter sits in between load balancer and web servers doesn't seem to a neat design at all, because it creates endless of trouble. How do you decide which web server to send a request to when it succeeds rate limit? Does the rate limiter service maintains Web Server auto scale group information?
    It should be a sit-aside service where LB (or web servers) does a check by calling it. Or it could even be a library in Web Server, but definitely not a pass through component.

    • @tryexponent
      @tryexponent  Год назад +4

      Hi yzhan004, thank you for your comment! It is a common approach to place the load balancer before the rate limiter. This configuration allows for an even distribution of traffic to the web servers, followed by the application of rate limiting measures.
      However, in the specific case of restricting users based on IP addresses, it is advisable to place the rate limiter before the load balancer. This placement enables early evaluation and enforcement of IP-based restrictions, enhancing system efficiency and security.
      Your observation is accurate, and it is indeed a smart move to put the rate limiter before the load balancer when implementing IP-based restrictions.
      Thank you for pointing that out! 💪

  • @mrcrazyenough007
    @mrcrazyenough007 Год назад +1

    I liked how Huzaifa tried to act dumb the whole time, while being an EM.

  • @OrbitZyro
    @OrbitZyro 2 года назад +2

    In a distributed env, I was thinking if the load balancer did geolocation based routing and have each rate limiter in each region , with its own isolated region specific cache ? No?

    • @viraj_singh
      @viraj_singh 2 года назад

      What if the client changes their ip to another country by using VPN and then it defats the purpose of rate limiter

    • @harishdalal136
      @harishdalal136 7 месяцев назад

      @@viraj_singh even before the idea here is we are rate_limiting on the basis of IP, if anyhow the client changes the country by using VPN the IP changes and it's treated as new user by the rate_limiter. The point here by redirecting based on geolocation seems good enough to me (I also had that in mind).

  • @pammybcc
    @pammybcc Год назад +2

    feedback : there was no discussion between these 2 guys.. they were just running at their own speed...

  • @mr_possible6197
    @mr_possible6197 Год назад

    This was wonderful!

  • @beltek01
    @beltek01 24 дня назад

    Wont the cache here for checking IP being blocked or not for each request be detrimental for the system and on a peak load scenario the window will slide in sub milliseconds...so the request which is in cache may be invalid for the new window duration

  • @patriklilja3673
    @patriklilja3673 2 года назад +5

    Thanks for the video!
    Could it not cause problems to rate limit on IP if multiple users are behind the same IP? Like in the case of CGNAT or VPN or similar?

    • @kolya6955
      @kolya6955 2 года назад

      device also has unique address

    • @ValeriCFBG
      @ValeriCFBG 2 года назад +9

      @@kolya6955 You can't get the Mac address from an HTTP call.

    • @jh0720
      @jh0720 2 года назад

      I was thinking the same thing. Bro a leetcode monkey 🤦🤦

    • @groovymidnight
      @groovymidnight 8 месяцев назад

      You're correct - and this is also a common implementation you see in the real world. I often see throttling errors since I'm behind the firewall in a big company. Design like this is often about tradeoffs and I think a great candidate can explain that and make an informed choice.

  • @saurabhsarkar1731
    @saurabhsarkar1731 9 дней назад

    can you also do mock interviews in fintech and banking space use cases?

  • @viraj_singh
    @viraj_singh 2 года назад

    Thanks. I’ve learned something new

  • @Nnngao4231
    @Nnngao4231 3 месяца назад

    It would be better to dig into the consistency and latency issue when using a centralized cache, discuss the solutions like pessimistic and optimistic locks and sharding.

  • @doddikarthik
    @doddikarthik 2 года назад +1

    Awesome content!!

  • @T-Radi
    @T-Radi 5 месяцев назад

    429 implies the client needs to adjust its behavior.
    529 suggests the server is experiencing temporary difficulties.
    So i would recommend your rate limiter responds with 429, not 529. You mentioned both, but you drew 529

    • @akshayparakh28
      @akshayparakh28 2 месяца назад

      The interviewee and your comment are both wrong here... you can only respond with a 429 if there's too many requests from the same clientID which rarely happens so instead of that I'd design the system to respond with a 503 error (The server is not ready to handle the request - as its busy processing others currently so slow down.) Please check out the official documentation of AWS S3 - Server timeouts 503 for reference.

  • @darshitgajjar5199
    @darshitgajjar5199 Месяц назад

    waiting for interesting and deep video rather than only discuss on cache, load balancer,....

  • @manojkumar.v.s9252
    @manojkumar.v.s9252 5 месяцев назад

    Hitting the cache for every request by every customer to check rate limit. This will being down the cache service/server immediately on even slightly higher load right?
    Any better approach to avoid cache service coming down?

  • @T-Radi
    @T-Radi 5 месяцев назад

    YES, you can have different rate limiters per geography !!! of course!! Not "i don't think so, it will put you in a vulnerable position". Imagine a situation where your backend Servers that you are connecting to from the rate limiters are setup differently in different geographies then each geography has different capabilities and hence can handle incoming requests at different rates!! And if you are rate limiting based on ip, then why do you want to have a joint cache between geographies? The requests from 1 IP always goes to the nearest geography based on the DNS. DUDE!!

  • @pravgcet
    @pravgcet 2 года назад +2

    If we use IP address, wouldn't it block all the users in a network because they all would have same public IP?

    • @tryexponent
      @tryexponent  2 года назад +9

      Hi Praveen! This won’t be an issue as the NAT router will do the translation such that the port numbers are not identical before sending it to the external server. So although the users in the same network will have the same public IP, they will have different port addresses which the server can use to identify the users.
      More info here: stackoverflow.com/questions/1982222/how-do-two-computers-connect-to-same-external-address-through-nat
      Hope this helps! Thanks for watching!

    • @pravgcet
      @pravgcet 2 года назад +3

      @@tryexponent Thanks , In that case the user identifier would be ip:port

  • @darshitgajjar5199
    @darshitgajjar5199 Месяц назад

    pls make more videos❤

    • @tryexponent
      @tryexponent  27 дней назад

      Hey darshitgajjar5199, glad you are enjoying our content!
      Let us know what types of videos you are looking for! More system design mocks?

  • @shurui91
    @shurui91 Год назад +2

    Will he get a hire/strong hire if this answer is given in a real interview?

    • @groovymidnight
      @groovymidnight 8 месяцев назад +1

      I would probably have given a weak hire rating for an L6 position. Context: I work at Google and regularly conduct these kinds of interviews.

    • @abhisheksingh-np8yi
      @abhisheksingh-np8yi 4 месяца назад

      ​​​@@groovymidnight how would you suggest I study hld, as with 2 yrs of exp I was caught off guard with "Impl idempotency at framework level"

  • @IlyaGazman
    @IlyaGazman 7 месяцев назад +1

    There is another prety powerful technic not mentioned in this video. You can cache on the token level, the backend can encript basic data in the token and look it up when the client is calling. It could eliminate the need of some other cach used in this video

    • @subhashdiwakar2888
      @subhashdiwakar2888 6 месяцев назад

      Can you please elaborate on this. Didn't clearly understood this solution

  • @birajendusahu3198
    @birajendusahu3198 6 месяцев назад

    What drawing tool you are using in the mock interview session.

    • @tryexponent
      @tryexponent  6 месяцев назад +1

      Hey birajendusahu3198, it's "Whimsical"!

  • @ahmadafghan6767
    @ahmadafghan6767 10 месяцев назад +6

    The lady has no idea what’s going on she just says yes to everything

  • @prashantsalgaocar
    @prashantsalgaocar 8 месяцев назад

    IP blocking might not be the best way to go as with DHCP, proxy the IP's can be different.. IP block can be done with WAF and we might not need a rate limiter..my view point..

  • @ThelmaPriscila
    @ThelmaPriscila Год назад

    What application is used by the Hozefa? thanks in advance

  • @metarus208
    @metarus208 Год назад

    thanks for this

  • @sur83848
    @sur83848 Год назад +4

    How did this guy get into Meta?

  • @groovymidnight
    @groovymidnight 8 месяцев назад

    I think the rules cache is pointless - just push rules to all rate limiter replicas whenever rules chance - which should be very rarely. One could also use a CDN for that (say, a json file with the rules) and have the API rate limiter servers read it now and then.

  • @manjy5927
    @manjy5927 11 дней назад

    isnt cache single point of failure

  • @fevicoI
    @fevicoI Месяц назад

    Is this an engineering manager? He appears more nervous than me lol.

  • @vippan
    @vippan Год назад +1

    It should be 429

  • @prashantsalgaocar
    @prashantsalgaocar 8 месяцев назад

    Another Q I had was at the end.. I am a customer like Stripe who is being rate limited by a fixed set of rules in the rules engine, I have no malicious intent. I am getting a 429, who needs to make the change? There could be a possibility that the API contract has changed or rules have become obsolete.. will this cause a maintenance headache? @hozefa

  • @anandkadu8875
    @anandkadu8875 Год назад

    interviewer didn't cross question too much almost agreed to whatever interviewee was saying, so this doesn't give idea on what could be cross questions on every decision taken while designing.

  • @rohit-ld6fc
    @rohit-ld6fc Год назад +1

    rate limiting on IP ? what if there is a whole family on facebook..they will have the same IP..it should be on userId!

    • @ancapist9698
      @ancapist9698 Год назад

      It shouldn't - you could make like 1k fake accounts and then if you had a rule per userId, you could still make 1000x calls from one IP using every account at the same time, without even changing the IP address. I doubt facebook would block a family - we are talking about hundreds/thousands of requests per minute/second, not 20 requests per second :D

  • @kbipalav
    @kbipalav 9 месяцев назад

    A computer science graduate can do this much of design. Should have talked specifically more on rule engine.

  • @deville295
    @deville295 8 месяцев назад

    My SDE friend at Amazon recruits for L4 and L5 positions. His tips for me would suggest that this kind of answers in the video would not pass at all.
    the interviewee starts spewing and regurgitating knowledge without caring about what the customers want .there were no questions regarding what this rake limit would be for. It just tells the interviewer that you only know one way to implement, and cannot handle the pros and cons of different approaches and why you need a certain type of limiter design

  • @Drraghavsethi
    @Drraghavsethi 6 месяцев назад

    System design should never be just talking without drawing anything and showing. SHOW YOUR THOUGHTS!!!!

  • @thecodepathshala
    @thecodepathshala 4 месяца назад

    Rate limiter system design in Hindi : ruclips.net/video/khhe7avsw1g/видео.html
    Easy to understand...

  • @Axadn
    @Axadn 9 месяцев назад +1

    This is so bad. You argued that you're going to globally rate limit users based on IP. But when questioned if you could route users to a different rate limiter based on geographic location you said no. Your justification was that IP address could be "easily faked" with a VPN. Hahahah . Make it make sense. His design is poor and she just nods her head and agrees to everything.

  • @ishantbhatia3194
    @ishantbhatia3194 9 месяцев назад

    Wrong answers

  • @ytPiglet
    @ytPiglet 9 месяцев назад

    Shouldn't he be conversing instead of mansplaining?

  • @King-rn7qm
    @King-rn7qm 6 месяцев назад

    For every word dont use ah ah ah ah🤦‍♂️ its irritating

  • @szyulian
    @szyulian 7 месяцев назад

    watched. -

  • @eternalsunshine313
    @eternalsunshine313 Год назад +1

    feels unnatural and scripted

  • @HR-ee6zm
    @HR-ee6zm Год назад

    Knowledge wasted, this video could have been more of format. You are not discussing in some structure.

  • @ishantbhatia3194
    @ishantbhatia3194 9 месяцев назад

    Bushit

  • @Polly10189
    @Polly10189 3 месяца назад

    What a pure waste of time... Even LKG kids can do better than meta EMs, I guess.

  • @mnasehzade
    @mnasehzade 3 месяца назад

    How annoying is his communication skill.

  • @hdrkn5247
    @hdrkn5247 6 месяцев назад

    seems like this guy doesn't know his stuff