November 202454:3820.8k views

Moving from Redis to SQLite with Mike Buckbee

About

In this episode, I sit down with Mike Buckbee to dive into the nitty-gritty of web application firewalls and his journey from using Redis to SQLite in Wafris. We talk about database architecture, operational challenges, and the fascinating ways SQLite improves performance and usability in cybersecurity tools.

Transcript

Everything we said

00:02

Aaron Francis

Hello and welcome back to the Database School Podcast. Uh, my name is Aaron Francis. Today, I'm here with, uh, somebody I've known, what, goodness, it's gotta be 12 years at this point-

00:14

Mike Buckbee

Yeah

00:14

Aaron Francis

... I've known, known you.

00:14

Mike Buckbee

Eas- easily over a decade, yeah.

00:16

Aaron Francis

It's been a long, long time. So the other voice that you hear is my dear friend, Mike Buckbee. Mike and another one of my friends, um, are the co-founders of WAFris, which I'll let you explain here in a second. But-

00:29

Mike Buckbee

Sure

00:30

Aaron Francis

... uh, yeah, like, like I said, I've known Mike for more than a decade, and he recently just wrote this amazing, uh, Redis to SQLite piece that we're gonna talk about today. So Mike, do you want to introduce yourself further?

00:40

Mike Buckbee

Sure. Um, I'm a longtime developer in a lot of different frameworks and a lot of different contexts. Um, Aaron and I worked together, uh, at a former job. Uh, uh, that was a cybersecurity, public cybersecurity company. And I've done some form of cybersecurity work for even longer than I've known Aaron, so

01:01

Aaron Francis

Which is, which is saying something at this point.

01:02

Mike Buckbee

Which is saying something. And, um, you know, the latest iteration of that and sort of, you know, all of the issues I've had with all the systems I've used and built, you know, to date, I'm trying to address with, with WAFris. Um, so WAFris is a open source, um, client web application firewall. Um, and it addresses one of the big issues I have, which is there's this sort of brutal asymmetry where there's lots of script kiddies and attackers out there, and it's trivial for them to, like, write

01:33

a one-line cURL, you know, command, loop over it, and hit 1,000 sites and sort of mess with 1,000 sites. It's very hard for those 1,000 sites to deal with that. Um, and so, m- that's a good, like, sort of, I think, starting point for my philosophy for those things.

01:48

Aaron Francis

So before we go any further, can we get a spelling of WAFris for the people that are, that are gonna go look it up?

01:53

Mike Buckbee

Sure.

01:53

Aaron Francis

Can you give us the spelling and a little background maybe?

01:56

Mike Buckbee

Sure. Uh, it's WAFris, W-A-F-R-I-S, and WAF stands for web application firewall, um, which is something that is typically used by a lot of big enterprises. That's a lot of my customers for my other web application firewall product, and it's something we're trying to bring down to, to more people. The original thought was, ironically, somewhat web application firewall and Redis, and we're gonna talk about that.

02:22

But also, sort of my, my thought on naming startups and stuff is you need a unique, weird name. Um- ... partially because it's a lot easier to get the domain for it, and you don't have to do like, you know, my thing app or tries my thing now.com.

02:37

Aaron Francis

Mm-hmm.

02:38

Mike Buckbee

Um, also it gets around a lot of, like, weird trademark stuff internationally. It's just so much easier in a lot of ways. Um, yeah. No one's, no one's competing for us on SEO for WAFris, so yeah.

02:50

Aaron Francis

No, I should think not. Um, yeah, when you said, uh, when you said you were switching to SQLite, I, I joked with you on Twitter that you're gonna rename it WAFqlite, which is, you know, is, it's not-

03:03

Mike Buckbee

It, it-

03:03

Aaron Francis

... it's not better

03:03

Mike Buckbee

... it just rolls off the tongue.

03:03

Aaron Francis

It's wor- it's much worse.

03:04

Mike Buckbee

It just rolls off the tongue. Yeah.

03:06

Aaron Francis

Um, okay. So I wanna talk a little bit before we get to, uh, WAFris. Tell me a little bit about, you know, I know all of this background. Honestly, you, you got me my job. That's the thing that Mike didn't say. He's too, he's too kind to say. I got that job that I worked with Mike at because he got it for me, which was very nice of him. And so back then, what were you doing?

03:27

And then you mentioned another WAF product. Um, so give us a brief, like, cybersecurity run-through of Mike's history.

03:34

Mike Buckbee

Sure. Um, so I, I, I don't even know if you know this, but, like, back before I even had moved to Virginia or met you or anything, I actually did essentially cybersecurity consulting, um, like in a previous role. And I had a, a CISSP, which is this like certification you need to get, and you have to take a test and get people to attest that like, you know, he's actually worked in this for a long time and stuff.

03:59

Um, and I had those sort of roles, and I was always sort of doing software development on the side. Like, I didn't start off doing software development. I mean, similar to you. You started as a CPA and then got into software development. Um, and then from there, just more and more software development, and really got into, you know, some marketing things. So at Varonis, was our old company, I was the director of demand generation, which is doing a lot of the, the marketing pieces for content writing and for ads and stuff.

04:28

And that evolved over time as they grew. Um, I had joined them pre-IPO. And then, um, as a side project, I had started Expedited SSL in the Heroku Salesforce ecosystem, which did certificate installation. And then later on, I had started Expedited WAF, which is an enterprise web application firewall that's in that ecosystem.

04:49

And, um, again, just a lot of, a lot of issues with it and a lot of frustration that due to sort of how it's designed, it can't be a default. It can't be something that just every app just has. A- and again, the frustrations are it's really easy to look in your logs of any application and find like all these IP addresses that are like, "Oh, I really wish they weren't doing that." Maybe it's not actively harming me, but it's not great to have this bot looking for .env files in every directory in my machine.

05:19

Aaron Francis

Right.

05:19

Mike Buckbee

It's not great for this bot to be testing like, oh, is this running Java with this exploit? And, and just like thousands and thousands of those. But there's no real good way to just go in and like click a button or say like, "I would rather not have this IP address ever make these requests again." And so that's part of what we're trying to deliver on with WAFris, so.

05:37

Aaron Francis

So before, pre-WAFris, you were strictly in the Heroku ecosystem.

05:43

Mike Buckbee

Yes.

05:43

Aaron Francis

And you were finding... Was it the platform integration points that you were finding difficult, like just the stuff they gave to you? Or why, why did you decide to break out of the Heroku ecosystem? Hey, I hope you're enjoying this. Just as a reminder, you can learn more about SQLite at highperformancesqlite.com. I'll get out of your way. Back to the interview.

06:06

Mike Buckbee

I think the Heroku ecosystem and what we had was, was really good. And can, and still, I still have, I think, nearly 1,000 customers, uh, over there. And I think what it more is, is that, um, it... The, the cost structure of it, because it works as a traditional, um, web application firewall through DNSs and proxy systems, and it's not something built into the application, there's, um, you know, there's

06:36

side effects to that architectural decision, just like everything.

06:39

Aaron Francis

Mm-hmm.

06:40

Mike Buckbee

One of those is that it's very hard to bring the cost down on that because of it, and the other one is it's very separate from your application, and there's a lot of sort of issues there. And the mix of that results then in behaviors that only enterprises or people that are almost forced, uh, to buy it, buy it.

07:02

Uh, so it's a lot of startups that are like, "Oh, we're gonna integrate with an insurance company. We're gonna integrate with a-

07:07

Aaron Francis

Oh, I see

07:08

Mike Buckbee

... a bank." And the bank or the insurer is like, "Great, fill out this PDF checklist." And like one of them is like, "Do you have a web application firewall?" And so there's a lot of resistance from developers like, "Does this actually do anything for me? Does this do stuff?" And I know you've heard this. I have like unending amounts of stories of like, "Yeah, I got on a call with this person and their site was messed up, and they had all these issues because they were under attack.

07:31

And so we turned it on and made some settings, and it stopped the attack." And so the, the web application firewall, I feel like picks up on the operational security issues that are outside of the framework. So Laravel, Rails, Express, all of these are made by brilliant people that have an eye towards security and take great pains to make sure you're developing that application well.

07:56

But depending upon how you deploy it, you know, the, the web server that, the, uh, actual HTTP server that's in front of it, um, it may have issues that you can't deal with out of the framework. It, it's still difficult to deal with like rate limiting issues. Um, I know Rails and Laravel and Express all have built-in rate limiting now.

