Python Web Apps that Fly with CDNs Transcripts
Chapter: Welcome to the course
Lecture: Why I avoided a CDN
0:00 I suspect like many of you, I have clearly known about CDNs for a long time. And yet I avoided them. Why?
0:10 Probably you have as well and you're here to think about maybe changing that too. So I'll tell you why I avoided them at least.
0:17 First of all, I didn't feel like I needed it. And to be honest, I kind of didn't.
0:23 I traveled around to different places in the world and I've interacted with the various
0:27 websites that I run, most importantly, TalkPython training courses site, but also the podcast ones and a bunch of services and things behind there.
0:36 With the right amount of static caching and lifetime type of stuff, maybe one request is a little bit slow, and then it was nice and quick after that.
0:46 I remember sitting in a hotel in Israel, which is quite far away, and interacting with a
0:51 site and it was much, much quicker than many of the other ones. similarly been in Europe and it seemed fine. Now, that was until last Black Friday.
1:01 Last Black Friday, I sent out the announcement, "Hey, Black Friday, there's some sales we got going on. Everyone come check it out through email
1:08 and over social media." And to my, very much my honor, a bunch of people came and checked it out. However, I decided to log into the server
1:17 and see how it was doing. And I could see the CPU usage on the main server was 85%. That's a little close to the limit, isn't it?
1:26 It was going up 89%, 90, 91, 92, 93%. If that hits over 100, it's done, right? It just can't keep up, the stuff will,
1:38 the requests will queue up and it's only gonna get worse and harder for it to keep up and it's just gonna come crashing down.
1:43 I was like, oh my gosh, what do I need to do? Surely the Python code is not running quite right or something with a database is not keeping up.
1:52 No, actually that wasn't it at all. Although the Python code was using like 8% of the CPU, the MongoDB server was at 10% maybe.
2:11 a bunch of CSS, a bunch of images. I couldn't believe it. And so do you know what will take, easily, easily take all that load off my server
2:19 and distribute it and make it a better experience for the users? CDN. So that finally gave me the kick that I needed to go,
2:26 all right, well, if it's not even a Python server-side code problem, maybe I should supply, apply some kind of tool like a CDN
2:35 that is exactly built for solving these at scale. At Talk Python, we're a small team, me, couple of consultants, some authors,
2:44 but we don't have a big DevOps team, we don't have a big data center team, none of that kind of stuff.
2:50 And so for me, I've always avoided complexity, especially operational and DevOps type complexity,
2:57 like crazy, I want something simple that works, it works well enough that's not too expensive.
3:03 And so my thought was, well, the CDN is just going to add complexity with cache staleness and in a bunch of things like that. So nope.
3:12 I also thought it might be expensive. We do about 15 terabytes a month, so 15,000 gigabytes a month of traffic. That's no joke.
3:22 I mean, I know some of you all out there probably have more, but that is a lot of traffic to be running through one server.
3:28 So if we were to run that through S3, our bill would be $1,400 in bandwidth every month.
3:37 And well, my first thought was a CDN is like, if it's going to go to 114 or over 100 different
3:43 locations throughout the globe, surely it's more than S3, right? So whatever that number is and we multiply it, eh, not really wanting to pay that at
3:52 the moment. So we'll see that is not the problem. It's actually incredibly affordable, which turns out to be surprising to me.
4:00 And finally, just honestly a bit of lack of awareness on my part.
4:04 Like I said, I knew about CDNs, but I haven't really used them for interesting things until
4:08 I dove into this and started integrating it into our infrastructure. And wow, how cool is it? So hence this course, why we're all here, right?
4:16 To learn more about it and get better at using them.