# Leaky bucket method with Haproxy - Rate limiting

**URL:** <https://discourse.haproxy.org/t/leaky-bucket-method-with-haproxy-rate-limiting/3450>\
**Category:** Help!\
**Created:** [January 29, 2019, 3:34pm UTC](https://discourse.haproxy.org/t/leaky-bucket-method-with-haproxy-rate-limiting/3450 "2019-01-29T15:34:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seb176](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@seb176](https://discourse.haproxy.org/u/seb176)\
**Post date:** [January 29, 2019, 3:34pm UTC](https://discourse.haproxy.org/t/leaky-bucket-method-with-haproxy-rate-limiting/3450/1 "2019-01-29T15:34:55Z")

</div>

Nginx uses the leaky bucket method to limit request rate. [Nginx http\_limit\_req\_module](http://nginx.org/en/docs/http/ngx_http_limit_req_module.html).

It means that if I set a limit to 100 req/sec, and then I get flooded by 120 req/sec, 100 requests will be served normally but 20 requests will be served by a 503 error.

How can I setup this with Haproxy?

I read a lot of the documentation about **sc\_http\_req\_rate** but since the rate **is always** 120 req/sec. I am always returning 503 errors.

```auto
frontend main
    bind *:80
    acl foo_limited_req sc_http_req_rate(0) ge 100
    http-request track-sc0 path table Abuse # Set the URI as the key of the table
    use_backend bk1 if foo_limited_req
    default_backend web

backend web
    server web1 192.168.0.10

backend Abuse
    stick-table type string len 128 size 100K expire 30m store http_req_rate(1s)

backend bk1
     server listenerror 127.0.0.1:81

listen errorlistener
    bind 127.0.0.1:81
    mode http
    errorfile 503 /etc/haproxy/errors/200-tuned.http

```

I want to serve the flow of 100 req/sec with _web_ backend. And the 20 req/sec surplus with _bk1_ backend. I am using Haproxy version 1.9.2.