08:19

Aaron Francis

Mm-hmm.

08:19

Mike Buckbee

But even with that, you still have issues of like, well, the, an actual attacker who's doing a credential stuffing attack, which is just pumping thousands of usernames and passwords into your system, they're rotating IP addresses, so it's trivial for them to get 1,000 IP addresses. So even though you have a rate limit of like, oh, well, five attempts per hour, that's still 5,000, you know, attempts per hour.

08:43

That's not great. That's a hard thing to tell your boss like, "Yeah, I fixed it. Only 5,000, you know, crazy bot attempts an hour on our, our login." So you need this other set of tools to help you stop those sort of attacks to prevent them, and-

08:58

Aaron Francis

Mm-hmm

08:59

Mike Buckbee

... that's, that's what we're trying to provide with Wafers, so.

09:02

Aaron Francis

And so the, the architecture, why don't we do the architecture of Wafers before you switched to SQLite and some of the... 'Cause y'all have some pretty unique constraints based on where you sit in the stack. Because I think where you sit in the stack is you sit between every, literally every single request-

09:22

Mike Buckbee

Mm-hmm

09:22

Aaron Francis

... and the application in which Wafers is installed. So it's a pretty, it's a pretty hot path. It's a pretty brutal-

09:29

Mike Buckbee

Mm-hmm

09:29

Aaron Francis

... place to be, honestly. It sounds a little bit stressful.

09:33

Mike Buckbee

Yeah.

09:33

Aaron Francis

So talk to me about the, uh, the architecture and how Wafers even works such that you're allowed to be and want to be in the middle of every single request.

09:44

Mike Buckbee

Sure. Um, so part of what we have, uh, I, I guess there's, there's two sides to it. There's, uh, a server configuration management side, and there is a client piece of this. And so, um, we refer to the server management side as Hub.

10:04

Aaron Francis

Okay.

10:04

Mike Buckbee

So on Wafers Hub, you can go-

10:05

Aaron Francis

And the s- when you say server, you mean your server? The-

10:08

Mike Buckbee

Yes. Maybe a better term-

10:09

Aaron Francis

Okay

10:09

Mike Buckbee

... is service. There's a server.

10:11

Aaron Francis

Got it. Okay. Hosted.

10:11

Mike Buckbee

We, we run, we run this management service, and partially, again, I'm talking about like all the issues I found. So a very typical thing is I will talk to people, and what they will have is they will have a web application firewall, they will have their application, their, you know, Rails or Laravel app, and then they'll have a separate logging service. And to deal with anything, they have to jump between those, and they just-

10:35

Aaron Francis

Mm-hmm

10:35

Mike Buckbee

... literally are copying and pasting. They're going into, um, their logs, extracting out a bunch of logs. They're, maybe they're pumping them into like an Elasticsearch cluster, and they're doing grouping on IPs, and-

10:48

Aaron Francis

Hmm

10:48

Mike Buckbee

... that is just a rough way to live. And it's really hard to be dynamic and like... So we're trying to take all of that and make that loop really tight, that feedback loop, and have it live on Hub. So one of the first things you see when you log into Hub and you have the system up and going is just a list of here's the top 10 IP addresses making requests to your site over the last 24 hours and how many requests.

11:13

Aaron Francis

Hmm.

11:13

Mike Buckbee

Now, that is not a complicated thing to, to conceive of. Oh yeah, w- just how many requests. That is a difficult thing for most developers to pull out of their systems, which is just... A- and it shouldn't be. It, it's, it, and it feels like if we were starting today, like designing all these systems-

11:30

Aaron Francis

Mm-hmm

11:30

Mike Buckbee

... we would have a system where it's easy to get that out. And so that's, that's really what Hub is. And then I think it's a very, you know, clear path to see like, oh gosh, we don't do any business with, you know, Indonesia or Canada or Finland, but this IP address is our number one requester.

11:50

Aaron Francis

Mm-hmm.

11:51

Mike Buckbee

And that is not uncommon. Like I have, I talked to a company that was doing essentially like internal HR software, that if you had an attack, like if something happened, you could report it in the company, it was anonymous to this outside thing.

12:03

Aaron Francis

Mm-hmm.

12:03

Mike Buckbee

And they found out only doing business in the US, the majority of the requests to their website were actually from China

12:11

Aaron Francis

Not great

12:11

Mike Buckbee

... n- not great. And nothing against China or these other countries, but it just doesn't make sense.

12:17

Aaron Francis

Yeah.

12:18

Mike Buckbee

It just doesn't make sense. Um, yeah. So that's what Hub is. And so then you can block that IP address, and that gets communicated down to the clients. And so the client is a middleware that lives in Laravel or lives in Rails.

12:31

Aaron Francis

Hm.

12:31

Mike Buckbee

Or somewhat complicating things is it could also live in Caddy, it could also live in Traefik-

12:39

Aaron Francis

Oh

12:39

Mike Buckbee

... which is an ingress controller. It could also live in NGINX because we do-

12:43

Aaron Francis

That's cool

12:44

Mike Buckbee

... so, yeah, so we can live at these different-

12:46

Aaron Francis

So it could, it could live as a middleware in Laravel in co- in code, so it hits the Laravel application and then starts-

12:53

Mike Buckbee

Mm-hmm

12:53

Aaron Francis

... through the middleware stack and it hits the WAF first middleware.

12:56

Mike Buckbee

Yep.

12:56

Aaron Francis

Or you could build it in as, what do they call them in Caddy? Is it modules?

13:00

Mike Buckbee

Yeah.

13:00

Aaron Francis

In NGINX it's modules, right? Okay. So you could build it into one of those two and it never hits your application at all?

13:05

Mike Buckbee

Yep. So we have-

13:06

Aaron Francis

Ah.

13:07

Mike Buckbee

And-

13:07

Aaron Francis

Okay

13:08

Mike Buckbee

... so, and we have this functional. We have a functional, and this is, and we'll get to V1 and V2, but we have this functioning right now with Redis-

13:16

Aaron Francis

Okay

13:16

Mike Buckbee

... which is what we describe as our V1. This work-

13:18

Aaron Francis

As your data store on the client.

13:20

Mike Buckbee

Yeah. And so the issue is that we have, say, I know you're most familiar with Laravel.

13:26

Aaron Francis

Mm-hmm.

13:26

Mike Buckbee

So you have Laravel, and then you have your Laravel set up, and then next to it, you know, you have your Redis instance-

13:33

Aaron Francis

Okay

13:33

Mike Buckbee

... that you've set up. We need access from Hub to that Redis instance basically to write these rules. And so then-

13:41

Aaron Francis

Oh, you need access from the outside world.

13:44

Mike Buckbee

Yeah.

13:44

Aaron Francis

You need access from back home.

13:45

Mike Buckbee

Yes.

13:45

Aaron Francis

Got it. I think I see, I think I see where the problem lies. Keep going.

13:48

Mike Buckbee

Yeah. And so that's, that's doable in a lot of ways. Like, and that's, like, you can go into AWS, and we have a lot of-

13:57

Aaron Francis

Mm-hmm

13:57

Mike Buckbee

... people on AWS, and set the rules for that, or you can set up a different server, or you can do things, but it's not easy. It's not just-

14:05

Aaron Francis

No

14:05

Mike Buckbee

... install it. Um, and-

14:07

Aaron Francis

So if I'm understanding right, it sounds like they share, the client, the client reads out of a local data store.

14:13

Mike Buckbee

Mm-hmm.

14:14

Aaron Francis

The hub writes to what is your local data store, but to it as a remote data store.

14:20

Mike Buckbee

Yeah.

14:20

Aaron Francis

And that way when a request comes in, you're just asking your, your service right next door rather than trying to phone home to some API over the-

14:28

Mike Buckbee

Yeah

14:28

Aaron Francis

... open internet.

14:29

Mike Buckbee

Yeah.

14:29

Aaron Francis

Which sounds like a nightmare.

14:30

Mike Buckbee

Exactly. And the constraint there was it's the hot path, that every request to your web application-

14:35

Aaron Francis

Mm-hmm

14:35

Mike Buckbee

... needs to be evaluated on the rules. And-

14:38

Aaron Francis

Yeah

14:38

Mike Buckbee

... I always think of, like, should this IP address be blocked? Like, that's the easiest-

