WEBVTT

00:00.000 --> 00:00.920
So let's get started.

00:00.920 --> 00:01.880
I'm Spencer Koch.

00:01.880 --> 00:03.740
I'm a principal security engineer at Reddit.

00:03.740 --> 00:05.220
And I'm joined by Prateek.

00:05.360 --> 00:08.120
He's a senior security engineer at Reddit as well.

00:08.120 --> 00:09.600
And we're on the security team.

00:10.080 --> 00:13.720
And so thank you to the DDoS village for having us be up here.

00:13.720 --> 00:14.620
And we sponsored them too.

00:14.620 --> 00:16.140
So we're great to see that advance.

00:16.280 --> 00:18.860
And I know we've got some moral support in the back as well.

00:18.860 --> 00:20.060
So thanks for coming out.

00:20.060 --> 00:22.360
And we're going to be talking about DDoS stuff.

00:23.660 --> 00:29.940
So in terms of context, and I'll try to read the top of the slide as you attempt to follow me through my slides that are online.

00:30.000 --> 00:31.700
So what are you going to get from this talk?

00:31.700 --> 00:35.360
So hopefully we should be able to go through an architecture.

00:35.360 --> 00:36.880
How do we think about rate limiting?

00:36.880 --> 00:42.380
And so the way that we kind of construct that mental model at Reddit so that we can do defense against it.

00:42.380 --> 00:45.320
We'll talk about signals and why they are so darn important.

00:45.320 --> 00:47.180
We're going to talk about where do we do rate limiting?

00:47.180 --> 00:48.500
When should we do that rate limiting?

00:48.500 --> 00:50.340
And why do we want to do that rate limiting?

00:50.540 --> 00:57.880
We'll talk about other resiliency strategies that don't necessarily fit in well to that particular do it at an edge or do it in an application.

00:57.880 --> 01:05.600
And then we'll talk about some lessons learned as we've kind of fought DDoS literally forever, but at least the last six years, which is my tenure.

01:05.600 --> 01:10.060
And there were only two of us when we started doing DDoS preventions a long time ago.

01:10.060 --> 01:16.980
So a lot of interesting things as you start in a scrappy startup mode and don't pay a vendor to just make the problem go away.

01:18.220 --> 01:25.980
So in terms of if you haven't heard of Reddit, and there's a banana for scale on the slide, which is the joke that would have been better delivered up here.

01:25.980 --> 01:28.240
We do a lot of traffic.

01:28.240 --> 01:31.320
So 1.3 trillion requests every week.

01:31.320 --> 01:34.620
We do 175 petabytes every week.

01:34.640 --> 01:36.280
That's a lot of stuff.

01:36.280 --> 01:39.660
And so we do this in conjunction with some of our CDNs.

01:39.680 --> 01:42.560
We are fastly and looking at Cloudflare right now.

01:42.560 --> 01:47.680
We are also AWS based for the most part for our serving side of the platform.

01:47.960 --> 01:51.100
And so that's a lot of stuff to flow through cloud providers.

01:51.880 --> 01:59.200
In terms of services, just to give you another sense of scale, like our GraphQL endpoints, that's mostly all of our new APIs.

01:59.640 --> 02:02.720
275,000 requests a second.

02:03.380 --> 02:06.420
And you can see some of the other metrics that are there.

02:06.420 --> 02:08.360
We do a lot of traffic.

02:08.580 --> 02:11.700
And so doing things at scale becomes really important.

02:13.380 --> 02:24.020
In terms of where we came from, from a DDoS perspective, in 2019, that's roughly when I joined myself and a gentleman named Jason Harvey.

02:24.100 --> 02:39.220
We essentially were in charge of DDoS prevention, which was a lot of whack-a-mole, a lot of like, well, we think we could get away with this in the cheapest, easiest time frame and then wait until the next stupid DDoS attack came through and figure out how do we want to respond.

02:39.400 --> 02:41.600
In 2021, we started getting more serious.

02:41.600 --> 02:44.640
So this is right around the time of our API riots.

02:44.640 --> 02:48.360
And we changed the way that we wanted to do how people interact with the platform.

02:48.420 --> 02:49.900
Don't yell at me about that.

02:49.900 --> 02:51.320
I just work here.

02:51.540 --> 02:57.840
But that means we needed to figure out how do we monitor and manage the traffic that's coming to us and take actions against it.

02:57.840 --> 03:00.820
So that's when we first started staffing our transport team.

03:00.980 --> 03:11.400
And then finally, where we are now in 2025, we have a traffic and a transport team, both looking at the defense of the traffic coming into Reddit, as well as how do we distribute that from a global load balancing perspective.

03:11.600 --> 03:13.820
And they're focused on DDoS mitigations.

03:14.640 --> 03:23.680
So in terms of signals, the first major component of how do you think about DDoS prevention, you have a whole bunch of signals, or hopefully you do, if you're fighting against DDoS.

03:23.860 --> 03:26.480
The first one that we'll talk about is the foundational ones.

