docs.rs uses a specialized storage model to serve individual files (like HTML, CSS, or source files) from large crate archives without downloading the entire archive.
Storage Model
For every crate version, two ZIP archives are stored:
- rustdoc output archive: Contains the generated documentation.
- source files archive: Contains the crate's source code.
The Index Model
To enable fast random access, docs.rs generates an SQLite database index for each archive. This index acts like a ZIP central directory and maps a logical file path to its specific location within the ZIP file. Each entry in the index contains:
- The
filename/path within the archive. - The byte range
from (inclusive start). - The byte range
to (inclusive end). - The compression algorithm used for that specific entry.
Request Flow
When a single file is requested:
- The system identifies the correct archive and index for the crate/version.
- The SQLite index is checked (and downloaded to a local cache if missing).
- The index is queried for the requested path.
- An HTTP Range request is issued to S3 to fetch only the bytes between
from and to. - The returned byte range is decompressed using the algorithm specified in the index and served to the user.