14:42

Aaron Francis

Right

14:42

Mike Buckbee

... rule to think of. Like, so we have to check something that says whether this IP address should be blocked.

14:46

Aaron Francis

Mm-hmm.

14:47

Mike Buckbee

And something like, and this is, again, the people I talk to, it, it's easy enough to think, like, I can go in and I'm gonna write my own constraint in the framework that's gonna block this.

14:57

Aaron Francis

Sure.

14:57

Mike Buckbee

Or I'm gonna set this as, like, an environment variable or something I can update. And then I see those systems get out of hand, where literally talked to a customer and they had three quarters of a million IP addresses in their own homegrown system that they were-

15:11

Aaron Francis

Just in a big list.

15:14

Mike Buckbee

Not great. Not great. Um-

15:15

Aaron Francis

Not great.

15:18

Mike Buckbee

So, and you know, no, no way to manage those. Like, in Rails, it's Rack Attack is something that's used a lot, and you can go in and you can put, you know, exactly that, and it, and it works, but there's, there's functional limits to it. You don't have the feedback loop. You have to... So anyway, so that's V1, is these middleware clients and HTTP servers and ingress controllers and frameworks that we're connecting to, to the application, a local Redis, and to Hub, a remote, um, Redis instance.

15:48

Aaron Francis

Mm-hmm.

15:49

Mike Buckbee

And for the reasons you said, the, it, it doesn't work. Like, it's, it's hard to get going. Um, we found, um, I think the phrase I use in the article is, um, we shouldn't make, um, people that are just trying to get this installed, we shouldn't casually make them Redis database admins.

16:06

Aaron Francis

Mm-hmm.

16:06

Mike Buckbee

Like, that's not something people wanna bring onto themselves.

16:10

Aaron Francis

Yep.

16:10

Mike Buckbee

So all of that, um, coalesced around we need a, a better way to do this, and what we turned to was SQLite. And with that same sort of set of constraints, we then had to do this big rearchitecture to move pieces around and to think about things differently, and to make them-

16:25

Aaron Francis

Mm-hmm

16:25

Mike Buckbee

... work with SQLite in, um, I think a fairly unique way because we have sort of unique constraints on this. So...

16:31

Aaron Francis

So I wanna talk about this from maybe two different approaches, which is, like, the operational, uh, flexibility or benefits that you got out of SQLite, and then maybe, like, the structural, uh, the data structure and performance benefits. But first, before we do that, how did, how was this all stored? 'Cause I imagine what you're storing is IP addresses or, um, ranges or something like that.

16:58

How was this all stored in Redis? Because I know they have some specialized data structures for this kind of thing.

17:04

Mike Buckbee

Yeah. So, um, you said it was okay to get real nerdy with this stuff, so-

17:09

Aaron Francis

Please

17:09

Mike Buckbee

... we're about to, we're about to take that, that dive.

17:11

Aaron Francis

Yep.

17:12

Mike Buckbee

Um, so there's two kinds of IP addresses. There's IPv4 and IPv6. And something we do a lot of in the application is l- look at CIDR ranges. So CIDR ranges are just, like, a start and a stop, um, IP address, and we need to represent those, um, in such a way that we treat them almost as a key, that if you're between this range, you know, that means that this IP address is in this country, or if you're

17:42

in this range, it means that you are part of this reputationally bad IP group-

17:48

Aaron Francis

Mm-hmm

17:48

Mike Buckbee

... and we need to get rid of you. Or it's a custom block that you have decided that, like, oh, we don't wanna have any traffic coming from this provider or this country, or the opposite, which is that, oh, we do want to allow all of our internal traffic or all the traffic from our headquarters.

18:08

Aaron Francis

Oh.

18:08

Mike Buckbee

And so for a single HTTP request- We have to hit four different sets of these ranges to check them all in worst case scenario, because you have to go, that's just what you have to do.

18:23

Aaron Francis

Mm-hmm.

18:23

Mike Buckbee

So this is like our most arduous set of queries is checking these ranges. Um-

18:30

Aaron Francis

It's checking these ranges because it's not necessarily a strict equality, it's checking to see if a, uh, if an IP address is contained within any set-

18:41

Mike Buckbee

Right

18:41

Aaron Francis

... of range. Got it. Okay.

18:42

Mike Buckbee

So before we started this, I was gonna ask you, so g- given that I figure you're a l- far ahead of me with the database structure stuff, how would you have structured this? Um-

18:52

Aaron Francis

See, but here's where I'm far, far behind you on, and it's the network stuff.

18:58

Mike Buckbee

Yeah.

18:58

Aaron Francis

And so when we're talking about CIDR ranges, vaguely in my head I see a slash 24, but like I don't know if that's super right. Like is that a CIDR range when you-

19:07

Mike Buckbee

Yeah

19:07

Aaron Francis

... do it that way? Okay. So I know that, um, I know that in MySQL and Postgres, they have specific data types for IPs, and I think Postgres has it for ranges. I don't know. I forget if MySQL has it for ranges or not. Um, but how would I do that? Um, goodness, probably I would ...

19:32

Oh, man. I know they can be converted to integers as well, so I might store the start and end as an integer. I don't know. I have no-

19:41

Mike Buckbee

Yeah

19:42

Aaron Francis

... idea. I know with, um, Postgres you could do some sort of like just overlapping thing and see if a point is contained within a range, but I have no idea how performant that is. So I don't know.

19:54

Mike Buckbee

Th- so everything you said is something I've tried. So I've tried- Um, tried storing these as integers.

20:01

Aaron Francis

Uh-huh.

20:01

Mike Buckbee

And there's a lot of like weird, um, I'm just gonna refer to it as bit fiddly stuff you can do-

20:06

Aaron Francis

Ah, yep

20:06

Mike Buckbee

... with it.

20:07

Aaron Francis

Mm-hmm.

20:07

Mike Buckbee

Um, so, uh, and for Redis at least, there is not, to my knowledge, a, a range sort of operator.

20:16

Aaron Francis

Mm-hmm.

20:17

Mike Buckbee

So there's not a special data type for that. Um, another complication here is you are absolutely correct. You can take an IP address and a range and get the, the first and last IP address out of that range-

20:29

Aaron Francis

Mm-hmm

20:29

Mike Buckbee

... and then you can convert those to integers. Seems very straightforward.

20:33

Aaron Francis

Good so far. Mm-hmm.

20:34

Mike Buckbee

That only works for IPv4. If you want to support-

20:37

Aaron Francis

Oh

20:38

Mike Buckbee

... IPv6-

20:39

Aaron Francis

Two

20:39

Mike Buckbee

... IPv6 is so huge that-

20:41

Aaron Francis

Yep

20:41

Mike Buckbee

... um, the integers are larger than a big int. They're larger than can be represented as an integer in your system.

20:47

Aaron Francis

Nothing should be larger than a big int. Um, okay. Yeah, that makes sense. I didn't think about that.

20:52

Mike Buckbee

Yeah. And so a- again, in trying to optimize this, we also didn't, i- ideally we didn't wanna have two structures. We didn't wanna have like an IPv4 lookup-

21:02

Aaron Francis

Sure

21:02

Mike Buckbee

... and then an IPv6 lookup.

21:04

Aaron Francis

Yeah.

21:05

Mike Buckbee

And this is a fun fact. Um, most of the systems that actually do the translation of an IPv6 into an integer, they cheat. They don't do the actual math on it. They do some like weird set of heuristics and regexes and math in order to have a more performant. So if you use like an IP adder, you know.

21:27

Aaron Francis

Really?

21:28

Mike Buckbee

Yeah. 'Cause it, again, it's just ridiculous, um, how, how big these numbers are. So-

21:34

Aaron Francis

Interesting

21:35

Mike Buckbee

... so in Redis, um, what we settled on was, um, using a sorted set.

21:42

Aaron Francis

Okay.

21:42

Mike Buckbee

Now, a sorted set is, um, usually used for a leaderboard.

21:46

Aaron Francis

Mm-hmm.

21:46

Mike Buckbee

So you have essentially a key and then you have a score, and so this works out great that you can have like, oh, Mike's high score is, you know, 1,000, Aaron's is 1,001, and then like you do something in the game and it increments them varying. And all of those operations are really fast, and it's really fast to get out like a chunk of it to say like-

22:05

Aaron Francis

Mm

22:05

Mike Buckbee