03:26.480 --> 03:29.480
These are the things that you basically get out of the box with any CDN.

03:29.840 --> 03:32.460
Literally, you could be running an NGINX proxy somewhere.

03:32.840 --> 03:35.500
It's the stuff you get basically for free.

03:35.620 --> 03:37.140
GUIP is super easy.

03:37.140 --> 03:38.480
It's not super useful.

03:38.500 --> 03:49.120
We'll start talking about, as we go down this list, they get more and more interesting, more and more important into your mental model of how do you want to build a defense for DDoS, as we go through this.

03:49.120 --> 03:53.440
I have GUIP+, because there's often an enrichment.

03:53.700 --> 03:55.220
We're in Fastly right now.

03:55.220 --> 03:59.340
We have a company called Digital Elements, who supplements data into Fastly.

03:59.340 --> 04:12.220
They give us additional information around hosting provider, is it a Tor exit node, all these distinctions around what could the traffic be, or what the user base could be behind that IP that's hitting us.

04:12.220 --> 04:13.100
That's why I say GUIP+.

04:14.480 --> 04:16.320
User agent is a fantastic one.

04:16.320 --> 04:21.100
Again, we're talking about 300,000 requests a second.

04:21.100 --> 04:24.940
We can model a lot of things, interestingly, with user agent.

04:24.940 --> 04:31.980
We can see, okay, for the patterns of the URLs that are being hit, for the paths that are being hit, do we see that that's actually coming from our iOS apps?

04:31.980 --> 04:35.600
Or do we have a random iOS app that's now hitting something that it definitely shouldn't?

04:35.600 --> 04:36.920
That's our web platform.

04:37.240 --> 04:38.800
Okay, there's something fishy there.

04:38.800 --> 04:40.400
Again, that signal helps us out.

04:40.800 --> 04:42.720
And path and query, those things come for free.

04:42.720 --> 04:49.900
So sure, these are all like the fundamental, bare minimum, things that you can do from a very raw, coarse-grained type modeling perspective.

04:50.280 --> 04:52.040
Now we're going to start moving up the stack.

04:52.400 --> 04:54.040
The first one is TLS fingerprints.

04:54.040 --> 05:00.760
We're still very much focused on where that traffic originated, or how that traffic initially got out the door.

05:00.900 --> 05:05.820
So at TLS fingerprint, if you aren't aware, I left a couple of links around Jaw 3 and Jaw 4.

05:05.820 --> 05:10.920
I did not come up with them, but they are super great tools for how you think about fingerprinting.

05:10.980 --> 05:12.320
What is the actual OS?

05:12.340 --> 05:13.280
What is the client?

05:13.280 --> 05:15.580
What are the libraries that are loaded behind the scenes?

05:15.720 --> 05:21.860
That is how you can focus on the type of machine or the platform that is making that request.

05:22.060 --> 05:24.540
And again, as we're going through here, we're stacking up a whole bunch of things.

05:24.540 --> 05:27.580
We're actually starting low-level and starting to move up the OSI stack.

05:27.980 --> 05:31.900
This is a great mechanism to figure out what is going on behind the scenes.

05:32.460 --> 05:36.200
Definitely based on, again, if you're not familiar with it, go check it out.

05:36.200 --> 05:40.180
It should be, by default, available for all of your CDN providers.

05:40.180 --> 05:44.380
And there's Nginx plugins that you can add to add that in.

05:44.380 --> 05:46.500
So pretty well solved.

05:46.520 --> 05:52.060
There's some fun things like Grease, which was meant to help with determining the interoperability of cipher suites.

05:52.080 --> 05:56.500
It's bad for us because that means there's a whole bunch of random garbage that shows up in those fingerprints.

05:56.720 --> 06:01.280
And so that means we need something like a Jaw 3 or Jaw 4 to exclude that noise.

06:01.560 --> 06:03.280
Same thing with protocol sprawl, right?

06:03.280 --> 06:10.120
So if you have HTTP 3, you have QUIC coming along, you're seeing a modification of how those handshakes are happening.

06:10.120 --> 06:12.920
That's just adding more complexity from a fingerprinting perspective.

06:13.040 --> 06:13.860
But that's okay.

06:13.860 --> 06:15.900
You just have to remember that it exists.

06:16.420 --> 06:19.260
And the next slide, I included an overview of Jaw 4.

06:19.580 --> 06:21.100
Again, you should totally go look it up.

06:21.100 --> 06:30.420
If you don't know what it is, it should be readily available for you from a CDN perspective to add into your mix of here's a list of things that I can start doing rate limiting with.

06:31.820 --> 06:32.400
Okay.

06:32.400 --> 06:33.400
So now we're into the interming.

06:33.400 --> 06:34.820
So we were fingerprints before.

06:34.820 --> 06:37.140
We're now kind of sort of retina scanning.

06:37.500 --> 06:40.380
The first thing we'll talk about is the request header fingerprints.

