Skip to content

Commit aedbf5f

Browse files
committed
Create documentation for CDNs
The documentation describes the current state with the most important CloudFront distributions. The motivation to document this now is that we are planning to introduce a second CDN, which we can collaborate on by updating this document.
1 parent 353d9dc commit aedbf5f

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
- Reduce costs of outbound traffic by caching resources in the CDN
14+
- Reduce load on origin servers to save compute resources
15+
- Provide a way to rewrite legacy URLs for some resources
16+
17+
## Infrastructure
18+
19+
Most of the project's resources are hosted on [AWS]. Static content is stored in
20+
[Amazon S3], while dynamic content is loaded from a server. Both types of
21+
content are served through [Amazon CloudFront], the [Content Delivery Network]
22+
of AWS.
23+
24+
When a user access a resource, e.g. they are trying to download a crate, they
25+
will access the resource through the CDN. Different _distributions_ map domain
26+
names to a configuration and a backend (called the _origin_). For example,
27+
downloading a crate from `static.crates.io` goes through a _distribution_ that
28+
fetches the crate from an S3 bucket and then caches it for future requests.
29+
30+
```text
31+
┌──► S3 (static content)
32+
33+
User ───────► CloudFront ────┤
34+
35+
└──► Server (dynamic content)
36+
```
37+
38+
## Distributions
39+
40+
There are many distributions, all of which are configured in the
41+
[rust-lang/simpleinfra] repository. However, their usage is very unevenly
42+
distributed. The following distributions are the most important ones for the
43+
project, both in terms of traffic and criticality for the ecosystem.
44+
45+
### Rust Releases
46+
47+
Whenever a user installs or updates Rust, pre-compiled binaries are downloaded
48+
from `static.rust-lang.org`. The same is true when Rust is installed in a CI/CD
49+
pipeline, which is why this distribution has by far the highest traffic volume.
50+
51+
Rust binaries are static and are stored in [Amazon S3], from where they are
52+
served by the CloudFront distribution.
53+
54+
The distribution for `static.rust-lang.org` has a custom router that runs in a
55+
[AWS Lambda] function. The router provides a way to list files for a release and
56+
rewrites the legacy URL for `rustup.sh`.
57+
58+
The cache for Rust releases is invalidated nightly.
59+
60+
### Crates
61+
62+
Similar to Rust releases, crates are served from as static content from
63+
`static.crates.io`. While still being the second-largest distribution in our
64+
infrastructure, it is much smaller than the releases.
65+
66+
Crates are static and stored in [Amazon S3], and served through a CloudFront
67+
distribution.
68+
69+
[amazon cloudfront]: https://aws.amazon.com/cloudfront/
70+
[amazon s3]: https://aws.amazon.com/s3/
71+
[aws]: https://aws.amazon.com/
72+
[aws lambda]: https://aws.amazon.com/lambda/
73+
[content delivery network]: https://en.wikipedia.org/wiki/Content_delivery_network
74+
[rust-lang/simpleinfra]: https://github.com/rust-lang/simpleinfra

0 commit comments

Comments
 (0)