... "Oh, Mike is at this spot, and we'll get the 10 above and the 10 below."

22:09

Aaron Francis

Okay.

22:10

Mike Buckbee

And you can imagine like, you know, paging through a high score list for that.

22:14

Aaron Francis

Mm-hmm.

22:15

Mike Buckbee

Um, what we discovered was if you set all the scores to zero, to the same value- ... it forces Redis to use lexical-

22:26

Aaron Francis

Mm

22:26

Mike Buckbee

... indexing for this, which basically it treats it like, like it's an alphabet. So it goes, you know. And to do the search through it, you know, it looks for the first column and the second and the third and the fourth.

22:36

Aaron Francis

It sorts, then it sorts on the keys instead of the values if they're all set to zero?

22:41

Mike Buckbee

Yep.

22:42

Aaron Francis

Okay.

22:43

Mike Buckbee

So, so-

22:44

Aaron Francis

This is absurd and I love it already. Keep going.

22:46

Mike Buckbee

Yeah. So-

22:47

Aaron Francis

So what do you, so what did y'all ... Okay, keep going. Keep going.

22:49

Mike Buckbee

So, so this, this is just the, the basis of this.

22:52

Aaron Francis

Mm-hmm.

22:52

Mike Buckbee

And so then, um, what we did was we took the first and the last, um, uh, IP address out of the range-

23:00

Aaron Francis

Mm-hmm

23:00

Mike Buckbee

... 'cause we can calculate that.

23:02

Aaron Francis

Mm-hmm.

23:03

Mike Buckbee

Turn them into an integer. Zero pad it so all of the columns are the same length.

23:09

Aaron Francis

Oh, 'cause you're sorting alphabetically, not numerically.

23:11

Mike Buckbee

Yes. Alphabetically. Lexically.

23:14

Aaron Francis

Fake, fake alphabetically. Yeah.

23:16

Mike Buckbee

Fake alphabetically. And so, uh, and then that's not enough 'cause now you just have this series of numbers, but you don't know if you just look at any two of them in there, like is this the, the first and the last in this? And also-

23:30

Aaron Francis

Oh

23:30

Mike Buckbee

... 'cause it's almost like, it's almost like ideally like in your, in my heart of hearts what I'd love is almost like a hash-

23:38

Aaron Francis

Sure

23:38

Mike Buckbee

... or a dictionary where the key is a range and then the value is a single value, but-

23:44

Aaron Francis

Mm-hmm

23:44

Mike Buckbee

... of course we don't have that. So then what we do is we append onto this, um, essentially a code that says like what rule ID it's for or what country it's for or whatever else.

23:54

Aaron Francis

Oh, geez.

23:55

Mike Buckbee

And so we have two entries for each of these. So what you do is you look up, um, so you do ... And remember I said earlier you can do a sorted set and you can then look up like the 10 above and the 10 below.

24:05

Aaron Francis

Sure. Mm-hmm.

24:07

Mike Buckbee

So we look, and we do a lookup, and we find the one above and the one below the value that we're looking for.

24:14

Aaron Francis

Hmm

24:15

Mike Buckbee

And so then we take those and we strip off, um, the end code on them

24:19

Aaron Francis

Your little secret code at the end

24:21

Mike Buckbee

Y- and if it's the same on both, we know it's within that range.

24:25

Aaron Francis

Okay.

24:26

Mike Buckbee

And this works. And so this, this satisfies the requirements-

24:30

Aaron Francis

That's insane

24:30

Mike Buckbee

... of a single, um, data object-

24:34

Aaron Francis

Right

24:34

Mike Buckbee

... that's in Redis that works for IPv4, it works for IPv6 ranges, and we can do one lookup on this. We can do- we can store keys, and that it's very performant. And, you know, we're gonna talk about the article and the switch to SQLite and the speed difference. This really wasn't about that speed difference.

24:56

I mean, like, that's great, we're getting a, a better speed difference out of it.

24:59

Aaron Francis

Sure.

25:00

Mike Buckbee

You know? SQLite, but this was n- never really the bottleneck for this, like, this architecture. Um, so it, it checks-

25:09

Aaron Francis

So the lexicographical sort thing, it worked.

25:11

Mike Buckbee

Oh, yeah.

25:11

Aaron Francis

It totally worked.

25:13

Mike Buckbee

It totally, it totally wor- it took forever to figure out. We refer to it affectionately-

25:16

Aaron Francis

How many, how many things do you think you went through between, uh, you know, the INET masks and the integers and other... Like, how many, how many iterations did it take to land on this insane setup?

25:29

Mike Buckbee

Oh, s- s- so many. Also, there's a whole other thing where we, we taught ourselves Lua, because this is all done-

25:34

Aaron Francis

Yeah

25:34

Mike Buckbee

... not in, not in any language anyone else uses except for Roblox developers.

25:39

Aaron Francis

Of course.

25:40

Mike Buckbee

Um-

25:40

Aaron Francis

Redis and Roblox. That, that makes sense.

25:42

Mike Buckbee

Yeah. So, um, this is essentially in a stored procedure that happens-

25:46

Aaron Francis

Mm-hmm

25:46

Mike Buckbee

... inside of Redis. And so we would take the request, package it up a certain way, send it to Redis, a- along with the script, and the script would actually do all of this stuff-

25:56

Aaron Francis

Hmm

25:56

Mike Buckbee

... to like, you know, peel it apart and stuff. Not, not... A- and it all worked. Like, this was not the problem. The problem, the problem was-

26:05

Aaron Francis

I was gonna say, not great

26:06

Mike Buckbee

... people couldn't install Redis properly after this because it's, it's not their, it's not what they do.

26:12

Aaron Francis

Sure.

26:12

Mike Buckbee

So yeah. So, um-

26:16

Aaron Francis

So you've, you've got it working in Redis.

26:19

Mike Buckbee

Mm-hmm.

26:19

Aaron Francis

The data structure is wild, but genius. But you're hitting operational roadblocks 'cause people are like, "You want me to do what to do what? I just want to block an IP address."

26:29

Mike Buckbee

Yeah.

26:29

Aaron Francis

And so that from a, I guess, technical, but more from a business perspective, that was like, "This is not workable. We can't keep asking people to install Redis and them say no and not ever, you know-

26:41

Mike Buckbee

Yeah

26:41

Aaron Francis

... sign up."

26:42

Mike Buckbee

Yeah.

26:42

Aaron Francis

So what happens next?

26:44

Mike Buckbee

So what happens next is, you know, Ryan, my co-founder, and I make the decision that we need, we need something different. And a lot of this was also driven by, um, uh, I think changes that we did not initially identify in the market, which is that everything is becoming more distributed.

27:00

Aaron Francis

Mm-hmm.

27:00

Mike Buckbee

Everything is becoming multi-region. Everything is... You know, that's just the standard for how apps are deployed in a way that I didn't really internalize, you know? And so that was the other piece of this. Everything I said is true about the difficulties installing Redis, but we also had the difficulties then of like, oh, well, if you're trying to operate in both, you know, in a, a data center in Ireland and one in US East, well, now you have a transatlantic lag, you know?

27:27

And, and, and you don't have one singular source of Redis, and you could do like crazy stuff, like make followers and things. Again, no one wants to be a Redis database admin.

27:36

Aaron Francis

I see. So now you're managing a Redis cluster.

27:39

Mike Buckbee

Yes.

27:39

Aaron Francis

Yeah.

27:39

Mike Buckbee

Or, or, or, or this other architecture. Again, too much for, for people to deal with. Um, so decide on SQLite. And, um, in order to do this, uh, of course, you know, we have to go through the same, the same machinations. And-

27:56

Aaron Francis

Mm-hmm

27:56

Mike Buckbee

... so, um, even just to test this, like will SQLite work? A- and the way we conceptualize this is there's two halves of what we do. There's essentially like a read half, which is reading out the rules from the data store, whatever it is.

28:10

Aaron Francis

That's local to local, right?

28:12

Mike Buckbee

Yeah. But e-

28:12

Aaron Francis

Yeah

28:12

Mike Buckbee

... and e- even just in the abstract, you know, like from a top level design document, we have to read the rules out and then we have to report on them like what we did. Like, did we block this request? Did we allow it?

28:23

Aaron Francis

Okay.

28:23

Mike Buckbee