06:40.380 --> 06:42.560
Now, this one's not super well publicized.

06:42.560 --> 06:43.520
There are a couple.

06:43.520 --> 06:47.540
I dropped a link that talks about what it is in theory.

06:47.640 --> 06:53.360
I have not found a whole lot of documentation or examples out in the wild of this is exactly how it's done.

06:53.680 --> 06:58.840
I'm hoping that we should be able to open source our implementation from a Reddit standpoint relatively soon.

06:58.840 --> 07:02.860
It's actually, I mentioned Fastly on here, this Fastly info OH fingerprints.

07:03.340 --> 07:05.720
Fastly built that using our algorithm.

07:06.040 --> 07:12.700
And so now we have a header, this request header fingerprint that's available because we made Fastly do it.

07:12.700 --> 07:14.940
We pay them enough, it's the least they could do.

07:15.040 --> 07:16.560
Same thing with Cloudflare, right?

07:16.560 --> 07:20.360
We got the exposure of what are the raw request header names.

07:20.360 --> 07:23.220
And now we can start doing maths against that.

07:23.220 --> 07:25.760
So what actually is the request header fingerprint?

07:26.300 --> 07:28.620
So we talked about like the TLS fingerprint, right?

07:28.620 --> 07:32.380
Like the way that the client is configured, the Cypher suites that it's going to have, et cetera.

07:32.500 --> 07:34.780
Okay, well now bump it up into HTTP land.

07:35.060 --> 07:39.360
The way that an HTTP request is constructed is very dependent upon what client you're using.

07:39.360 --> 07:40.840
Is it a Golang request client?

07:40.840 --> 07:42.620
Is it a Python request client?

07:42.700 --> 07:44.440
Is it some, is it curl?

07:44.440 --> 07:53.660
Like all of those have very distinct ways that they craft an HTTP packet, which provides you additional data about what type of thing is making that request behind the scenes.

07:53.700 --> 07:56.260
So we're moving up the stack from OS to libraries perspective.

07:56.260 --> 08:00.480
We're now in the land of what is the actual client that is making those calls.

08:00.860 --> 08:07.140
On the subsequent slide in the code, I have a whole bunch of, like that is an example, literally taken from our source code internally.

08:07.520 --> 08:14.080
Nothing juicy there, but it is essentially an example of, here's a request that might have come through from our proxy perspective.

08:14.560 --> 08:16.200
We do some maths.

08:16.440 --> 08:18.080
And I'm not a maths, I'm an engineer.

08:18.120 --> 08:23.100
So you get maths and you get down at the bottom, which is essentially a glorified fingerprint, right?

08:23.360 --> 08:32.580
Again, I'm going to hope to be able to publish the algorithm in open source relatively soon, but just know that Fastly will return you exactly that.

08:32.720 --> 08:40.960
Which is great, because now you can take that as, this is a unique string that I can use in my ML learnings or to understand what do I want to block against.

08:41.340 --> 08:43.800
It's a great another example of a fingerprint.

08:44.760 --> 08:47.600
And so finally, we have advanced signals.

08:48.580 --> 08:52.180
So the first thing to think about is the network request timings.

08:52.180 --> 09:01.940
So we're starting to get into things where it makes a lot of sense to throw into a model and do things async, rather than I need to do something as the request is coming to me in a synchronous fashion.

09:02.080 --> 09:04.560
Network request timings are great examples of that.

09:05.180 --> 09:13.360
You should roughly know, if you know anything about your app, you should roughly know the order of operations and the timing that your app behaves.

09:13.620 --> 09:15.580
And you can glean information from that.

09:15.580 --> 09:20.900
So for example, if you go to Reddit, if you go to new Reddit, I'm not going to talk about old Reddit, also don't come after me.

09:21.000 --> 09:23.900
New Reddit, we have, it's a single page app.

09:23.900 --> 09:29.820
You load that, it loads a whole bunch of JavaScript bullshit, and then you're basically done until you scroll down.

09:29.980 --> 09:43.060
So I should have a burst of network traffic at the very beginning that's loading in assets and resources, making a couple of GraphQL calls to populate the initial page, like populate the DOM out, and then I'm going to be quiet and maybe emit some events.

09:43.260 --> 09:44.320
Is the user still there?

09:44.320 --> 09:45.840
What experiments did we expose?

09:45.840 --> 09:46.380
Et cetera.

09:46.380 --> 09:48.980
There's a rough pattern that exists there.

09:49.380 --> 09:53.160
And that's assuming that you're using a browser or Chrome or whatever.

09:53.160 --> 10:02.280
Now, if you're just curling something, I can tell real quick that you didn't do anything, because curl's not going to do it, I mean, unless you add flags and you try to emulate that on purpose.

10:02.280 --> 10:08.420
If you just try to hit a post, I can easily tell that, yep, you're behaving in a particular way that is non-human.

10:08.420 --> 10:10.060
I can get that distinction then.

10:11.080 --> 10:12.440
Same thing with analytic events.

