← Status board  /  Architecture

Backend architecture Three processes, one protocol each. This page follows a single question from the browser to a StarRocks tablet and back, and explains why the middle layer cannot be skipped.

Engine StarRocks 3.5.21 API Spring Boot 3.3.5 Client React 18 + Vite Endpoints 17

1 The three tiers

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.

TIER 1 · BROWSER React 18 + Vite localhost:5173 · ECharts TIER 2 · API Spring Boot 3.3.5 :8080 · JdbcTemplate cache 60 s · 4 + 13 endpoints TIER 3 · ENGINE StarRocks FE :9030 SQL · :8030 admin ONE BE Tablets 25 partitions · ZSTD SOURCE (READ-ONLY) 1,309,594 rows TSV → Stream Load HTTP GET · JSON JDBC · MySQL wire protocol RPC CREDENTIALS secop_reader GRANT SELECT ON ALL TABLES DDL → ERROR 5203 (measured) INSIDE THE API 60 s cache · no scheduler ?refresh=true bypasses it
client API engine credentials

2 Why the middle layer cannot be skipped

It looks like an avoidable hop. It is not, and the two reasons are measured, not assumed:

AttemptResult on this build
Browser talks to StarRocks directlyImpossible. Port 9030 is the binary MySQL protocol; a browser has no TCP client and no such codec.
Use the FE's HTTP query endpoint insteadPOST :8030/api/query answers 501 Not Implemented on 3.5.21. Tried, captured, rejected.
Add a thin HTTP bridgeThe 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.

3 Inside the API

PieceWhat it does, and the rule it enforces
ConsolidadoController17 read-only GETs. Validates before touching the engine: year 2000–2026, limit 1–200, offset ≤ 100 000, search term ASCII and ≥ 2 chars.
ConsolidadoServiceCache of 60 s keyed by request, with refresh=true bypassing it. No scheduler: nothing runs in the background.
ConsolidadoRepositoryTwo 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.
StartupCheckFails 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.
ApiExceptionHandlerEngine down → 503 with {error, engine, message}; bad parameter → 400. Never a stack trace.
WebConfigCORS for http://localhost:5173 only. The engine itself never leaves loopback.

4 The seventeen endpoints

EndpointRowsShape of the answer
/resumen1Contracts, total value, buyers, suppliers, undated count, min, max, median.
/por-anio29Contracts and value per year, plus the anio = 0 bucket for undated rows.
/por-anio-stat29Same, plus percentile_approx(valor, 0.5) — the median per year.
/por-fuente2SECOP I versus II: contracts and value.
/por-anio-fuente58The same split across years, for the stacked chart.
/por-mes12Contracts and value by month of signature.
/por-anio-mes300Year × month grid for the calendar heatmap, 2000–2026.
/por-rango-valor6Six COP bands: how many contracts and how much value in each.
/por-entidad≤200Buyer codes for one year, ordered by value.
/por-departamento≤200Departments for one year.
/por-municipio≤200Municipalities, all years.
/por-contratista≤200Suppliers by value, for the concentration curves.
/por-representante≤200Legal representatives as recorded on the contract.
/distribucion-compradores5Buyers bucketed by how many contracts they have.
/texto1Substring count over the description, ASCII-normalised.
/contratos≤200Contract-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.

5 Deployment as it runs today

ContainerImagePorts (loopback only)
sr-labstarrocks/allin1-ubuntu @ sha256:faf5f6b…9030 · 8030 · 8040
my-labmysql:8.0.46 @ sha256:7dcddc0…13306 → 3306
dash-apieclipse-temurin:17-jre + the built jar8080
vite previewhost 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.

6 Decisions that are load-bearing

DecisionWhy
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 LIKEStarRocks 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 namesCollation could merge two spellings into one group on MySQL and not on StarRocks, turning a benchmark into a collation test.
No scheduled refresh, no pollingRequested. 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 startupThe API should be unable to write even if it is compromised, and unable to start half-configured.
Golden JSON fixturesFour 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.

7 Failure modes, measured

If this failsYou seeHow it was verified
StarRocks is down503 engine_unavailable naming the engineSecond container pointed at a dead port
Credentials missingProcess exits with code 1 and the missing variable namesContainer started with no environment
The API is downThe page shows a red panel, not empty chartsdocker stop dash-api, hard reload
A parameter is invalid400 with bad_request and the offending valueYear 1990 and an empty term

8 What this architecture does not do

Deliberately absent

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.

The shape of the gap

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.

Files

dashboard-api/ pom.xml Spring Boot 3.3.5 · Java 17 · web, jdbc, mysql, springdoc Dockerfile two stages, runtime carries no compiler src/main/java/co/secop/lab/ DashboardApiApplication entry point api/Envelope.java the one response shape api/Rows.java 16 records — one per query shape repo/ConsolidadoRepository 17 SQL queries, no ORM service/ConsolidadoService 60 s cache, no scheduler web/ConsolidadoController 17 GETs, validation before SQL web/ApiExceptionHandler 503 / 400 mapping web/EngineUnavailable... 503 signal config/StartupCheck fails the context on missing env config/WebConfig CORS for :5173 only src/test/java/...ContractTest 8 tests over 4 golden payloads src/test/resources/golden/ captured from the live API