You know? And that's sort of the right, you know, quote, unquote. If you're listening to this, I'm making little bunny finger quotes. Um, but yeah. So, um, that's where we were. And so I made this testing harness because then I had to re-implement, like, well, I know what the best way to do these ranges is in Redis.

28:43

Aaron Francis

Mm-hmm.

28:43

Mike Buckbee

Now we have to reinvent that for, for SQLite. And luckily, it turned out the most performant way to do that was the same thing. So we've actually-

28:52

Aaron Francis

Oh, wow

28:53

Mike Buckbee

... implemented basically the same thing in SQLite. And um, you know, we have a bunch of developer friends. I nerd sniped, I think, half a dozen of them-

29:02

Aaron Francis

I think you did, yeah

29:03

Mike Buckbee

... into like, "This is the best way I can figure it. Can you do something better?" And had like a little bit of test code, and everyone else tried it, and they couldn't come up with something faster, so.

29:13

Aaron Francis

I, I think I tried it, too. I think I tried it the first time around as well, and was like, "I have no idea what's going on here. I don't, I don't understand."

29:20

Mike Buckbee

Yeah.

29:20

Aaron Francis

Yeah, I remember. And if you're not familiar with nerd sniping, it's exactly what Mike just described, where it's like you give a nerd something and you're like, "Hey, I don't know. This is the best I could do." And they're like, "Ah, well, let me take a look." And then they wander back six hours later having taken a look. That's exactly what happened to everyone when you presented this problem.

29:39

Mike Buckbee

Yeah. And if, if, if I'm nerd sniping people here on this, and you have a better way to do this, this is, this is open source. Like, you can actually go to like, you know, our repos for the clients and implement this.

29:50

Aaron Francis

That is gonna be so interesting if somebody's like- ... "No, I've done this before, and it's this other weird thing."

29:57

Mike Buckbee

I would love that. So, but, uh, yeah, no. Or reach out to me on Twitter or whatever. I would love to talk to whoever can do this better, um, 'cause it's, it's such a cool problem.

30:07

Aaron Francis

So SQLite, SQLite famously very, very few types, and so you're shoving all this into what? Just a-

30:14

Mike Buckbee

A table

30:14

Aaron Francis

... a table with a, what, what, what's the column structure? You've got the lexicographical ranges again that are just strings.

30:23

Mike Buckbee

Yep.

30:24

Aaron Francis

And then you have a... I guess you don't even need a value at that point, 'cause you were zeroing them all out, so it's just a big old table of-

30:31

Mike Buckbee

So I think-

30:31

Aaron Francis

... strings

30:31

Mike Buckbee

... I think, I think we got extravagant and we used two fields, so two columns.

30:35

Aaron Francis

Oh, wow.

30:36

Mike Buckbee

You know? So-

30:37

Aaron Francis

Somebody was, somebody was feeling wealthy that day.

30:40

Mike Buckbee

Yeah.

30:40

Aaron Francis

Two-column table.

30:41

Mike Buckbee

Yeah. So I, and 'cause it- it's, I think instead of having to put the code into the string, we actually just have it as a second column.

30:49

Aaron Francis

Yeah. I g- I guess that makes sense. When you're not restricted to key value, you don't have to shove everything into a single string.

30:55

Mike Buckbee

Yeah. So two columns. So-

30:57

Aaron Francis

Okay

30:57

Mike Buckbee

... living the life. And of course, that's indexed, and it works the same way. So we do-

31:01

Aaron Francis

Mm-hmm

31:01

Mike Buckbee

... a look up, find the one above, find the one below, see if the, the field in the second column matches, and if it does, then it's in that range and we know what that is.

31:10

Aaron Francis

Okay.

31:11

Mike Buckbee

Um, so that's, that's where we're at. Now, this has a whole different deployment model and everything else.

31:18

Aaron Francis

Right.

31:19

Mike Buckbee

And, and this is really what the article gets into is some of that. And so there's sort of that, and then there's also the performance stuff. Um, I don't know what you wanna talk about first or, like, what makes sense, but...

31:29

Aaron Francis

Let's switch, uh, let's switch to the operational side, so the deployment stuff, because, um, I'm curious how, I guess... Well, we're about to find out, but the whole, like, phone home and update thing might be a little bit different given the unique nature of SQLite. So let's switch to deployment and tell us how that changed.

31:49

Mike Buckbee

Sure. So, um, I had said before in the abstract we're doing, like, a read step and a write step.

31:54

Aaron Francis

Mm-hmm.

31:55

Mike Buckbee

So let's just talk about the read, 'cause what we ended up doing was using SQLite only in read-only, um, which gives us big speed improvements.

32:04

Aaron Francis

Mm-hmm.

32:05

Mike Buckbee

And what we have happening is that the middleware or the Waffrs client in whatever environment it's working on, uh, we developed what we call, like, an up-sync and a down-sync, um-

32:15

Aaron Francis

Hmm

32:16

Mike Buckbee

... systems. And so the down-sync, um, takes, you know, an API key and pulls down, uh, the latest database that you have, and it does this from the client reaching out to hub instead of-

32:29

Aaron Francis

Okay

32:29

Mike Buckbee

... hub trying to push stuff in.

32:31

Aaron Francis

Okay.

32:31

Mike Buckbee

This works much better for deployment because-

32:34

Aaron Francis

Mm

32:34

Mike Buckbee

... and from an, from the user experience side now, this has gotten much, much more successful. We have many more people able to actually successfully install this-

32:46

Aaron Francis

Mm

32:46

Mike Buckbee

... 'cause, you know, they update Composer, they update their Gemfile, whatever, run this, and it just works. I mean-

32:53

Aaron Francis

Mm-hmm

32:53

Mike Buckbee

... that's the goal is it just works. And so what just works in the background is that there's a bunch of, you know, um, levers for how often this happens, but, you know, every so many requests, every so often, it goes out and it just checks, "Hey, is there a new database from hub? Any new updates on the rules? Nope? Okay. Gonna check." And it just does that, and when it finds there is an update, it pulls down, um, the database from, you know, essentially S3, you know?

33:22

Aaron Francis

Mm-hmm.

33:22

Mike Buckbee

Uh, and writes a new SQLite database, and then we update, uh, a pointer that says like, "Oh, here's the new database." So there's never any lock contention.

33:31

Aaron Francis

Oh.

33:31

Mike Buckbee

We don't do differential updates, because these are essentially pretty small.

33:36

Aaron Francis

Mm.

33:36

Mike Buckbee

And, um, all of the reads can happen, you know, like, in a rollover state. So even as-

33:42

Aaron Francis

Right

33:43

Mike Buckbee

... like, you're updating this new SQLite database file, you can still have requests rolling through on the old one until it gets the new one, and then it just flips over. So, um-

33:51

Aaron Francis

Okay. This is interesting. Tell me, um... So you have a client. You have a middleware.

33:58

Mike Buckbee

Yep.

33:58

Aaron Francis

Let's say, for the sake of example, uh, it's in Caddy.

34:03

Mike Buckbee

Okay.

34:03

Aaron Francis

And so the, I don't know, millionth request comes in, 100,000th request comes in, and the Caddy module, the Waffrs Caddy module phones home and says, "Do you have a new hash or a new version number?" Whatever.

34:16

Mike Buckbee

Mm-hmm.

34:17

Aaron Francis

Uh, hub says, "Yeah, I do." Then what happens? Do you have a, like, a backgrounding... Where is the script run and by whom, and how do you distribute that script? Is it baked into the middleware?

34:30

Mike Buckbee

It's baked into the middleware.

34:32

Aaron Francis

And so in the Caddy middleware client, you have to figure out... So in every middleware client, you have to figure out, "How do I download this thing in the background while still serving requests?"

34:42

Mike Buckbee

Yeah. And-

34:43

Aaron Francis

Okay

34:44

Mike Buckbee

... and, and there's, there's ways to do that async, but even if there's not, it is like one out of a million requests. Like-

34:50

Aaron Francis

Right

34:50

Mike Buckbee

... it's gonna be, you know, slightly, slightly longer. So your, even your P99, you know, percentile 99th, you know, request-

34:57

Aaron Francis

Right

34:57

Mike Buckbee

... still stays very fast. Um, and we've done a lot of stuff as well to distribute that system, so it's, you know, globally distributed, you know, databases, so it's all very fast. Um, yeah. And that, just that piece, the sync architecture of distributing these databases works-

35:19

Aaron Francis

