Web / NGINX Interview questions
What is the difference between limit_req and limit_conn for rate limiting?
Both directives protect backends from being overwhelmed, but they limit different things.
| limit_req | limit_conn |
| Limits the rate of requests over time, e.g. 10 requests per second. | Limits the number of simultaneous open connections per key. |
| Uses a leaky-bucket algorithm, can allow controlled bursts. | Simple concurrent count, no time dimension. |
| Good against rapid-fire abuse like brute-force login attempts. | Good against a client holding many connections open at once, e.g. slow downloads. |
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s; limit_conn_zone $binary_remote_addr zone=addr:10m; server { location /login { limit_req zone=one burst=20 nodelay; limit_conn addr 5; } }
They're frequently combined - limit_req to throttle how fast a client can hit an endpoint, and limit_conn to cap how many connections that client can hold open at the same time.
More Related questions...