Architecture

Admission Control and Load Shedding: Keeping a Server Alive Under Overload

By NileVPS Team · Published · 4 min read

اقرأ المقال بالعربي

A server that accepts every request it receives will eventually accept more than it can finish. When that happens, latency climbs for everyone, timeouts trigger client retries, and the extra retries push the server even deeper into overload. Admission control is the practice of deciding, at the front door, whether a request should be accepted at all. Load shedding is what you do when the answer is no: reject some work quickly so the rest can still succeed. This article explains why these techniques matter and how to apply them on an ordinary VPS.

Why Overload Collapses Throughput

Intuitively, a busy server should simply process requests at its maximum rate. In practice, throughput often falls when load exceeds capacity. Several effects combine:

  • Queues grow without limit. Requests wait so long that clients have already given up by the time the server answers, so the work is wasted.
  • Retries multiply load. Each timed-out request may come back two or three times.
  • Resource contention rises. More concurrent work means more context switching, more memory pressure, more lock contention and sometimes swapping.
  • Dependencies slow down too. A database flooded with connections becomes slower for every caller.

The goal of admission control is to keep the server operating near the point where it does the most useful work, not to squeeze in every possible request.

The Core Techniques

Concurrency limits

Cap the number of requests being processed at the same time. A worker pool, a semaphore, or the pm.max_children setting in PHP-FPM all act as concurrency limits. When the limit is reached, new requests wait in a short queue or are rejected.

Bounded queues

A queue absorbs short bursts, but an unbounded queue only converts overload into latency. Give every queue a maximum length and a maximum wait time. A request that has waited longer than the client is willing to wait should be dropped, not processed.

Rate limits

Rate limiting controls how many requests a client or key may send per unit of time. It protects against individual abusive clients, while concurrency limits protect against total overload. You usually want both.

Priorities

Not all requests are equal. Health checks, checkout pages and logged-in users may deserve capacity before anonymous crawlers or batch exports. When shedding load, reject the least important traffic first.

Fast, honest rejection

A rejected request should fail quickly and clearly, typically with HTTP 503 or 429 and a Retry-After header. A fast rejection costs the server almost nothing; a slow timeout costs a worker slot for the entire wait.

Practical Settings on a VPS

Here is how these ideas map to common tools:

LayerSettingEffect
Nginxlimit_conncaps concurrent connections per key
Nginxlimit_req with burstcaps request rate with a small burst allowance
PHP-FPMpm.max_childrencaps concurrent PHP workers
PHP-FPMlisten.backloglimits the queue of waiting connections
Gunicorn / Uvicorn--workers, --backlogcaps worker processes and pending connections
PostgreSQLmax_connections, plus a poolerprevents connection storms

A minimal Nginx example that limits each client IP and returns 503 when exceeded:

http {
    limit_req_zone  $binary_remote_addr zone=perip:10m rate=10r/s;
    limit_conn_zone $binary_remote_addr zone=connip:10m;

    server {
        location /api/ {
            limit_req  zone=perip burst=20 nodelay;
            limit_conn connip 20;
            limit_req_status  503;
            limit_conn_status 503;
            proxy_pass http://127.0.0.1:8000;
        }
    }
}

These numbers are placeholders. Measure your application under load with a tool such as wrk, k6 or hey, find the concurrency where latency starts to rise sharply, and set limits just below that point.

Inside the application, a simple pattern is a semaphore around expensive work:

import asyncio
from fastapi import FastAPI, HTTPException

app = FastAPI()
slots = asyncio.Semaphore(32)

@app.get("/report")
async def report():
    if slots.locked():
        raise HTTPException(status_code=503, headers={"Retry-After": "5"})
    async with slots:
        return await build_report()

Adaptive Admission Control

Static limits are a good start, but capacity changes with the workload. Adaptive approaches adjust the limit based on observed latency: if response times rise above a target, the limit shrinks; if they stay low, it grows. This is similar to how TCP congestion control probes for available bandwidth. Several open-source libraries implement this idea, and service proxies such as Envoy include overload and concurrency features. On a single VPS, static limits plus monitoring are usually enough.

Checklist

  1. Set a concurrency limit for every worker pool.
  2. Bound every queue by length and wait time.
  3. Reject early with 503 or 429 and Retry-After.
  4. Classify traffic and shed the lowest priority first.
  5. Make clients retry with exponential backoff and jitter.
  6. Load test to find real limits instead of guessing.
  7. Monitor rejection rate alongside latency and errors.

Admission control works hand in hand with backpressure, which pushes the overload signal back toward producers. When your limits are consistently reached by legitimate traffic, that is the signal to add capacity; you can compare plan sizes on the pricing page.

FAQ

Is load shedding the same as rate limiting?

No. Rate limiting restricts how fast a particular client may send requests, regardless of server state. Load shedding rejects requests because the server as a whole is at capacity, even if each client is behaving normally. A robust setup uses both.

Should I return 503 or 429 when shedding load?

Use 429 Too Many Requests when a specific client has exceeded its quota, and 503 Service Unavailable when the server is overloaded for everyone. Include Retry-After in either case so well-behaved clients know when to try again.

Will rejecting requests hurt my users?

Some users will see an error, but without admission control many more would see slow pages and timeouts. Fast rejection keeps the service responsive for the requests it does accept, and clients that retry with backoff usually succeed shortly after.

Related guides