Mm-hmm

35:19

Mike Buckbee

... really well. And this is, this is an exciting thing for me, 'cause I had never really... I've n- I haven't seen this concept too much in the web development side of things.

35:27

Aaron Francis

Mm-hmm.

35:28

Mike Buckbee

But, um, on the mobile side, this is how those developers live, which is like-

35:33

Aaron Francis

Yeah

35:33

Mike Buckbee

... "Oh, I updated Candy Crush." What that means is you downloaded some new JPEGs and you downloaded a new SQLite database of, like-

35:39

Aaron Francis

Yeah.

35:40

Mike Buckbee

... how much each piece of candy is worth.

35:41

Aaron Francis

It has a new JSON string with the level in it, yeah.

35:44

Mike Buckbee

Yeah. Well, and I think it really is the case that, like, uh, from a, from a database nerd perspective, I think it's really neat that you can take, instead of distributing JSON, you can distribute SQLite.

35:58

Aaron Francis

Mm-hmm.

35:59

Mike Buckbee

And that, and w- because we also looked at that. Like, this needs to run everywhere. It is a bunch of rules. It's not that many rules. It's not hundreds of millions.

36:09

Aaron Francis

Mm-hmm.

36:10

Mike Buckbee

So we could have... A- and we could have sent this out in JSON, and then we could have added indexes to it, and then we could have reinvented SQLite.

36:17

Aaron Francis

You've ha-

36:17

Mike Buckbee

And so-

36:18

Aaron Francis

You just rolled a worse version of SQLite, exactly.

36:20

Mike Buckbee

Yeah. And, and this means-

36:22

Aaron Francis

And SQLite is so universally accessible at this point-

36:25

Mike Buckbee

Yep

36:25

Aaron Francis

... that that's, like, that's probably- One of your biggest advantages of using it is you can just-

36:31

Mike Buckbee

Oh, yeah

36:31

Aaron Francis

... trust that it's everywhere.

36:33

Mike Buckbee

Yes. So, and we, it ... Trust that it's everywhere, trust that it has really good performance that's been, you know, tweaked for it.

36:41

Aaron Francis

Mm-hmm.

36:41

Mike Buckbee

And, you know, trust that it's ... They- they've thought about a lot of things that we don't have to.

36:48

Aaron Francis

Right.

36:48

Mike Buckbee

That we're building on the shoulders of giants, like the-

36:50

Aaron Francis

Mm-hmm

36:50

Mike Buckbee

... the best parts of, you know, open source. Yeah.

36:53

Aaron Francis

And so when this, uh, when this new SQLite file comes down, this is full of individual rules that have been set by the user.

37:04

Mike Buckbee

Mm.

37:04

Aaron Francis

And so everybody's getting their own SQLite file. And so on the hub side, you provide, I assume, some interface for, like, saying, "Ah, actually, yeah, block all of these-"

37:14

Mike Buckbee

Mm

37:14

Aaron Francis

... you know, Lambda IPs or whatever. And then you have a process that generates a new SQLite file and puts it into-

37:21

Mike Buckbee

Yep

37:21

Aaron Francis

... some sort of identified bucket that the client is then looking for.

37:26

Mike Buckbee

Mm.

37:26

Aaron Francis

Is that right?

37:27

Mike Buckbee

Yep. Uh-

37:27

Aaron Francis

Okay

37:28

Mike Buckbee

... it's, of course, like, the real world's a little more complicated.

37:31

Aaron Francis

Of course.

37:31

Mike Buckbee

We actually just, we actually distribute multiple SQLite files. Um, a custom rules one, which is like, I wanna block this IP, I wanna block this user agent.

37:40

Aaron Francis

Mm-hmm.

37:40

Mike Buckbee

I only want to allow, you know, these IPs. Those sort of rules. And then we have another, um, one, another database that we distribute, which we refer to as, like, our data subscriptions.

37:50

Aaron Francis

Mm-hmm.

37:50

Mike Buckbee

Which is, um, we have a ton of data about what IP addresses are doing bad things on the internet, like, right now.

37:59

Aaron Francis

Oh, cool.

37:59

Mike Buckbee

Because we have the other, you know, web application firewall service I've run for a long time.

38:05

Aaron Francis

Mm-hmm.

38:05

Mike Buckbee

So I have a ton of data from that, and there's a ton of other sources. So we take and process all of that data in this huge data jobs, reformat it, and then put it into these SQLite databases that are then distributed.

38:17

Aaron Francis

Hmm.

38:17

Mike Buckbee

And the same with GeoIP data. We license GeoIP data to do the same thing. So-

38:22

Aaron Francis

Interesting. So it's not only, uh, checking an IP against rules that I have explicitly set. You have some sort of threat list or bad actor list-

38:33

Mike Buckbee

Mm

38:33

Aaron Francis

... that you're also providing, that it checks against.

38:36

Mike Buckbee

Yeah. And, and we had spoken about, like, earlier we said, like, well, what do you do if you are in a situation where there's a credential stuffing attack?

38:44

Aaron Francis

Right.

38:44

Mike Buckbee

It- it's pegging the rate limiting, which is good, but a- the majority of those IP addresses are, you know, proxy servers that, you know, is someone's Android app or someone's home PC that's taken over and being used-

38:57

Aaron Francis

Mm-hmm

38:57

Mike Buckbee

... for these attacks. The IP reputation will just automatically stop all of those. And, you know-

39:04

Aaron Francis

Hmm

39:04

Mike Buckbee

... that's, that's what you want. That's how you really deal with the attack, other than just saying like, "Yeah, we're gonna peg the rate limits for, until it gets bored and they go somewhere else." So, you know.

39:13

Aaron Francis

And the, the GeoIP databases is so that if I say, "Let's block all the people from Oklahoma," 'cause, you know-

39:20

Mike Buckbee

Mm-hmm

39:20

Aaron Francis

... they're just north of us here in Texas. If I wanna block all the Oklahomans-

39:24

Mike Buckbee

Yeah

39:24

Aaron Francis

... you don't stuff that into my rule set. You send down a GeoIP database that I check against?

39:31

Mike Buckbee

Yep.

39:32

Aaron Francis

Okay.

39:32

Mike Buckbee

Okay. And-

39:33

Aaron Francis

That makes sense

39:34

Mike Buckbee

... yeah, and that's really for, you know ... The, the custom rules tend to be a lot smaller. Like, you know-

39:41

Aaron Francis

Mm-hmm

39:42

Mike Buckbee

... at the far end is three-quarters of a million IP addresses.

39:44

Aaron Francis

Right.

39:44

Mike Buckbee

It's more likely is a couple hundred or, you know, a couple other rule sets. Like, we have individual rule sets to stop, um, like, SEO scrapers, like Ahrefs and Semrush-

39:55

Aaron Francis

Cool

39:55

Mike Buckbee

... have really aggressive scrapers.

39:57

Aaron Francis

Yep.

39:57

Mike Buckbee

Go through your site. Don't want that, you just block them, you know. Same with all the AI, um, scraping that's happening now. Like, you can stop that as well.

40:06

Aaron Francis

Mm-hmm.

40:06

Mike Buckbee

Um, so yeah. Um, so that's, so that's the operational side. And then on the ... Like, once it's synced down, um, we had run a bunch of these same tests, and we found that not ... So this is just like wins stacking on wins from using SQLite.

40:25

Aaron Francis

Mm-hmm.

40:25

Mike Buckbee

We have a win that it's so much easier to set up 'cause you essentially don't have to set it up. It just works.

40:30

Aaron Francis

Mm-hmm.

40:31

Mike Buckbee

We have a win that, um, we're able to have it work across regions and all sorts of distributed systems, and it works just out of the box for so many of these different client platforms we need to be in. And then the final win was we found it's actually substantially faster, uh, in our benchmarking, um-

40:50

Aaron Francis

Yeah, this surprised me. I, I, I saw all of the operational wins coming, but the fact that it was faster surprised me. So walk me through that.

40:58

Mike Buckbee

Sure. Um, so I'm, I'm not an expert at all of this, but I'm gonna do the best-

41:05

Aaron Francis

I don't know. You might be the only expert at this point.

41:08

Mike Buckbee

Well, I ... This was something I tried to express in the article about this, which is this was not, uh, an impartial, unbiased benchmark-

41:17

Aaron Francis

Right

41:18

Mike Buckbee

