Optimizing Concurrency in Go with Single Flight | Preventing Duplicate Work

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ม.ค. 2025

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

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

    your content is good and every thing you told is very clear thanks for making this video series I have searched go lang series but every single video is for only views but I find this series ......thnkyou bro...keep going dont stop

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

      I appreciate the kind words. I'm glad you're finding the videos helpful!

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

      @@codeandlearnwithlove just a suggestion use # for more reach. I have one more question are you indian.

    • @codeandlearnwithlove
      @codeandlearnwithlove  2 หลายเดือนก่อน +1

      @@prashlovessamosa Yes, bro, I am Indian. I believe if my work is good, it will reach people through word of mouth. My only aim is to spread knowledge and help young software developers through their journey.

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

      @codeandlearnwithlove I knew it you live here or abroad btw which state?

    • @codeandlearnwithlove
      @codeandlearnwithlove  2 หลายเดือนก่อน +1

      @@prashlovessamosa I am from Punjab and I live outside India. Somewhere in North America ;)

  • @unisol111
    @unisol111 2 หลายเดือนก่อน +1

    thanks for this video. Does it will work with web socket data like fetching prices from multiple exchanges(Binance, Bybit, etc.) Lets say multiple strategies or users wait for same price data?

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

      Yes, for sure. The Do method accepts a closure, that gives you the flexibility to have your own implementation. What you consider a duplicate request is up to you. The Singleflight package uses the key to see if a request is a duplicate or not. You can use the same key for your calls to mark them as duplicate. Example: use the outgoing requests that wait for the same price data with the same key and they will considered duplicates.

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

    When would you use this over a cache like redis?

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

      One example is cache stampede, when you service just starts and there are multiple duplicate incoming requests. This would cause your service to forward all those requests to your cache. Other example is when you data changes very frequently and you may not be able to decide a optimal cache TTL. Example stock market prices, in this case you still want to fetch data from a resource server but also don't want to make multiple duplicate requests. Cache may also add latency if your cache is in some other geographical area.

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

    🙏