10:12.440 --> 10:18.960
If those fire or don't fire, curl doesn't care that there's JavaScript that needs to exist that should fire out that event.

10:19.020 --> 10:22.360
I can get some information about the absence of that data there.

10:22.360 --> 10:24.260
Same thing with cookies and JOTs.

10:24.740 --> 10:30.860
We'll talk about a resiliency technique that happens when we don't have a JOT or a cookie on the request.

10:31.140 --> 10:39.180
But if I see something and I can tell, like, oh, yeah, there's no actual, you know, you're hitting, you're going to a post directly, well, there probably should be trappings about that request.

10:39.180 --> 10:47.260
So, like, if you're coming from an embed for maybe you're on some other competing platform, how dare you, there would be an origin that would come across that.

10:47.260 --> 10:55.000
So I should be able to match up, okay, I understand there are additional headers that should flow as a natural evolution of web traffic.

10:55.000 --> 10:59.300
If that doesn't exist, then I can pretty much tell that, yeah, you just sent out a curl request.

10:59.300 --> 11:02.060
You're not an actual human that's surfing Reddit.

11:02.760 --> 11:12.920
And then finally, the extension of that is to take your most prized or your most sensitive or most well-known flows and understand what that order of operation is.

11:12.920 --> 11:15.320
We know exactly how our login flow works.

11:15.320 --> 11:18.360
It is literally essentially three API calls.

11:18.420 --> 11:20.580
If those happen out of order, well, okay, great.

11:20.580 --> 11:24.860
Now I can tell that you're trying to brute force passwords or I can tell that you're doing something nefarious.

11:24.860 --> 11:25.820
You're not a real human.

11:25.820 --> 11:30.140
Again, this is additional signal, but it's much higher level of complexity.

11:30.160 --> 11:34.720
I have to do some asynchronous processing to understand is it good or is it bad?

11:37.480 --> 11:37.940
All right.

11:37.940 --> 11:40.100
So now I'm going to talk about where do we rate limit.

11:40.100 --> 11:44.500
So I have all this signals and these exist between an edge and an application.

11:44.900 --> 11:47.180
And I'm completely discarding layer three and four.

11:47.180 --> 11:51.500
There are, you know, I'm paying a CDN or I'm paying a cloud provider to make that problem go away.

11:51.500 --> 11:56.660
So like the HTTP 1.1 desyncs that we had in the news the other week, I don't care.

11:56.660 --> 11:58.940
Fastly can send me a postmortem and it's fine.

11:59.200 --> 12:02.080
I do care from a HTTP perspective.

12:02.360 --> 12:04.840
So now I get to make a decision of do I do that at the edge?

12:04.840 --> 12:08.280
So if I'm in my CDN or do I do that at my application?

12:08.720 --> 12:11.480
And so the way that I'm thinking about this are twofold.

12:11.540 --> 12:12.840
I can think about cost.

12:12.840 --> 12:17.980
So doing at the edge always makes it cheaper from my perspective because that means it doesn't have to hit my app.

12:17.980 --> 12:19.100
I don't have to load data.

12:19.100 --> 12:26.020
I don't have to go through this very complicated flow, which you'll see here is a network diagram of what does the Reddit ingress stack look like.

12:26.400 --> 12:30.860
I can make that decision early on and save me a bunch of money.

12:31.260 --> 12:33.400
Or I can do it at the application layer.

12:33.560 --> 12:35.440
Maybe I need it to be more expensive.

12:35.440 --> 12:37.740
Maybe I need to have that additional app context.

12:37.740 --> 12:39.240
And that's where it makes sense.

12:39.520 --> 12:41.340
Essentially, you always have to use both.

12:41.340 --> 12:46.120
But thinking, being able to have that architectural pattern of, okay, here's how I'm doing this at the edge.

12:46.120 --> 12:47.300
Here's how I'm doing at the app.

12:47.300 --> 12:50.720
Extremely important so that you understand how good your defenses are.

12:50.720 --> 12:51.620
Again, like defense in depth.

12:51.620 --> 12:53.000
This is just defense in depth.

12:54.980 --> 12:57.700
Okay, so we said we're going to do both.

12:57.920 --> 13:01.800
We need to store essentially that data in some sort of KV.

13:02.000 --> 13:06.080
Now, an edge and an app both have pros and cons around that KV structure.

13:06.320 --> 13:10.020
So, you know, you might make a decision that, okay, I want to store that data.

13:10.020 --> 13:12.000
But Fastly only gives you...

13:12.000 --> 13:13.780
So Fastly has a product called Edge Rate Limiter.

13:13.780 --> 13:15.060
We'll talk about it in a second.

13:15.060 --> 13:17.820
It gives you very, very coarse-grained access to...

13:17.820 --> 13:19.580
It actually doesn't even give you access to the KV.

13:19.580 --> 13:22.940
If you wanted to go and look to see, like, what's in there, you can't.

13:23.380 --> 13:26.580
Which is okay if you don't need that information.

