Skip to content

Commit 72f9311

Browse files
authored
Merge pull request #660 from jdno/document-cdns
Create documentation for CDNs
2 parents a2bec71 + b9e37c9 commit 72f9311

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
- [AWS access management](./infra/docs/aws-access-management.md)
5454
- [Bastion server](./infra/docs/bastion.md)
5555
- [Bors](./infra/docs/bors.md)
56+
- [CDN](./infra/docs/cdn.md)
5657
- [Crater agents](./infra/docs/crater-agents.md)
5758
- [Custom GitHub Actions runners](./infra/docs/gha-self-hosted.md)
5859
- [Dev Desktops](./infra/docs/dev-desktop.md)

src/infra/docs/cdn.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Content Delivery Networks
2+
3+
Users of the Rust programming language interact with the infrastructure of the
4+
project in various different ways. They access the project's website and
5+
documentation, query the crates index, and download Rust releases and crates.
6+
These resources are hosted by the Rust project and served through a [Content
7+
Delivery Network] (CDN).
8+
9+
This document outlines why we use CDNs, for what, and how we have set them up.
10+
11+
## Objectives
12+
13+
We have three goals for our use of CDNs in our infrastructure:
14+
15+
1. Reduce costs of outbound traffic through cheaper pricing and caching
16+
2. Reduce load on origin servers to save compute resources
17+
3. Provide a way to rewrite legacy URLs for some resources
18+
19+
### Reducing Costs
20+
21+
As an open source project, we have to be very mindful of our infrastructure
22+
costs. Outbound traffic is by far one of the most expensive items on our monthly
23+
bills, and one that will continue to increase as Rust gets more popular.
24+
25+
Cloud providers typically charge different rates for outbound traffic based on
26+
the service. For example, serving data straight from [Amazon S3] is more
27+
expensive than serving the same data through an [Amazon CloudFront]
28+
distribution. This is why we now use a CDN by default, even for services that
29+
can't make use of other features of a CDN such as caching.
30+
31+
## Infrastructure
32+
33+
Most of the project's resources are hosted on [AWS]. Static content is stored in
34+
[Amazon S3], while dynamic content is loaded from a server. Both types of
35+
content are served through [Amazon CloudFront], the [Content Delivery Network]
36+
of AWS.
37+
38+
When a user access a resource, e.g. they are trying to download a crate, they
39+
will access the resource through the CDN. Different _distributions_ map domain
40+
names to a configuration and a backend (called the _origin_). For example,
41+
downloading a crate from `static.crates.io` goes through a _distribution_ that
42+
fetches the crate from an S3 bucket and then caches it for future requests.
43+
44+
```text
45+
┌──► S3 (static content)
46+
47+
User ───────► CloudFront ────┤
48+
49+
└──► Server (dynamic content)
50+
```
51+
52+
## Distributions
53+
54+
There are many distributions, all of which are configured in the
55+
[rust-lang/simpleinfra] repository. However, their usage is very unevenly
56+
distributed. The following distributions are the most important ones for the
57+
project, both in terms of traffic and criticality for the ecosystem.
58+
59+
### Rust Releases
60+
61+
Whenever a user installs or updates Rust, pre-compiled binaries are downloaded
62+
from `static.rust-lang.org`. The same is true when Rust is installed in a CI/CD
63+
pipeline, which is why this distribution has by far the highest traffic volume.
64+
65+
Rust binaries are static and are stored in [Amazon S3], from where they are
66+
served by the CloudFront distribution.
67+
68+
The distribution for `static.rust-lang.org` has a custom router that runs in a
69+
[AWS Lambda] function. The router provides a way to list files for a release and
70+
rewrites the legacy URL for `rustup.sh`.
71+
72+
The cache for Rust releases is invalidated nightly.
73+
74+
### Crates
75+
76+
Similar to Rust releases, crates are served from as static content from
77+
`static.crates.io`. While still being the second-largest distribution in our
78+
infrastructure, it is much smaller than the releases.
79+
80+
Crates are static and stored in [Amazon S3], and served through a CloudFront
81+
distribution.
82+
83+
[amazon cloudfront]: https://aws.amazon.com/cloudfront/
84+
[amazon s3]: https://aws.amazon.com/s3/
85+
[aws]: https://aws.amazon.com/
86+
[aws lambda]: https://aws.amazon.com/lambda/
87+
[content delivery network]: https://en.wikipedia.org/wiki/Content_delivery_network
88+
[rust-lang/simpleinfra]: https://github.com/rust-lang/simpleinfra

0 commit comments

Comments
 (0)