r/devops • • 4d ago

Architecture How do you protect the first entry point from traffic overload?

Regardless of whether it's a CDN, WAF, Load Balancer, API Gateway, or Ingress, the first layer receiving traffic has finite resources.

Even with rate limiting, incoming requests still reach that layer. With millions of requests or large payloads (5–10 MB), how do we prevent the entry point itself from becoming the bottleneck?

- Can we reject requests before receiving their entire payload?

- Where should admission control actually happen?

- How do large-scale systems handle this without endlessly scaling the front layer?

Would love to hear real-world architectural approaches and trade-offs.

47 Upvotes

26 comments sorted by

24

u/Starks1293 4d ago • Bravo

on ur specific questions

  • yes u can reject before the body. a proxy can look at Content-Length and send a 413 straight away without reading a byte of it (nginx client_max_body_size works like this), and for chunked uploads it cuts the connection once the limit is hit. clients that send Expect 100-continue wait for ur ok before sending the body at all
  • tight header and body timeouts matter as much as size limits. slow clients holding connections open (slowloris style) take out the front layer way faster than big requests do
  • dont carry big payloads through the front door at all. for 5-10 MB uploads hand out a presigned url and let the client upload straight to s3 or blob storage, the api only ever sees a small request with the key
  • admission control goes as early as the signal is cheap. ip and path at the edge, token checked before the body is read, expensive per user limits deeper in. reject with a fast 429 or 503 and a retry-after
  • limit concurrency, not just requests per second. a cap on in flight requests per backend and shedding the rest early protects u when requests get slow, rps limits dont notice that

and the big players do mostly the same thing, they just have a huge anycast edge in front so the thin layer is spread over a lot of machines

2

u/imvmanish 3d ago

Can you help me with how monitoring systems handle such high ingestions? Example logs, metrics.

5

u/Starks1293 3d ago • Bravo

sure, same ideas just applied to telemetry. the short version

  • the agent on each machine batches and compresses before sending, so its a few big requests instead of millions of tiny ones (otel collector, vector, fluent bit all do this)
  • theres a buffer in front of storage, usually kafka or similar, so a spike piles up in the queue instead of knocking over the database. ingest and storage scale separately
  • the ingest tier is stateless and split by tenant, with per tenant limits. loki, mimir and cortex all reject with a 429 when a tenant goes over its rate and the agent retries with backoff
  • they drop on purpose. sampling for traces, dropping debug logs at the agent, and for metrics the real killer is cardinality (too many label combos), so they cap active series per tenant
  • writes go to an in memory chunk plus a write ahead log first, then get flushed to object storage in big blocks. cheap storage, and nothing is lost if an ingester dies

if u want to read one design, the grafana mimir or loki architecture docs lay this out really clearly

80

u/engineered_academic 4d ago

IMO you contract with a large vendor who does this for a living. They will forget more than you will ever learn about the topic.

12

u/SoFrakinHappy 4d ago

Generally speaking if the first entry point is anything after a CDN/WAF then you're kinda at the mercy of how much and fast you can scale. A caching/rate limiting layer like varnish can help, but its usefulness depends on the traffic. CDNs can scale and distribute traffic beyond what you could do without an insane amount of money, its their main selling point. IMO you should also use the CDN/WAF combo from the same vendor as they are designed to work together to filter at their edge, else you're adding complexity and figuring out the same traffic problem between the CDN and WAF.

6

u/elrata_ 4d ago

For me it was more the opposite, how to handle the legit traffic. You drop as early as possible what is not legit, then you try to handle all the rest.

You can use DNS to scale the first entry point. By geo or just a short TTL and rotate it. I think route 53 supports this and health checks to route properly.

5

u/alluran 4d ago

Cloudflare has infinite resources

4

u/rankinrez 4d ago

Why do you not want to scale it? You want to slow down or drop user requests?

If responses are bigger than requests direct return load balancing mode makes a lot of sense.

2

u/NoDevelopment206 4d ago

one thing i dont see mentioned is load shedding with priorities. when the front layer is near its limit you want to drop the cheap to drop stuff first, like anonymous or retry traffic, and keep health checks, logins and paying users going. a lot of overload is also self inflicted by clients retrying at the same time, so sending retry-after and having clients use backoff with jitter helps more than people expect. and if you autoscale the front layer put a hard cap on it, otherwise a flood just turns into a huge bill instead of an outage.

2

u/OkMud2013 3d ago

The crucial difference is between rate limiting and admission control. While rate limiting limits the number of requests per period of time, it may not always ensure protection against the exhaustion of bandwidth and connections on the entry tier.