13:26.580 --> 13:30.140
Reddit is really weird and we want to be able to control and have observability for everything.

13:30.140 --> 13:31.660
So we really want that.

13:32.720 --> 13:38.180
So if I need to get something that I actually can inspect or I actually can invert, I'll probably do it at the app level.

13:38.740 --> 13:41.620
Otherwise, sure, I'll stick it up in Fastly and call it a day.

13:42.400 --> 13:45.520
This also extends to, like, the ability to flush or reset that.

13:45.580 --> 13:51.260
You know, if you accidentally ban all of a particular TLS fingerprint, and we've never done this.

13:51.260 --> 13:51.960
Oh, no, we have.

13:51.960 --> 13:55.160
We do this much too often because it's hard.

13:55.160 --> 13:57.580
But you want to be able to revert that very quickly, right?

13:57.580 --> 14:05.020
So whether that is you're able to set a config variable or you're able to do an exclusion in that Edge logic, you got to figure out how you do that.

14:05.020 --> 14:09.400
Because inevitably, you will block somebody that you did not mean to.

14:09.900 --> 14:12.480
And then lastly is programmatic interactions, right?

14:12.480 --> 14:16.680
Again, along the same lines, how often do you need to interact with your KV store?

14:17.100 --> 14:18.720
Last one is a very interesting one.

14:18.720 --> 14:22.000
We're going through a process right now of what we're calling worldwide Reddit.

14:22.120 --> 14:29.100
So essentially, all of Reddit traffic, you know, if you asked us maybe a quarter ago, all of that was served out of AWS US East One.

14:29.240 --> 14:32.680
Not super great if you are literally anywhere else but on the East Coast.

14:32.680 --> 14:36.340
So if you're in India, it's going to take a long ass time for your site to load.

14:36.340 --> 14:38.720
Obviously, not a good user experience.

14:38.720 --> 14:39.840
So we want to fix that.

14:39.840 --> 14:46.380
That means we now are going to be deploying essentially serving stacks across the globe in different points of presence.

14:46.940 --> 14:48.840
But what happens about rate limiting?

14:48.840 --> 15:02.180
I now have a problem of if somebody is hitting me in Germany through a Tor exit node, and they're able to... if I'm silly about my routing, and I don't have a great consistent way that I'm saying, okay, this German traffic always needs to go to this particular pop.

15:02.220 --> 15:05.220
Maybe it's through any cast, maybe through circular hashing.

15:05.220 --> 15:08.180
There's a couple of different computer science algorithms that will give you that information.

15:08.420 --> 15:16.680
Then if I don't have that done consistently, I will lose that algorithm of I saw that traffic once, I'm incrementing a counter.

15:16.680 --> 15:18.500
I now know if I can go back and rate limit.

15:18.660 --> 15:23.460
So as you start globalizing, and again, this is a Reddit scale problem for sure.

15:24.000 --> 15:28.160
You have to figure out how do you deal with that inconsistency that might exist?

15:28.160 --> 15:30.300
Am I going to try to replicate those caches everywhere?

15:30.300 --> 15:31.560
That's expensive.

15:31.760 --> 15:33.320
Fastly does do that for us.

15:33.320 --> 15:35.320
They abstract a lot of that away.

15:35.380 --> 15:39.260
Cloudflare will also do that with KV store, or the KV workers product.

15:39.260 --> 15:41.400
That's fine, but it's something that you then have to consider.

15:41.400 --> 15:50.580
You have a time of call, time of use problem now, where if somebody's throwing a million requests a second, and it's distributing it globally, you now have a problem.

15:54.100 --> 16:00.740
Okay, and then finally, making some smart architectural principle decisions will help you in your defenses.

16:00.740 --> 16:04.320
So for Reddit, we have historically always split out.

16:04.320 --> 16:06.420
We've got one site that serves all of our server rendering.

16:06.420 --> 16:08.740
We've got one site that serves media assets.

16:08.740 --> 16:13.680
There's one domain that serves chat traffic.

16:13.680 --> 16:17.280
That makes it very easy for us to understand, okay, this is this traffic.

16:17.280 --> 16:18.200
This is the rate limits.

16:18.200 --> 16:20.340
This is how expensive those calls are.

16:20.680 --> 16:31.780
Doing that and being very, I have reasonable on the slides, being reasonable about that architecture helps you in your defense to figure out, okay, where do I want to put in those guardrails?

16:32.400 --> 16:34.160
Cache where you can.

16:34.160 --> 16:35.600
This is a computer science problem.

16:35.600 --> 16:37.980
You always want to cache it because then it's going to be cheaper.

16:38.620 --> 16:40.160
Caching Reddit is hard, though.

16:40.400 --> 16:46.840
When you load your feed, you are not getting, like, it's not the same cache or the same feed that Pratik is going to have.

16:46.840 --> 16:47.820
It's going to be different.

16:47.820 --> 16:50.720
So I can't cache that, but I can cache media assets.

