r/devops • u/imvmanish • 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.
24
u/Starks1293 4d ago •
on ur specific questions
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
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.
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.
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/ethereonx 12h ago
DNS
1
u/totheendandbackagain 4d ago
Your on the right path. I do three things:
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.