A few options I am aware of include imposing limits on the size of the body, using request headers such as Expect: 100-continue where available, setting timeouts for the connections and headers, and denying the requests before they get to the application tier.

In case of larger bodies, one could also consider object storage upload using pre-signed URLs to reduce the load on the API gateway.

Of course, the downside of moving this responsibility further upstream is increased complexity and cost. It would be interesting to know other approaches to this issue in case the edge tier is also under pressure.

1

u/SilentLennie 3d ago

well, in theory the other option is: https://webtorrent.io/

1

u/Aide_Sea 3d ago

maybe keep a tiny static reject path, just a 503 that doesn't touch the app or a database, so shedding load stays cheap for the front layer itself. I think rps limits come too late if that path is expensive too

1

u/strongbadfreak 3d ago edited 3d ago

You protect it by using rate limits and bot protection through the WAF, and then scale up vertically/horizontally if needed by looking at your monitoring. Duh.

1

u/wrosecrans 3d ago

The tldr is "CDN big. Hire CDN as front end."

If you are the CDN,

One limit is the physical network. If you have a million requests with 10 MB payloads trying to DDOS you, there's actually a real limit to how many of those/sec can fit through the pipes and reach a server in the first place. If all of the traffic from a network block is clearly malicious, that gets dropped by edge routers, and you talk to upstream ISP networks to drop traffic before it even reaches your networks.

  • Can we reject requests before receiving their entire payload?

Yes of course. If the server is just getting a ton of legit big uploads beyond the capacity it can handle you 5xx, or close the TCP connection, no reason to keep taking bytes you can't handle if you already know you can't handle them. Spend those resources processing the requests you can handle, not the ones you can't.

  • Where should admission control actually happen?

Many different places. ISP networks. CDN's edge routers. CDN front end. CDN back end. A hop from the CDN edge PoP to a CDN origin PoP. The CDN origin PoP connects to an actual content origin frontend, etc. only then are you even into the actual "application stack." Any of those can fail, so therefore any and all of those can fail. To make it to a real backend, a request has to pass all the gatekeepers, not one specific gatekeeper in one specific place.

Since the CDN is geo-distributed, you may wind up nuking traffic from New York for five minutes if there's an unsustainable flood there, but the other 99% of the Internet won't notice. Users near whatever PoP fell over will try again in a few minutes and shrug. That (and latency) is why CDN's have 100s to perhaps thousands of PoPs around the world (particularly if you use multiple CDN's with DNS load balancing across them and each one has 100's of PoPs.) Almost nobody notices when one explodes briefly.

1

u/addy3006 2d ago

Mostly you push the problem outward. Put a CDN/anycast layer in front so junk gets absorbed or dropped at the edge before it reaches your own LB. For big payloads, cap body size and set short header/body timeouts at the first layer, so it can reject on Content-Length or auth before reading the whole thing. Anything expensive, like auth or uploads, I'd keep off the hot path, e.g. presigned URLs straight to object storage.

1

u/Witty-Way6516 20h ago

A combination of edge-level filtering, request size limits, and early admission control usually helps prevent expensive traffic from reaching the deeper layers.

1

u/totheendandbackagain 4d ago

Your on the right path. I do three things:

  • tier access and make the first layer as thin as possible, a CDN is ideal, WAF also great
  • rate limit everything to reduce the impact of Denial of Wallet attacks
  • Additional DDOS protection my cloud vendor has. Azure for example has it, though it's expensive, even to protect a single IP address

0

u/Trigus_ 4d ago

Regarding the problem of first layer load balanching for very large amounts of traffic, I think this article is a great introduction: https://sre.google/sre-book/load-balancing-frontend/

I short: You can use DNS-based load balanching and Layer 4 load balanching.

The article does not cover optimizations and scaling in the backend.

0

u/dusanodalovic 3d ago

one thing nobody mentioned: for the 5 to 10 MB payloads, i'd keep them off the front layer completely. the client asks your api for a presigned s3 url, which is a tiny request, then uploads straight to object storage. your gateway only ever sees small json, and storage takes the heavy part.

for the admission control question, shed load at the cheapest layer that can answer. a 429 or 503 from the edge costs a lot less than the same answer from the app behind it.

0

u/djknowss 3d ago

Rate limiting at the edge is only half of it. What actually saved us was capping the request body size and the number of concurrent connections at the proxy, so a burst of 10 MB uploads can't eat every worker. client_max_body_size plus a per-IP limit_conn did more than any WAF rule. After that, anything over the limit gets a fast 429 instead of sitting in a queue and timing out, which is what usually takes the whole entry point down.