16:50.820 --> 16:51.220
So great.

16:51.220 --> 16:54.060
Figuring out where you can and cannot is extremely important.

16:54.060 --> 16:55.480
It means you have to know your traffic.

16:56.200 --> 16:59.620
And then finally, this isolating workloads for a specific purpose.

16:59.620 --> 17:03.760
We'll talk about some of our resource pools as another resiliency technique in a second.

17:03.760 --> 17:13.800
But being able to say, like, this is exactly the pool of traffic where I can fan out, like, we, for example, our server-side rendering, we call it Shred It, that we have multiple pods.

17:13.940 --> 17:16.640
And we're on vanilla Kubernetes.

17:16.640 --> 17:27.060
We have multiple deployments of those pods, one that might do the login page, one that might do our post details page, one that might do chat iframe rendering.

17:27.300 --> 17:36.220
Doing that makes it very easy for us to kind of swap in and out either with the rate limits themselves or to understand the behavior of that traffic that's hitting those backend services.

17:37.420 --> 17:41.700
So on the next slide, I have a very fancy diagram that I'm not going to go into super detail.

17:41.700 --> 17:43.800
It's there from like a reference architecture standpoint.

17:43.840 --> 17:51.220
This is how we talk about the network ingress from clients all the way to backend requests and the return trip.

17:51.220 --> 17:54.400
I'll reference this as we talk about edge and application rate limiting in a second.

17:55.340 --> 17:58.040
Okay, so edge rate limiting, I kind of already talked about this a little bit.

17:58.040 --> 18:01.500
Fastly, we use their paid product, Fastly Edge Rate Limiter.

18:01.500 --> 18:02.300
It's pretty good.

18:02.300 --> 18:06.860
They give us essentially two KVs, a penalty box and a rate counter.

18:06.860 --> 18:20.040
So think of the penalty box as essentially that's the TTL for if this IP looks bad or this IP plus TLS or this whatever the combination is, it's literally a function that they provide, then we can add that value into their KV store.

18:20.040 --> 18:26.600
And it'll have a TTL that we can configure and then it'll drop out a cache whenever it's supposed to drop out.

18:26.600 --> 18:30.060
The rate counter is literally, it's the abacus of the entire thing.

18:30.060 --> 18:33.560
As we see those things happen, we're adding one to those counters.

18:33.680 --> 18:35.940
And that's the other half of that magic.

18:36.140 --> 18:38.020
There's documentation on how Fastly does it.

18:38.020 --> 18:40.820
We did not have an option to do this.

18:40.820 --> 18:43.520
We use Fastly's VCL implementation.

18:43.520 --> 18:47.260
It's not the compute product because computed edge can get a little spendy.

18:47.260 --> 18:52.020
Again, we're thinking about like cost optimization of the sheer volume of traffic that we have.

18:52.020 --> 18:56.320
And so we are doing this outside of VCL, which is our normal flow.

18:56.320 --> 18:56.880
It's fine.

18:56.880 --> 18:59.880
We're actually changing this, as we talk about the next slide.

19:00.820 --> 19:01.800
Oh, sorry.

19:01.800 --> 19:07.060
I included a very fancy picture of, okay, this is how you might do this rate limiting call in Fastly.

19:07.180 --> 19:08.720
Documentation is actually pretty good.

19:08.720 --> 19:11.120
So do go check that out if you are using Fastly.

19:11.240 --> 19:13.540
Otherwise, on the Cloudflare side, you got two options.

19:13.540 --> 19:20.700
You can be an enterprise customer and pay a boatload of money, which we weren't super interested in, or you can build it yourself in workers.

19:20.700 --> 19:25.900
So between workers and KV workers, we've essentially replicated what we have in Fastly into Cloudflare.

19:25.900 --> 19:27.740
Again, this is our like multi-CDN approach.

19:27.740 --> 19:32.320
We want to have the ability to swap in and out and do commercials and do all this jazz.

19:33.040 --> 19:37.820
Business aside, engineering principles, it's essentially we're going to replicate that functionality.

19:38.540 --> 19:42.180
And so relatively straightforward with what Cloudflare provides you.

19:42.880 --> 19:48.080
One thing that I will say is that we are extremely, extremely obsessive about the logs that come out of that.

19:48.080 --> 19:57.320
Now, if you've ever looked at a CDN log provider, the logs that come out are really terrible in terms of like the verbosity of what is going on, right?

19:57.320 --> 20:00.140
It'll give you like HP status codes and then maybe some other stuff.

20:00.140 --> 20:06.040
And that's a super, super lacking of detail for you to figure out what exactly is happening.

20:06.040 --> 20:11.320
So for us, we have customized all of our logging to say, okay, this is exactly what we want to have.

20:11.320 --> 20:13.920
We have these synthetic code and synthetic reason values.

20:13.920 --> 20:16.180
We can track why is something being rate limited?

20:16.180 --> 20:20.380
Oh, it's being rate limited on TLS fingerprint or it's being rate limited on IP plus TLS.

