# Under the hood

> How the Spare Cores Navigator collects and publishes its data, from the vendors' APIs to the database, and the components doing it.

How the Spare Cores Navigator collects its data and publishes it, and the
components doing it. For the data itself and the ways to access it, see
[Data](https://docs.sparecores.com/data.md). For the methods behind the data, e.g. the benchmarks, explained
in conference talks with recordings and slides, see the
[talks](https://sparecores.com/talks) on sparecores.com.

## Components

The Navigator consists of several well-scoped, interconnected components:

| Component | Source license | References | Description |
| --- | --- | --- | --- |
| Runner | MPL 2.0 | [GitHub repository of sc-runner](https://github.com/SpareCores/sc-runner) [sparecores-runner on PyPI](https://pypi.org/project/sparecores-runner/) | Pulumi wrapper to launch instances across clouds. |
| [Images](https://docs.sparecores.com/images.md) | MPL 2.0 | [GitHub repository of sc-images](https://github.com/SpareCores/sc-images) [Container images on the GitHub Container Registry](https://github.com/orgs/SpareCores/packages?repo_name=sc-images) | Container images for hardware discovery and benchmark workloads. |
| Inspector | MPL 2.0 | [GitHub repository of sc-inspector](https://github.com/SpareCores/sc-inspector) | Python tools to inspect and benchmark cloud servers. |
| [Inspector Data](https://docs.sparecores.com/data.md) | CC BY-SA 4.0 | [GitHub repository of sc-inspector-data](https://github.com/SpareCores/sc-inspector-data) | Raw hardware information and benchmark results. |
| [Crawler](https://docs.sparecores.com/crawler.md) | MPL 2.0 | [GitHub repository of sc-crawler](https://github.com/SpareCores/sc-crawler) [sparecores-crawler on PyPI](https://pypi.org/project/sparecores-crawler/) | Cloud vendor API and Inspector Data integrations. |
| [Crawler Data](https://docs.sparecores.com/data.md) | CC BY-SA 4.0 | [GitHub repository of sc-data-dumps](https://github.com/SpareCores/sc-data-dumps) | JSON dumps of collected cloud resource information. |
| [Database](https://docs.sparecores.com/sqlite.md) | BSL 1.1 | [Download the Database](https://cdn.sparecores.net/sc-data/latest/sc-data-all.sql.xz) [Documentation of the Database schemas](https://docs.sparecores.com/schemas.md) | SQLite database dump of current cloud resource information. |
| [Data Wrapper](https://docs.sparecores.com/sqlite.md) | MPL 2.0 | [GitHub repository of sc-data](https://github.com/SpareCores/sc-data) [sparecores-data on PyPI](https://pypi.org/project/sparecores-data/) | Python package for easy integration of the Database. |
| [HTTP API](https://docs.sparecores.com/api.md) | MPL 2.0 | [GitHub repository of sc-keeper](https://github.com/SpareCores/sc-keeper) [API endpoint of the HTTP API](https://keeper.sparecores.net/openapi.json) | Programmatic access to the Database. |
| [Web UI](https://docs.sparecores.com/web-ui.md) | MPL 2.0 | [GitHub repository of sc-www](https://github.com/SpareCores/sc-www) [Homepage of the Web UI](https://sparecores.com/servers) | Web frontend for human access to the Database. |

To make the Spare Cores Navigator available to the community, our software
components are licensed under MPL 2.0 and all raw collected data under
CC BY-SA 4.0. For deep production integrations and enterprise reliability, we
offer commercial API and database access, expert support, and consulting
services.

## How it works

1. The **Crawler** pulls the products (SKUs) and prices of the supported cloud
   vendors from their APIs, enriches with manually curated mappings,
   standardizes them, and publishes them as JSON dumps and as an SQLite
   database. See the [Crawler](https://docs.sparecores.com/crawler.md) docs, and the [Schemas](https://docs.sparecores.com/schemas.md)
   section for the structure of the database.
2. The **Inspector** selects the servers to be inspected based on the database,
   any task blocking reason codes, and previous runs, and starts them with the
   **Runner**, and runs hardware discovery and benchmark tasks on each,
   collecting the raw results. The tasks run the container images described in
   the [Images](https://docs.sparecores.com/images.md) section.
3. The Crawler parses the inspection results into the database, so that the
   hardware details and benchmark scores are stored along with the prices.
4. The database is available as a file download and via the **Data Wrapper**
   Python package (see [SQLite](https://docs.sparecores.com/sqlite.md)), via the **HTTP API** (see the
   [API](https://docs.sparecores.com/api.md) docs), and on the **Web UI** at
   [sparecores.com](https://sparecores.com/servers) (see its
   [user guide](https://docs.sparecores.com/web-ui.md)).

```mermaid
flowchart TD
    %% colors of the Spare Cores design: external services gray, data amber,
    %% Python components green, runtime environments panel blue
    classDef external fill:#374151,stroke:#9ca3af,color:#e5e7eb;
    classDef data fill:#78350f,stroke:#f59e0b,color:#fef3c7;
    classDef python fill:#065f46,stroke:#34d399,color:#ffffff;
    classDef env fill:#06263a,stroke:#0369a1,color:#e5e7eb;
    classDef default fill:#0c4a6e,stroke:#0369a1,color:#e5e7eb;
    vendor(Vendor APIs) -- SKUs-->  crawler
    class vendor external

    inspector_data[inspector-data] -- Prior runs --> inspector_outside[inspector]
    class inspector_outside python
    class inspector_data data
    inspector_outside -- Select servers --> runner
    class runner python
    runner -- Start/stop servers--> server

    subgraph crawler_gha[GHA: data-dumps]
        crawler
    end
    class crawler_gha env

    subgraph inspector_gha[GHA: inspector-data]
        inspector_outside
        runner
    end
    class inspector_gha env

    subgraph server[Cloud server]
        inspector <--> tasks@{ shape: processes, label: "Tasks" }
        class inspector python
    end
    class server env

    inspector -- stdout, stderr, metadata--> inspector_data
    crawler -- JSON --> data_dumps
    class crawler python
    class data_dumps data

    crawler -- SQLite --> s3[(Object store)]
    class s3 data
    s3 --> cdn[CDN] --> data[sc-data]
    class cdn external
    class data python
    data -- Server list --> inspector_outside

    inspector_data -- Parse results --> crawler

    subgraph keeper_gha[GHA: keeper]
        keeper_repo[keeper] --> docker_keeper[Docker build]
        class keeper_repo python
    end
    class keeper_gha env
    subgraph keeper_ecs[Service: keeper]
        keeper@{ shape: processes, label: "Tasks" }
    end
    class keeper_ecs env
    ECR[(Docker registry)] --> keeper
    class ECR data
    docker_keeper[Docker build] --> ECR
    data --> keeper

    subgraph www_gha[GHA: www]
        www_repo[www] --> docker_www[Docker build]
        class www_repo python
    end
    class www_gha env
    subgraph www_ecs[Service: www]
        www@{ shape: processes, label: "Tasks" }
    end
    class www_ecs env
    ECR --> www
    docker_www[Docker build] --> ECR
    keeper_cs -- SSR --> www

    subgraph ECS
        keeper_ecs
        www_ecs
    end
    class ECS env

    keeper --> alb[ALB]
    www --> alb
    alb --> keeper_cs[Cloudfront: keeper.sparecores.net]
    alb --> www_cs[Cloudfront: sparecores.com]
    keeper_cs -- Task list --> inspector_outside

    ssm[Secrets] --> www
    ssm --> keeper
    class ssm external

    redis[(Cache)] <--> keeper
    class redis data

    clerk[Auth provider] <--> www
    clerk --> keeper
    class clerk external

    %% nested in ECS, so their class is not applied
    style keeper_ecs fill:#082f49,stroke:#0369a1
    style www_ecs fill:#082f49,stroke:#0369a1
```

## Standardizing the vendors' data

The vendors' APIs and catalogs differ in what they list, how, and how
completely, so the Crawler and the Inspector don't just copy them:

- **Prices:** few vendors list one price per server type. Google Cloud, for
  example, prices most server types by their vCPUs and memory, as SKUs whose
  descriptions name the server family, with exceptions, e.g. its C2 family is
  "Compute optimized", and M2 is priced as a premium on top of M1. The Crawler
  matches these into one price per server type, region, zone and allocation.
- **Specs:** what the vendors' APIs don't list, the Crawler takes from their
  docs or from hand-written mappings.
- **Inspection:** the Inspector reads the hardware of each server directly,
  e.g. with `dmidecode`, `lscpu`, `lstopo` and `lshw`, which fills in or
  corrects specs such as the number of cores, the CPU caches, or the memory
  actually available. Specs that neither the vendor nor the inspection
  provides stay empty (see [Data](https://docs.sparecores.com/data.md#things-to-know)).

The raw outputs of every inspection, with their stdout, stderr and metadata,
are public in [`sc-inspector-data`](https://github.com/SpareCores/sc-inspector-data),
so that any spec or score can be checked against what was measured.
