Python Web Apps that Fly with CDNs Transcripts
Chapter: Integrating Static Content
Lecture: Creating the static content pull zone

Login or purchase this course to watch this video and the rest of the course contents.
0:00 It's time to start configuring the CDN. Drop over to Remember in this setup section, we talked about creating your account.
0:08 So you are going to need an account here. You've got the 14 day free trial. It's even when you pay for it, it's basically free.
0:15 You know, a couple of cents. You went crazy for using data during this course. So no problem, but you do need that account.
0:22 So once you have your account, go over and hit login. Here you can see the talk Python panel. This is all of our infrastructure and stuff running here.
0:32 So you can actually, I'm gonna show you a little bit about what's happening behind the scenes. Notice we're doing at the moment
0:39 about 14 terabytes of traffic and a little over 2 million requests in the last 30 days. And amazingly and really great, 88% cache hit rate.
0:50 So 88% of the users who come to it are like, yep, you've got this, or we're serving it out of a node and don't have to come get it from another node
0:59 or even from the origin servers we just talked about. We have some storage zones. You can see we have our podcast and our course video.
1:08 In fact, this video right now that you're watching and hearing is coming to you through, through that storage zone right there.
1:16 All right, that's the large content section. We also have these pull zones and this is what we're gonna set up.
1:22 We're gonna set up something called a pull zone. Before I move off this page though, I just want to point out our traffic here is 14 terabytes.
1:29 Our price is $40. And look at this, this is 18 times cheaper than S3, Amazon S3 or Azure. Incredible. Last time I checked,
1:40 those were 9 cents a gigabyte for bandwidth. This is half a cent. Really, really good. Another thing to be aware of, these numbers across the top,
1:48 those are a 30 day rolling average. These numbers across the bottom, this is calendar month. So they don't exactly line up.
1:55 this really is more like 70 or 80 bucks a month, but it's still considering that much traffic, it's nothing.
2:02 Okay, this chapter we're messing with pull zones, next chapter storage potentially. There's cool stats and other stuff you can see.
2:08 We'll go and pull up the stats, see what we can see here before we get to them. So here it'll give you numbers like,
2:14 oh, look over here, we served 775 gigabytes, but only 24 of that was uncached, which is great. or you can see which one this is the origin shield
2:26 and for that 47 gigabytes of traffic that it served internally and only had to go back to the server for six, seven, eight.
2:35 Some of those also may be the storage as well. So that is even less traffic on our server. But again, cache versus uncached.
2:42 And here's a really cool picture to explore is actually use this for the course image. So you've seen this before in a sense,
2:48 here's all the different nodes and the brightness or darkness of them shows how much of your data is in that particular,
2:56 what's called a point of presence or POP, basically local server, file server on the internet. And then down here, it'll show you
3:03 how much storage you're using there. So for example, in the Chicago data center, we have five terabytes, in Miami we have a little under a terabyte.
3:11 All right, enough of the survey, let's jump into this pull zone. There's two kinds that you can have. You can have a standard one,
3:18 which is built for like CSS files and images, or you can have a volume one. The volume one we use for MP3 files that are 50 megs each
3:29 or video files that are more potentially, sometimes they're smaller, but a lot of times they're a couple of hundred megabytes.
3:35 So that lets them to be a little bit cheaper. And here's this one that I've already set up. I'm gonna actually copy this URL
3:43 'cause I'm gonna need it in a second. We'll go and set up another one here called VideoCollector, let's say class.
3:50 This is what I was doing to demo it before. We're gonna create a new pull zone. The name, so this is, this name you put here,
4:02 you may never use this, but you can, and I'm not gonna, because I don't have a domain for our VideoCollector site, I have to use this.
4:09 If you had your own custom domain, you would probably use a subdomain.
4:13 So for example, it's like or, something along those
4:21 lines is what we actually use on our site, but there's a equivalent one that we could use. So that's what this is asking here.
4:32 We'll call this video collector. Just like that. Let's go with this.
4:40 And here's those two types of storage zones we had in that animation, that previous video.
4:45 Do you want it to come back to your web server and serve it as if it was a local browser
4:49 of the website or do you want to put it into a cloud drive that you manage independently?
4:55 We're going to use URL for this static content that we're talking about.
4:59 Over here, this says where if I have to go, if somebody requests something and it doesn't
5:05 exist in the CDN, where do I go find it? Or if it expires, you know, the cache time has
5:10 expired, where do I get a new copy? So we're going to say go to the ngrok destination.
5:19 This is the point where if you don't have a paid ngrok plan, this is going to keep changing
5:25 and as you shut down and open ngrok, you just need to come back here and edit this field.
5:29 It's super easy, but that's how it works. Here we have the standard tier, not the high
5:34 volume tier for this one because it's optimized for more performance, not for large files.
5:39 And then you can also talk about where you want to be available. Do you want to be available
5:44 in the Middle East and Africa? Do you want to be available in Europe? Here's the cost
5:50 that you pay for these different locations. It's slightly different, but that's fine.
5:53 I'm going to hit add. It gives us a little bit of help on how to get started. It says,
5:59 The public domain and the public URL with your previous static content was things like What you said your domain was so we the CDN and grok thing
6:08 /images /logo, and it says alright. Well now you got to use your CDN Prefix and okay great ready to go if you wanted to add a custom domain like
6:21 I have no idea what that is please don't visit it
6:28 You would set that up with your DNS and this actually guides you through doing that.
6:31 If you need to come back and edit your ngrok, just edit it right here, okay?
6:35 So we're only of this one, but you can have multiple ones. That's how we do it. So we can click on the origin. It says what type again, you can
6:43 figure that. It says what is the price you're paying? You can tell it how to deal with timeouts and if it can it'll replay things.
6:51 This one's important. We come over here and say caching. I want to It can take a guess on what to do that doesn't make me happy.
7:00 So what I'm going to do, it could let our website communicate the caching ideas. But I'm just going to set this really high three months.
7:09 And you'll see that while that might give you the idea we're going to lead to a lot of stale
7:15 caches and problems, it's not going to absolutely fix this. Do you want to let it normalize the query string order? Sure.
7:23 And then this one is important. We don't need it now, but we'll need it later. Set URL query string querify.
7:31 We're going to do that because we want to be able to prefix something on the end to say, "Here's a new version of file like question mark v=2."
7:38 That'll give us a new CSS file or a new image or whatever we put that query string on, but only if you turn this on, it's off by default.
7:46 Okay. Yeah, it looks pretty good here. So you can say also you even serve out of a stale cache if things are broken on your
7:55 server, you know, leave that off. What else can we do? We're going to go down here to origin shield. And I can say enable origin shield.
8:03 So what this will do is says, if somewhere in the CDN network, the file they're asking
8:10 for exists, instead of coming back to my server, say, there's a user who's loaded in the CDN
8:17 South America and then someone in Australia comes back and tries to access it. Instead of going to my server, keep it within the CDN.
8:24 Okay, so that's what this is about. That's always good. There's lots of security, including restricted files and stuff that you can do.
8:34 You can pass along headers, for example, you can do cores stuff or link back to your site if you need to. A bunch of other things.
8:42 I think we don't really need to worry about these. I guess the last one is, if you really need to clear out the cache, you can just blast
8:49 it away right there, but we shouldn't need to. All right, now we haven't done anything yet. Let's see how this works.
8:56 We'll go back to our website here. Here's our website, but remember, we don't want this one. We want the ngrok URL.
9:08 So I'm going to launch it from here again. And notice it's coming in really slowly.
9:14 There's nothing that has gotten better with what we did over the CDN yet. It's all the same.
9:22 So what I need to do is I need to open up one of these images. Let's go here and say image, open in a new tab. And this is our ngrok version.
9:36 But what we put into the CDN is we said we want to use video collector-bc. This is not a great name.
9:43 I would use a subdomain if I were you, but we don't have a subdomain. So here's what we got. But we hit this very first time, it's a little slow.
9:51 The CDN actually came if you look at ngrok, it came over and requested that right there. That was the CDN that did that, not us.
9:59 And then the CDN served this up. But now if we hit this again, notice, basically instant and also notice down here not coming back to our website.
10:09 It's there for three months in the server until we either go and explicitly delete it or it's just going to be there for three months.
10:18 It's there for a good long while. And super fast, going to start geo-replicating. Beautiful.

Talk Python's Mastodon Michael Kennedy's Mastodon