20:20.380 --> 20:26.600
We can see what that failure mode is rather than just here's a whole slew of 429s, go figure it out.

20:26.600 --> 20:29.380
That does not work from an engineering standpoint.

20:30.380 --> 20:36.080
So in terms of how I'm piecing all of these things together, think of it as just a series of band pass filters.

20:36.080 --> 20:40.020
I'm gonna have something extremely coarse grained at the very top that might be like IP address.

20:40.440 --> 20:44.700
If you haven't already exhausted that rate limit, then we'll bump down to the next one.

20:44.700 --> 20:46.560
Maybe it's IP plus TLS fingerprint.

20:46.660 --> 20:50.960
Maybe the next one is IP plus TLS fingerprint plus this pools word that I have here.

20:50.960 --> 20:55.180
So think about like logged out traffic, logged in traffic, third-party clients.

20:55.180 --> 21:00.260
If it's OAuth, you can group your traffic and extend the groupings that you're having there.

21:00.260 --> 21:01.500
And then finally, reCAPTCHA.

21:01.500 --> 21:08.840
So I might pay somebody else to give me some additional signal that maybe I include that as part of my rate limit.

21:09.000 --> 21:15.620
Again, as I'm moving down that stack, I am getting more narrow in the terms of how many times you can do a thing.

21:15.640 --> 21:18.900
But I'm also, the permutations are becoming more and more and more, right?

21:18.900 --> 21:20.420
So that is the trade-off.

21:20.900 --> 21:23.680
Obviously, this has super bad weaknesses.

21:23.680 --> 21:27.600
We have CGNATs, people have shared IP addresses.

21:27.940 --> 21:29.220
This is a problem.

21:29.740 --> 21:30.980
You will block people.

21:31.160 --> 21:31.800
It happens.

21:31.800 --> 21:35.840
But that's why the importance of being able to tune and understand like what are the exemptions?

21:35.840 --> 21:39.840
We have plenty of edge dictionaries that say, all right, we know that this is a Google crawler.

21:39.980 --> 21:41.700
Obviously, we don't want to block Google.

21:41.700 --> 21:42.980
So Google, you go on through.

21:42.980 --> 21:49.460
We're going to add some fingerprinting and some secret sauce to make sure that that's actually Google and not somebody impersonating.

21:49.660 --> 21:51.860
But if that's actually you, Google, then sure, go on through.

21:51.860 --> 21:52.900
We won't rate limit you.

21:52.900 --> 21:56.060
Again, all that is controlled via these edge dictionaries that are in Fastly.

21:56.060 --> 21:58.300
Or again, a KV store on the Cloudflare side.

22:00.000 --> 22:07.200
And so if I look at the edge rate limiting application, you can see some locks that I'm doing that at the edge.

22:07.200 --> 22:10.520
Those are the cheaper, but those are, again, very, very coarse grained.

22:11.120 --> 22:13.320
All right, let's talk about application rate limiting.

22:13.700 --> 22:15.720
Ooh, and we're going to go move really fast.

22:15.840 --> 22:18.420
So in terms of application rate limiting, we have a library.

22:18.420 --> 22:19.820
This is the easiest way for your devs.

22:19.820 --> 22:22.980
Don't make them think about what algorithm, how should I go and implement this?

22:23.000 --> 22:24.180
We have a baseplate library.

22:24.180 --> 22:26.100
Every single dev can use this.

22:26.100 --> 22:28.860
We have essentially one click for standing up Redis.

22:28.960 --> 22:33.380
If you need rate limiting is essentially a handful of lines of code to get something.

22:33.380 --> 22:34.620
You have a KV store.

22:34.620 --> 22:35.480
You have Redis.

22:35.480 --> 22:36.820
You now have rate limiting your app.

22:36.820 --> 22:39.960
The hardest part here is to figure out, well, what should the values be?

22:39.960 --> 22:45.640
And the general guidance is that you will always do how fast a human should be able to do this, given an order of magnitude, right?

22:45.640 --> 22:46.360
Is it 2x?

22:46.360 --> 22:47.320
Is it 10x?

22:47.320 --> 22:49.620
Pick something, but devs just need to hear that.

22:49.620 --> 22:50.340
And then they're like, all right, cool.

22:50.340 --> 22:51.200
I can dial this in.

22:51.200 --> 22:56.340
And now that it is less of a security problem and it is more of a developer experience problem, which is great.

22:57.960 --> 23:02.480
So this is the best for if I have per user or per endpoint logic.

23:02.480 --> 23:06.820
So how many times can you post in an hour or in a minute?

23:06.820 --> 23:09.800
Those are great rate limits for this because I need the context.

23:09.800 --> 23:11.580
I need to know, okay, what post are you looking at?

23:11.580 --> 23:12.520
Who are you?

23:12.520 --> 23:15.880
I need this information that only the app might actually have.

23:15.880 --> 23:17.500
Same thing for OAuth clients.