... of these things. This was, we have a weird use case. Like, we don't have to do any writes to the SQLite database. We're just reading from it. We're distributing it ourselves. It's only local. Like, all of these caveats on caveats.

41:29

Aaron Francis

Mm-hmm.

41:30

Mike Buckbee

So a- and the other piece of it is, um, it is so hard for, for us to get people to update Redis that it's not a situation where, oh yeah, if you put it in this other mode, or you do this other thing to it, or you give it-

41:43

Aaron Francis

Compile with this flag. No way.

41:45

Mike Buckbee

Yeah. Like, we had a great d- we had trouble getting people to set it up w- to start. Just functional setup. M- And then there's even some real, like, top level things we couldn't get people to, to consistently set. So this is a biased benchmark. Um, but SQLite running locally and Redis running locally, sorta out of the box for both, SQLite just blew this away, um, by 3X.

42:12

And-

42:12

Aaron Francis

3X?

42:14

Mike Buckbee

Yeah. So number ... And that's ... And so here's how I tested. So I said we have these data sets.

42:22

Aaron Francis

Mm-hmm.

42:22

Mike Buckbee

So, um, basically I put the GeoIP database into, um, the sorted set, and then I made an identical one that was set up for SQLite.

42:33

Aaron Francis

Mm-hmm.

42:35

Mike Buckbee

I took, um, a random sampling of different numbers of unique IP addresses from a reputation IP and split that half IPv4 and half IPv6.

42:47

Aaron Francis

Okay.

42:48

Mike Buckbee

And then I took all of those IP addresses, and so this was in chunks, 'cause I was curious, like, how this would work. So I did that at 1,000 IP addresses, and then all the way up to, like, half a million-

42:59

Aaron Francis

Mm

42:59

Mike Buckbee

... and pushed through. Did that five times and took the average. Um, so-

43:05

Aaron Francis

Seems pretty real world to me.

43:07

Mike Buckbee

Yeah. And this is what it came up with. And so there were a lot of hacker news commentators, um- ... that were skeptical of this.

43:15

Aaron Francis

As there can be, yeah.

43:17

Mike Buckbee

As there can be. Um, eh, honestly, everyone was really nice, um, and had lots of good things to say. And even the suggestions, uh, I thought were interesting. But, um-

43:26

Aaron Francis

I saw one, uh, commenter suggested indexes in the database.

43:30

Mike Buckbee

Yeah, I thought that was neat. I thought- ... maybe we could look into that. So, um, may- maybe that's for V3. We'll put in an-

43:38

Aaron Francis

Yeah, we'll see

43:39

Mike Buckbee

... order and all this.

43:39

Aaron Francis

Nobody knows-

43:40

Mike Buckbee

So

43:40

Aaron Francis

... what those are.

43:41

Mike Buckbee

Yeah. Um, yeah. So, uh, so trying to be nice to everybody. Y- so I think what this is, is that this function's inside the process. So this is happening inside the process.

43:54

Aaron Francis

Mm-hmm.

43:54

Mike Buckbee

There's no... Like, even if Redis is local, it's still going over a socket.

43:59

Aaron Francis

Mm-hmm.

43:59

Mike Buckbee

It's still essentially going out to the network, even if that network is your machine, like the localhost loop, and it's still, um, to my knowledge, like, and we, we've had to implement some of the Redis protocol. Like, it's still, like, taking this, putting it into the Redis protocol, getting it out, and doing that sort of encoding and decoding across-

44:19

Aaron Francis

Mm-hmm

44:19

Mike Buckbee

... across that, that network socket interface, and I think that's just slower. Uh, and that even-

44:26

Aaron Francis

Just cannot eliminate it. Do you just have to do that?

44:31

Mike Buckbee

Yeah. And so a- and a- an interesting thing, um, Stephen Margheim, you know, had pointed me-

44:36

Aaron Francis

Mm-hmm

44:36

Mike Buckbee

... to the SQLite docs where it says, like, "Oh, SQLite doesn't compete with databases, it competes with fopen," like opening-

44:42

Aaron Francis

Mm-hmm

44:42

Mike Buckbee

... a file. And, you know, we're in the fortunate case of, like, we are opening this in read-only mode. Like-

44:49

Aaron Francis

Mm-hmm

44:49

Mike Buckbee

... there's no writes. It doesn't care about that, and it just does these as fast as it can. And even at, even if the performance was worse on SQLite, because it's rare that the Redis is actually on the same server-

45:02

Aaron Francis

Mm-hmm

45:02

Mike Buckbee

... as the HTTP stack, it would still be a win because we're not doing, you know, 10, 15 milliseconds to go across the data center-

45:11

Aaron Francis

Geez

45:11

Mike Buckbee

... or, you know-

45:11

Aaron Francis

Yeah.

45:12

Mike Buckbee

A- and so i- it's just a win on a win on a win for us. Um, so easier to deploy, people are more successful, less management, faster. It's been, it's been great. So we were very excited to write this up, and then hopefully other people that find themselves, they can reach for this tool or this setup and, and do these things the same way, so.

45:33

Aaron Francis

That is, that is amazing. So how long do you think... So you said 10 to 15 milliseconds to get across a data center or, you know, outside to the building and back. Um, how long do you think you're taking in a stack now when a request comes in, it's handed off to you, and by the time you hand back, uh, an okay or whatever, how long do you think that is now?

45:54

Mike Buckbee

Oh, it's probably... Well, just for the SQLite portion of it, it's probably microseconds. I mean, that's really-

45:59

Aaron Francis

That's awesome

45:59

Mike Buckbee

... what it comes down to.

46:00

Aaron Francis

Mm-hmm.

46:01

Mike Buckbee

Like, uh, and again, this, the-

46:04

Aaron Francis

That's awesome

46:05

Mike Buckbee

... the benchmark was just this, was just this.

46:07

Aaron Francis

Of course, yeah.

46:08

Mike Buckbee

Yeah. Um, we have to do a bunch of these, so it's probably a couple milliseconds-

46:14

Aaron Francis

Mm-hmm

46:14

Mike Buckbee

... um, that we would add to each request. But, you know, like, the enterprise version of this that's a DNS-based proxy that's worldwide, you have to go through, um, normally we advise clients that's, like, 100 milliseconds that it adds-

46:28

Aaron Francis

Whoa

46:28

Mike Buckbee

... to a request. And that's, like, you know, most of the systems that do that, this is a-

46:35

Aaron Francis

Wow

46:35

Mike Buckbee

... real big tangent, but that's just network effects that you're-

46:38

Aaron Francis

Right

46:38

Mike Buckbee

... you have to go through US East to something else. And you can get around some of that, but it's still, it still happens.

46:45

Aaron Francis

Mm-hmm.

46:45

Mike Buckbee

And it's still flaky, and you still end up in, like, weird, tough-to-diagnose situations where, like-

46:51

Aaron Francis

Mm-hmm

46:51

Mike Buckbee

... Northern Brazil can't get to our site today. I'm like, "Oh, okay. Well, let's, let's look at what's happening," and then you find out it's ISP issues and BGP or whatever.

47:01

Aaron Francis

Is this an actual call you've been on?

47:03

Mike Buckbee

Oh my, so many of these. So yeah.

47:06

Aaron Francis

Gosh.

47:06

Mike Buckbee

So, yeah. So this is, this is just a lot more, uh, the term I like is legible. Like, it's easier-

47:13

Aaron Francis

Mm

47:13

Mike Buckbee

... to understand what's happening, and I think that brings down the administrative burden on developers. And again, the mission is to make this a default, to make this something that's just easy. It's a no-brainer. You know, it g- it, it's just so frustrating. Every site gets attacked. Like, every site-

47:30

Aaron Francis

Mm-hmm

47:30

Mike Buckbee

... has these stupid bots that are just attacking sites, and maybe today's your unlucky day that they actually find something. Maybe today's the day there's a zero day that nobody knew about.

47:40

Aaron Francis

Right.

47:40

Mike Buckbee

Maybe today's the day that your number came up at the top of the CSV of the domains they're attacking for, you know-

47:47

Aaron Francis

Mm

47:47

Mike Buckbee

... weird SEO purposes, and you get a big... There's just no way of knowing. So, but so since every site gets attacked, to me, it just makes sense every site should just have a default, some set of security tools, and, and we're trying to provide that, so.

48:02

Aaron Francis

