I Got Hit With 3TB of Traffic at 2 A.M. — Here's How I Set Up Bandwidth Caps and Alerts
A late-night traffic spike burned through 3TB of CDN egress while my origin stayed perfectly healthy. I walk through how I split traffic alerts from availability alerts, set per-route bandwidth caps with headroom, and built a three-layer alerting setup that actually wakes me up — plus the smaller fixes that followed.
At 2:17 in the morning my phone buzzed on the nightstand. I figured it was the old monitoring box acting up again, rolled over, and ignored it. Ten minutes later it buzzed again — three messages in a row this time. I got up and checked the dashboard. The traffic graph had gone almost vertical, jumping from the usual 30Mbps to 1.2Gbps and holding there for nearly twenty minutes.
By the time the bill settled that morning, there was an extra 3TB of egress. Not an astronomical amount of money, but the feeling of someone wandering in at night and helping themselves stung. What stung more was going through the logs afterward and realizing that from start to finish, apart from that one curve, nothing anywhere had actively told me something was wrong.
Most people's first reaction is "I'm getting CC'd." It wasn't that. CC attacks hammer request counts, origin CPU, database connections. This was pure egress. Request counts weren't high — maybe a dozen requests per second from a single IP — but every request was pulling a several-hundred-megabyte installer package. Basically someone was using my download site as free cloud storage. The URLs were public, no auth, cache hit rate was excellent, the edge nodes served the files directly, the origin didn't feel a thing, and the whole bill landed on CDN egress. The nastiest part of this kind of attack: the origin is perfectly healthy, every availability check is green, and only your wallet is bleeding.
So the first thing I did was split "traffic anomaly" and "availability anomaly" into two completely separate alert categories. Before that I only had an origin liveness probe, and that thing was blind to this situation.
Bandwidth caps — I resisted them at first. I was afraid of collateral damage, of cutting off my own normal traffic during peak hours. Then it clicked: without a cap, you're letting the attacker decide your ceiling.
My approach is to set them per route, not one-size-fits-all. I watched the evening peak for a week, noted the actual maximum on each route, and set the cap at 2.5 to 3 times that. Say a route peaks at 80Mbps normally — the cap goes around 220Mbps. That number means normal traffic could triple and still not touch it, but the moment someone starts hammering, they hit the line within minutes. Hitting the line doesn't kill service outright; it degrades first: limit per-IP connections and new connection rate, throttle large-file delivery, make it not worth the attacker's while while normal users still get through, just slower. Doing packet drops and rate limiting at the kernel layer is far less hassle than blocking requests at the application layer — I tuned this against the protection docs over two rounds before it felt right.
One detail worth mentioning. Don't set the cap to a round number. My first version was 200Mbps, and some hourly backup job plus normal traffic would graze the line once or twice a month, and the alert would scare the hell out of me. I changed it to something like 217 with an odd tail, and the false positives dropped a lot. Sounds like superstition, but it works.
Bandwidth caps are the brakes; alerts are the dashboard. The best brakes in the world are useless if nobody's watching the dashboard.
I now have three layers. Layer one is an absolute threshold: egress above 1.8x the daily peak for 5 minutes triggers a push. Layer two is a slope alert, which is far more useful than absolute values: regardless of current traffic, if the growth rate over 3 minutes exceeds a certain value, it fires. At 3 a.m. traffic going from 20Mbps to 200Mbps might not hit the absolute line yet, but the slope is already insane. Layer three is origin fetch ratio: if cache hit rate suddenly drops from 95% to below 70%, someone is hammering dynamic requests or punching through the cache, and that's usually followed closely by the origin falling over.
Where alerts go matters too. I don't use email — nobody reads it at night. Now it's instant messages pushed to my phone, plus a phone call as a fallback, and the call only happens when "slope alert + cap triggered" are both true, so I'm not getting woken up every night.
Incidentally, around that time I was also digging into CC issues and wrote up which numbers I check first under a CC attack. The metrics in there and this traffic alerting are really the same idea: look at the trend first, then the absolute value, and don't wait for the bill to do your postmortem.
After the big moves, there were a handful of small things I patched in over time. None of them look like much on their own, but together they let me sleep.
All download URLs got auth — type A, with expiry. Old links stop working, so I put a redirect notice on the page and users just click again. That alone closed most of the "use me as cloud storage" route. IP allow/deny lists are managed by group: normal crawlers, partner origin fetches, internal testing each get a group, and when something goes wrong I block the group instead of individual IPs. A partner once ran a batch job at night and I was blocking IPs one by one until my hands hurt — after grouping, one rule solved it.
Then there are node logs. I used to only look at aggregates. Now I regularly go through the last 72 hours of real-time access logs looking for entries where "a single IP has low request volume but an extremely high share of egress." Those accounts are basically freeloaders, and catching them early saves trouble.
Last is config changes. When something blows up at 2 a.m., that's when people panic, and panic is when you fat-finger things. Now every config change involving bandwidth, auth, or blocking goes out signed, with an audit trail — who changed what at what time is crystal clear. I also turned on mandatory two-factor auth in the console. One more door never hurts.
Honestly, bandwidth caps and alerts only reduce my losses — they don't eliminate them. The genuinely hard part is judgment: is this sudden traffic spike an attack, or did some channel's content suddenly blow up? The former should be blocked; blocking the latter is cutting off your own revenue. Right now I still distinguish them by hand, looking at request characteristics and Referer — slow, and my brain is foggy when I'm woken up at night. If there's smarter automatic detection out there, I want to try it first.
After those 3TB, my biggest change wasn't a few extra rules. It was finally admitting: an origin being alive doesn't mean the business is safe, and the bill is also an availability metric.