23:17.500 --> 23:24.820
We have a whole slew of OAuth clients, third party and first party that we want to say, okay, you have this quality of service through.

23:25.260 --> 23:25.420
Great.

23:25.420 --> 23:26.800
You have a thousand requests a second.

23:26.800 --> 23:28.280
Or, you know, you're not paying.

23:28.280 --> 23:30.160
So you only get 10 requests a second.

23:30.280 --> 23:31.860
All that data has to come from somewhere.

23:31.860 --> 23:34.660
I'm coming, that's coming from the application itself.

23:36.380 --> 23:38.160
The rest, I'm going to skip.

23:38.160 --> 23:40.180
So I'm on resiliency techniques.

23:40.820 --> 23:45.520
So I threw an example of like what our logging looks like from a Cloudflare or from a Fastly perspective.

23:45.600 --> 23:46.620
It's gnarly.

23:46.620 --> 23:50.800
We did a Terraform module that actually generates all this for us.

23:50.800 --> 23:54.580
You have to do JSON escaping, like it's kind of gross.

23:54.620 --> 23:57.020
But we're extracting that all to BigQuery, right?

23:57.020 --> 24:03.740
And for us, the network traffic logs are by far not even the drop in the bucket when it comes to our analytic events.

24:03.760 --> 24:08.900
So for us, this makes a lot of sense stored in BigQuery because it's cheap and we're not burning a lot of cash.

24:09.080 --> 24:12.660
And we can now do SQL queries against it to understand what's actually going on.

24:12.660 --> 24:15.680
But it requires a lot of setup for us to actually be able to use it.

24:15.680 --> 24:18.060
So you have to have observability.

24:18.060 --> 24:21.060
You have to get those custom web logs with additional enrichment.

24:21.240 --> 24:26.820
Add a UUID for each request so you understand if people are having problems, they're getting rate limited, track that back.

24:26.820 --> 24:27.800
That's pretty commonplace.

24:27.800 --> 24:31.660
Like this is a Cloudflare unique ID, the Ray ID that's on every request.

24:31.660 --> 24:32.360
Great.

24:33.120 --> 24:36.180
You might have to do that yourself, which we did in Fastly.

24:36.180 --> 24:37.760
And then we have to invest in tooling.

24:37.760 --> 24:47.340
So we literally have a Go binary that will query BigQuery using application default credentials that a user, you know, gcloud off logon.

24:48.080 --> 24:49.920
That actually will go and then query BigQuery.

24:49.920 --> 24:53.520
So it takes out that whole, like, you got to go to the console, put in some SQL, do some stuff.

24:53.520 --> 24:57.320
It's literally one CLI command to see, okay, is this request being rate limited?

24:57.320 --> 24:58.960
Why is it being rate limited, et cetera.

24:59.440 --> 25:04.300
So in terms of resiliency techniques, and we're going to speed real quick because we got two.

25:04.800 --> 25:05.440
Yeah.

25:05.440 --> 25:09.900
So the thing I will call out here, the slow lane versus well lane.

25:09.900 --> 25:17.120
This is probably the most interesting thing that I had, I saw when I came on as a security engineer, that you can have pools that can be degraded and you don't care about it.

25:17.120 --> 25:26.100
So if you can identify, oh, hey, this is from a Tor exit node, or this is from an IP that has a bad reputation, throw it to a pool that's extremely constrained and just let it die.

25:26.100 --> 25:27.520
And if it dies, no big deal.

25:27.520 --> 25:31.540
And write your SLOs that aren't going to hit against that thing dying.

25:31.540 --> 25:34.820
But they can all go and fight to see who dies fastest in that pool.

25:35.260 --> 25:36.500
I had not seen that before.

25:36.620 --> 25:38.040
We don't talk about that a whole lot.

25:38.040 --> 25:42.400
It's a great resiliency technique to say, I see you're a bad request, you go to timeout.

25:44.380 --> 25:46.420
Tar pitting and response bloat, you can check that out.

25:46.420 --> 25:52.860
We actually use badger, badger, badger as the response bloat within our VCL, which is a very Reddit-y thing, so I had to include that.

25:53.260 --> 25:55.380
But again, the idea here is to make it very easy.

25:55.380 --> 26:02.560
So if a request comes to us, it used to be like, you just hit the front page, like send a request to get the front page of Reddit, and that would cascade.

26:02.620 --> 26:06.980
So obviously, it is a bad ratio of bytes sent to me versus bytes I'm sending back.

26:06.980 --> 26:12.780
I want to make it expensive for the attacker so they have to go out wide, or they have to go out through multiple machines.

26:12.780 --> 26:16.480
Like, I want to make it the most expensive for them to come at us.

26:17.900 --> 26:19.060
All right, we're gonna wrap there.

26:19.160 --> 26:20.280
The rest of the slides are online.

26:20.280 --> 26:21.900
We'll be over here if you guys want to talk.

26:21.900 --> 26:22.480
Thanks, y'all.