And y'all are going hybrid, right? There's, like, a free open source community-

48:05

Mike Buckbee

Mm-hmm

48:05

Aaron Francis

... edition, and then there's the, the paid version, 'cause you really do just want people to install this thing.

48:11

Mike Buckbee

Yeah. Um, so there's a couple, there's a couple levels of that. One level is there's a freemium, which is basically you can go in and set custom rules and things, and then what you really pay for is the data subscription stuff. Um-

48:23

Aaron Francis

Mm-hmm

48:24

Mike Buckbee

... so if you wanna go in and just use this, not set any rules, just install it and just look at your traffic and see what the top IP addresses are and things, you can do that. And then if you wanted to start blocking them, you can do that for free. And then there's also the piece of this which is- ... this is a SQLite database. Like, we have this whole syncing architecture stuff, but it's a SQLite database.

48:46

You can crack it open. Um, I explained, uh, the most complicated part of it on this podcast- ... which is this lexical decimal thing.

48:53

Aaron Francis

Have the time.

48:53

Mike Buckbee

If you wanted to, you could implement that yourself. Um, but you know, if you wanna just block a, a 200 IP addresses, you could also just write those into the SQLite database and distribute the SQLite database-

49:05

Aaron Francis

Sure

49:05

Mike Buckbee

... yourself. Like, check it into Git, deploy it with your application. Never talk to us, we don't know anything about it. Like, that, that's also a possibility. Um, so and, you know, from there it goes up to, you know, you have 20 servers, you need more stuff-

49:24

Aaron Francis

Right

49:24

Mike Buckbee

... you need more things. But yeah.

49:25

Aaron Francis

Yeah.

49:26

Mike Buckbee

So.

49:26

Aaron Francis

Cool. Tell us, um, just quickly and then we can wrap it, but tell us about the upsync. How do you get the reports and stuff back?

49:34

Mike Buckbee

So, uh, again, a flaw I think of our version one architecture, which was based on Redis-

49:40

Aaron Francis

Mm-hmm

49:40

Mike Buckbee

... was that we had merged those things together into essentially one stored procedure, that it was both-

49:46

Aaron Francis

Oh.

49:47

Mike Buckbee

And, and that was a performance thing, which is we don't wanna make multiple calls to Redis, so we have one Redis call to preserve the network, you know, latency-

49:57

Aaron Francis

Penalty, yeah

49:57

Mike Buckbee

... that, that... And what it, th- what the stored procedure did was it, here's all of the request information, the user agent, the IP address, and then the response it got was, "Hey, that's a pass, that's a fail."

50:09

Aaron Francis

Mm-hmm.

50:09

Mike Buckbee

And so it would then record in that Redis instance what happened to it and all the metadata, and do all of-

50:15

Aaron Francis

Mm

50:15

Mike Buckbee

... the precomputes of the, you know, the leaderboards and stuff. Um, so now with this split, we have an upsync, and the upsync is just an async, you know, REST endpoint essentially, that can batch send, "Oh, here's the last 200 requests," like what we did with them, what the disposition is, and that's what shows up in Hub now, so.

50:38

Aaron Francis

So as the request is coming through the stack, uh, you open all the rules read-only, and then I presume you open a second or a tertiary database and do the write, and then at some point, somebody comes along and sends the r- the batched request up?

50:53

Mike Buckbee

So we don't, um... This is very dependent on the client.

50:57

Aaron Francis

Okay.

50:57

Mike Buckbee

So in the Rails client, um, we have a mechanism where we can, um, we can batch multiple, uh, requests together in memory and then send them up-

51:09

Aaron Francis

Oh-

51:09

Mike Buckbee

... through to those JSON

51:09

Aaron Francis

... I see. I see.

51:10

Mike Buckbee

And then we're, we're tweaking that for each different stack. Like, like OpenResty is the one I'm working on now.

51:17

Aaron Francis

Mm-hmm.

51:17

Mike Buckbee

They have a whole different, like, shared memory model for how things work and stuff. And so there's a different-

51:21

Aaron Francis

Gotcha, gotcha, gotcha.

51:22

Mike Buckbee

But, you know, it-

51:23

Aaron Francis

So let's say on like the, well, Laravel's tough 'cause it dies after every request. On the Caddy side, you're just keeping 10, 20-

51:31

Mike Buckbee

Yeah

51:31

Aaron Francis

... 30 requests or, or like the format that you're gonna send to the Hub, you're just keeping that in memory and at some point you tip over and fire 'em off.

51:38

Mike Buckbee

Yeah. But even in Laravel, um, this gives us a lot of flexibility, that i- if it makes sense, we could write all these to files on the local machine and then scoop them up-

51:48

Aaron Francis

Mm-hmm

51:48

Mike Buckbee

... on every 1,000th request.

51:50

Aaron Francis

Mm-hmm.

51:50

Mike Buckbee

We could write them to a SQLite database, like per process have a different SQLite database just for writing, and then that gets eventually pushed up to the API.

51:59

Aaron Francis

Mm-hmm.

51:59

Mike Buckbee

But, you know, by splitting it with, the reads have to happen super fast-

52:04

Aaron Francis

Mm-hmm

52:04

Mike Buckbee

... so it's very performant. That's all the rules, that's the front end. We can take our time, you know, 'cause it, what's it matter if it's 250 milliseconds or a full second- ... you know, to upload all the last set of requests. That's okay.

52:17

Aaron Francis

Mm-hmm.

52:17

Mike Buckbee

Like, no one's mad about that. Um, so we're, it's another, it's another advantage of this by splitting the architecture-

52:24

Aaron Francis

Cool

52:24

Mike Buckbee

... that we're able to do that, so.

52:26

Aaron Francis

Cool. This is, this is great. I read the article and thought, "Oh, man, I know exactly, I know exactly who wants to hear about this- ... and it's a bunch of database nerds."

52:35

Mike Buckbee

Yeah.

52:35

Aaron Francis

So I'm so glad that you wrote that and that it went so well, um, both on Hacker News and elsewhere. So give us, give us a, a place we can find you, a place we can find WAFRis, and give us your final, uh, closing pitch for WAFRis.

52:49

Mike Buckbee

Sure. Um, I guess, one, wafris.org, uh, W-A-F-R-I-S.O-R-G. Um, you can go there, and at this point, other than the Rails client, um, which is V2, all the clients are V1, and we're sort of gently encouraging people to wait for the V2. Um, not that the V1 doesn't work, but it's just, it's just not easy.

53:13

Um, and we wanna make this easy. Um, so the Laravel client, um, we're working on a V2 of that. We're working on, you know, all these other ones. So that's where we're at for those. Um, sign up. The other thing you can do is follow me. I am on LinkedIn. There's not a lot of Michael Buckbys on there, so- ... you should be able to find me.

53:30

Aaron Francis

Yeah.

53:30

Mike Buckbee

Uh, same for Twitter. I'm pretty active on Twitter, um, as mbuckby. Um, yeah. So please, and if anyone has a better way of doing this, reach out. I would, I would love to know it, just for, just for my own sake. So yeah.

53:45

Aaron Francis

Uh, here's, here's my promise. If anyone has a better way of doing this and they reach out to Mike, and y'all talk about it and figure it out, and it is actually better, you can come on the show, whoever you are, person, and you can talk about how it was better and how interesting it must have been, because this is wild already. So that's my pitch to you, dear listener. Um, well, thanks Mike, for doing this.

54:07

Uh, this was-

54:08

Mike Buckbee

Oh, thank you, Aaron. Yeah

54:08

Aaron Francis

... an absolute delight. I'm sure there are, uh, not many podcasts that want you to go into the nitty-gritty details of sorted sets in Redis, but that was super fun for me.

54:18

Mike Buckbee

Yeah.

54:18

Aaron Francis

So thanks for being here.

54:19

Mike Buckbee

At some point, most people's eyes glaze over, and they're sort of like- ... "Okay. Yeah. What's a Redis?"

54:24

Aaron Francis

Sure, guy. Sure, sure, sure.

54:26

Mike Buckbee

Yeah.

54:26

Aaron Francis

All right. Well, y'all can check this out, um, I think on, just on my YouTube channel at youtube.com/@aarondfrancis. Uh, let me know what you think, and we'll see you next time

Databases

More videos on databases

All videos

Get the next one by email

I’ll send you some more. Not too many.

Join 7,500+ other readers.

Read past issues