Each tier speaks exactly one protocol, and none of them can be removed. The browser speaks HTTP and renders; the API speaks JDBC to the engine and JSON to the browser; the engine speaks its own binary MySQL protocol on 9030.
It looks like an avoidable hop. It is not, and the two reasons are measured, not assumed:
| Attempt | Result on this build |
|---|---|
| Browser talks to StarRocks directly | Impossible. Port 9030 is the binary MySQL protocol; a browser has no TCP client and no such codec. |
| Use the FE's HTTP query endpoint instead | POST :8030/api/query answers 501 Not Implemented on 3.5.21. Tried, captured, rejected. |
| Add a thin HTTP bridge | The only remaining path — and the one that also gives a place to hold credentials off the client. |
A request therefore travels: GET /api/v1/consolidados/por-anio → controller validation → cache lookup → JdbcTemplate → FE on 9030 → BE tablets → rows mapped to records → envelope → JSON. The whole trip measured 61 ms for resumen and 334 ms for the heaviest aggregation.
| Piece | What it does, and the rule it enforces |
|---|---|
ConsolidadoController | 17 read-only GETs. Validates before touching the engine: year 2000–2026, limit 1–200, offset ≤ 100 000, search term ASCII and ≥ 2 chars. |
ConsolidadoService | Cache of 60 s keyed by request, with refresh=true bypassing it. No scheduler: nothing runs in the background. |
ConsolidadoRepository | Two classes of SQL: aggregations over 1.3 M rows, and one paginated detail query. No ORM — a GROUP BY has no object graph to map. |
Envelope<T> | Every response carries data, generatedAt, source, cached, rows. source is the engine's own current_version(), so a screenshot cannot lie about who answered. |
StartupCheck | Fails the context when SR_URL, SR_USER or SR_PASSWORD is missing. Added after discovering the app happily booted without them and served 503 to everything. |
ApiExceptionHandler | Engine down → 503 with {error, engine, message}; bad parameter → 400. Never a stack trace. |
WebConfig | CORS for http://localhost:5173 only. The engine itself never leaves loopback. |
| Endpoint | Rows | Shape of the answer |
|---|---|---|
/resumen | 1 | Contracts, total value, buyers, suppliers, undated count, min, max, median. |
/por-anio | 29 | Contracts and value per year, plus the anio = 0 bucket for undated rows. |
/por-anio-stat | 29 | Same, plus percentile_approx(valor, 0.5) — the median per year. |
/por-fuente | 2 | SECOP I versus II: contracts and value. |
/por-anio-fuente | 58 | The same split across years, for the stacked chart. |
/por-mes | 12 | Contracts and value by month of signature. |
/por-anio-mes | 300 | Year × month grid for the calendar heatmap, 2000–2026. |
/por-rango-valor | 6 | Six COP bands: how many contracts and how much value in each. |
/por-entidad | ≤200 | Buyer codes for one year, ordered by value. |
/por-departamento | ≤200 | Departments for one year. |
/por-municipio | ≤200 | Municipalities, all years. |
/por-contratista | ≤200 | Suppliers by value, for the concentration curves. |
/por-representante | ≤200 | Legal representatives as recorded on the contract. |
/distribucion-compradores | 5 | Buyers bucketed by how many contracts they have. |
/texto | 1 | Substring count over the description, ASCII-normalised. |
/contratos | ≤200 | Contract-level rows for one year, largest first, paginated. |
All sixteen share one envelope and one cache. The seventeenth is the OpenAPI description at /v3/api-docs.
| Container | Image | Ports (loopback only) |
|---|---|---|
sr-lab | starrocks/allin1-ubuntu @ sha256:faf5f6b… | 9030 · 8030 · 8040 |
my-lab | mysql:8.0.46 @ sha256:7dcddc0… | 13306 → 3306 |
dash-api | eclipse-temurin:17-jre + the built jar | 8080 |
vite preview | host process, built dist/ | 5173 |
The API joins the compose network secop-lab_default and reaches the engine as sr-lab:9030, so no database port is published to the host beyond loopback. Credentials arrive as environment variables and are never written to the repository.
| Decision | Why |
|---|---|
SUM(CAST(valor AS DECIMAL(20,0))) | The same sum in double gives different last digits depending on the order of addition, and a columnar engine does not add in row order. Decimal makes the two engines print the same integer. |
LOWER() on both sides of LIKE | StarRocks compares byte-exact and the stored text is uppercase; without it the query returns zero rows. MySQL's ai_ci would also fold accents, which is disclosed wherever it changes a count. |
| Group by codes, never names | Collation could merge two spellings into one group on MySQL and not on StarRocks, turning a benchmark into a collation test. |
| No scheduled refresh, no polling | Requested. The heaviest consolidation answers in 334 ms, so asking the engine per request is interactive; the 60 s cache absorbs bursts and ?refresh=true exists for the user. |
| Read-only user, fail-fast startup | The API should be unable to write even if it is compromised, and unable to start half-configured. |
| Golden JSON fixtures | Four captured payloads with pinned figures (71,901 · 2,018 · 29) are asserted by 8 tests, so a change in SQL breaks the build instead of moving a chart silently. |
| If this fails | You see | How it was verified |
|---|---|---|
| StarRocks is down | 503 engine_unavailable naming the engine | Second container pointed at a dead port |
| Credentials missing | Process exits with code 1 and the missing variable names | Container started with no environment |
| The API is down | The page shows a red panel, not empty charts | docker stop dash-api, hard reload |
| A parameter is invalid | 400 with bad_request and the offending value | Year 1990 and an empty term |
Authentication on the dashboard, TLS, high availability, and any streaming ingestion. Each would be required in production and none of them changes the comparison this laboratory exists to make.
One BE, four gigabytes, a 1-in-13 sample, loopback only. The API is a laboratory instrument: it proves the tier is necessary and cheap, not that it is production-ready.