# Limit Http Client throughput

**URL:** <https://discuss.akka.io/t/limit-http-client-throughput/5370>\
**Category:** Akka Libraries\
**Tags:** akka-http\
**Created:** [November 7, 2019, 3:45pm UTC](https://discuss.akka.io/t/limit-http-client-throughput/5370 "2019-11-07T15:45:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![twKrash](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/twkrash/32/1658_2.png) [@twKrash](https://discuss.akka.io/u/twKrash)\
**Post date:** [November 7, 2019, 3:45pm UTC](https://discuss.akka.io/t/limit-http-client-throughput/5370/1 "2019-11-07T15:45:13Z")

</div>

Hi! I want to ask if it possible to limit by, say, 50 concurrent outbound requests using Akka Http Client API?  
I tried with Source.queue[(HttpRequest, Promise[HttpResponse])] and Http().cachedHostConnectionPool but external API which I’m calling return 429 error with retry-after and I don’t want to hit that.  
My code

```auto
val poolClientFlow
    : Flow[(HttpRequest, Promise[HttpResponse]), (Try[HttpResponse], Promise[HttpResponse]), Http.HostConnectionPool] =
    Http().cachedHostConnectionPoolHttps[Promise[HttpResponse]](host = host)

val queue: SourceQueueWithComplete[(HttpRequest, Promise[HttpResponse])] =
    Source
      .queue[(HttpRequest, Promise[HttpResponse])](bufferSize, OverflowStrategy.backpressure)
      .throttle(elements = maxNumberOfRequests, per = 1 minute)
      .groupedWithin(50,1 second)
      .mapConcat(identity)
      .via(poolClientFlow)
      .to(Sink.foreach({
        case ((Success(resp), p)) =>
          p.success(resp)
        case ((Failure(e), p)) =>
          p.failure(e)
      }))

def send(request:HttpRequest) = {
    val responsePromise = Promise[HttpResponse]()
    queue.offer(request -> responsePromise).flatMap{...}
}

```

I also tried using global limit Actor described here : [https://doc.akka.io/docs/akka/current/stream/stream-cookbook.html#globally-limiting-the-rate-of-a-set-of-streams](https://doc.akka.io/docs/akka/current/stream/stream-cookbook.html#globally-limiting-the-rate-of-a-set-of-streams) but no success. My idea here was to release token after Future completes.

`.throttle()` is not helping too (

Unfortunately I cannot rely on max-open-connections because my server can has multiple clients. And each client should be able to do 50 concurrent requests with Akka Http Client API  
Thanks
