Rate Limiting in NextJs with Middleware, Vercel KV Storage & Upstash

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ย. 2024

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

  • @dirtbagmoto
    @dirtbagmoto 23 วันที่ผ่านมา +1

    Great video, thank you. This is much simpler than I expected, nice!

    • @hamedbahram
      @hamedbahram  23 วันที่ผ่านมา

      Glad it was helpful!

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd 3 หลายเดือนก่อน +1

    THank you so much hamed

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

      You are welcome!

  • @farzadmf
    @farzadmf 4 หลายเดือนก่อน +2

    I'm confused; does this really help? If we're doing rate limiting at our own application level, the requests will be considered traffic to our application, and we WILL be charged for those.
    Also, we're redirecting again at our own app level, so technically they could [D]DOS us by sending millions of requests.
    In my mind, the rate limiting part should be done BEFORE traffic reaches our app to avoid charges and our sever going down
    Am I missing something?

    • @hamedbahram
      @hamedbahram  4 หลายเดือนก่อน +1

      That's a good question, you can apply rate limiting at different layers such as a proxy server before you reach your application server, here we're using the edge middleware which runs before and separate from the application (nextjs) server. As far as the response, it's up to you how to handle; you can block with a 429 response instead of redirecting, this was just an example.

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

      Thanks, that's true. My main concern is that it is OUR part of the infra that's handling things
      The middleware is still running as part of our application, so if someone starts constantly sending requests, and say we're charged based on RPS, they can easily bankrupt us!

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

    Hey great video , how can i rate limit a server action?

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

      That's a good question! you can implement the same logic inside the server action and limit the response based on the user specific ID or the request.

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

    Hey Hamed my kv daily request keep getting exceeded. Just 3 users and its exceeding 3000 limit

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

      Look at your implementation. You can clone my code and compare.

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

      @@hamedbahram Thanks for your reply hamed.......Luv your content and that problem I changed kv to redis, Now its give me 10k dailylimit

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

    Is it work without vercel? It's paid

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

      You can use it on the free hobby plan as well.

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

    and how can i rate limit all my application routes?

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

      Without the config matcher, the middleware function runs for every request. Read more here to exclude static paths from the running the middleware → nextjs.org/docs/app/building-your-application/routing/middleware#matcher