TL;DR — Pinning one upstream hostname at nginx startup caused site-wide
504timeouts every time a container rotated. That single line in an edge proxy config was one of five production failures we had to close while migrating Indonesia’s national TKDN (Tingkat Komponen Dalam Negeri) registry from a six-year PHP monolith to Axum + Leptos 0.8 SSR, a Golang headless CMS, and a Cloudflare D1 read-through replica. Today, tkdn.kemenperin.go.id serves 143,980 certificates (83,606 active) with zero JavaScript required for indexable HTML and sub-second faceted search.
Contents
- 1. Why a Six-Year PHP Monolith Hit a Wall
- 2. Five-Arc Engineering Timeline (Sep–Dec 2026)
- 3. Why Pinning One Upstream IP Caused Site-Wide 504s
- 4. Keeping Neon Asleep with a Cloudflare D1 Read-Through Replica
- 5. Closing the Fast-First-Search 403 Race with ALTCHA PoW
- 6. Bounding SSR Memory Before Crawlers Hit the Semaphore
- 7. Preventing Stale WASM Traps and Hydration Mismatches
- 8. What Broke Along the Way & Key Trade-Offs
1. Why a Six-Year PHP Monolith Hit a Wall
For six years, Kemenperin’s TKDN site ran as a server-rendered PHP/MySQL monolith (search.php, sertifikat_ik_idx.php, rekap.php, regulasi.php). Every public page rendered per-request against the same database tables that held the certificate registry, and every editorial or org-chart update required a code deploy.
When procurement officers and manufacturers verify a TKDN score—such as the Material 75% + Tenaga Kerja 10% + Overhead 15% + BMP breakdown under Permenperin 35/2025 Pasal 4—trust is a latency problem. If a lookup stalls or a regulation table drifts out of date, users fall back to manual PDFs and phone calls.
We split the platform into two decoupled halves:
| Layer | Responsibility | Key Contract |
|---|---|---|
Axum 0.8 + Leptos 0.8 SSR/WASM (tkdn-web) | Server-rendered HTML for SEO + progressive WASM hydration for interactive tools | curl -s / \| grep Title works with zero JS; /kalkulator, /sertifikat, /cari, /kapasitas hydrate in-browser |
Golang Headless CMS + CmsRepository | Structured pages, regulations, infographics, media, and org-chart nodes in Postgres | Syncs TKDN and LVI records directly from SIINas—staff never re-key certificate data |

Live /infografis dashboard rendered via Leptos 0.8 SSR with synced SIINas certificate metrics, issuance volume, and sector distributions.
2. Five-Arc Engineering Timeline (Sep–Dec 2026)
Instead of a single big-bang cutover, the platform evolved across five documented engineering arcs, culminating in 76 commits across 20 active days in November 2026:
| Arc | Period | Scope | Core Deliverable |
|---|---|---|---|
| 01. Bootstrap | Sep 9–11, 2026 | 12 commits | Axum + Leptos SSR scaffold, Render PORT bind rule, fail-soft lazy-DB boot, Neon/PgBouncer statement-cache hardening |
| 02. Content Build-Out | Oct 19, 2026 | +4,981 / −834 lines | Public routes (/inventarisasi, /regulasi, /tentang), OKLCH @theme tokens, JSON-LD + sitemap.xml |
| 03. CMS Integration | Oct 20, 2026 | +7,470 / −894 lines | Bidirectional CmsRepository (direct Postgres read arm + Go API client), staff auth, /api/snapshot |
| 04. Hardening Era | Oct 21–Nov 1, 2026 | 16+ commits | Branded error layers, CSP nonces, /kalkulator F.1.4 rework, self-hosted ALTCHA PoW, html_cache, cold-SSR Suspense fix |
| 05. Scale & Expansion | Nov 3–Dec 1, 2026 | 76 commits | Box<str> memory cuts, D1 replica, tkdn-edge 504 fix, /cari FTS, /capaian, /referensi, /kapasitas, 21 SVGs |
Daily commit cadence across November 2026—76 commits landed across resilience, PoW defense, and new public surfaces.
Diff distribution across app/ pages, server/ gates, Cloudflare workers, and documentation.
3. Why Pinning One Upstream IP Caused Site-Wide 504s
On 2026-11-13, the tkdn-edge nginx proxy began returning site-wide 504 Gateway Timeout errors whenever Railway rotated backend container IPs.
Root cause: proxy_pass pointed directly at a static upstream hostname. nginx resolved that hostname once at startup and pinned the stale IP until the proxy itself restarted.
The fix:
- Per-request DNS resolution: Switched
tkdn-edge.conf.templateto an explicitresolverpaired with a variable-backedproxy_pass, forcing fresh DNS lookups on every request. - Dual-stack private mesh: Bound
API_INTERNAL_URLover Railway’s private network so internal CMS calls skip public egress while media URLs stay browser-resolvable. - Public-origin fallback: Added an automatic public-origin retry when the private-mesh transport fails at connect.
Dynamic upstream DNS resolution in tkdn-edge paired with dual-stack private-mesh transport and /api/version freshness checks.
4. Keeping Neon Asleep with a Cloudflare D1 Read-Through Replica
Public certificate registries are overwhelmingly read-biased. Without an edge read layer, every anonymous GET /sertifikat or GET /infografis woke serverless Postgres and ran full-table facet aggregates before painting the first row.
The fix (2026-11-04):
Client ─▶ tkdn-edge (10r/s, 30 conn/IP, dotfile 444)
└─▶ App (velocity_gate, PoW gate)
└─▶ edge_key() eligible GET?
├─ NO (POST / Bearer / verify / export) ─▶ CMS / Postgres
└─ YES ─▶ D1 Worker (4s timeout, 300s STALE_TTL)
├─ HIT ─▶ JSON (Neon stays asleep)
└─ MISS ─▶ CMS / Postgres fallback- D1 Read-Through Replica (
edge_get()): EligibleGETrequests query a Cloudflare D1 worker (EDGE_READ_URL,300s STALE_TTL, 4-second timeout) before touchingCmsRepository. Cache hits never wake Neon. - Strict Exclusions (
edge_key()): Non-GETs, bearer-authenticated requests, token-parameterized queries,/verifyendpoints, and/exportroutes bypass the shared replica so bulk exports never serve stale data. - Split Row and Facet Queries: We split
load_sertifikat_pageintoload_sertifikat_rows(indexedLIMITquery, render-blocking) andload_sertifikat_facets(tab-keyed aggregates). Filter edits no longer re-scan facets or block initial paint.
Read-through replica flow and edge_key() exclusion boundaries.

/sertifikat rendering indexed certificate rows independently of tab-level facet counts.
5. Closing the Fast-First-Search 403 Race with ALTCHA PoW
Our initial 30 req/min per-IP scrape_guard stopped naive bots, but legitimate users behind shared corporate NATs hit 429s. When we added a Proof-of-Work (PoW) widget, fast typers who submitted a search immediately after page load hit a 403 race before the background challenge finished solving.
Design rule: Security controls that degrade legitimate first-interaction UX get bypassed or disabled. Self-hosted PoW had to be invisible to normal users and deterministic under load.
The fix (2026-10-31 & 2026-11-04):
- Built
server/src/challenge.rs, a self-hosted ALTCHA-compatible PoW verifier with zero third-party CAPTCHA calls (/api/challenge,/api/issue). - Replaced naive
==token checks with constant-time MAC comparison and enforcedCache-Control: no-storeon challenge endpoints to prevent shared-cache replay. - Added a client-side clearance promise (
arm_gate_formsdocument-capture submit handler) in<PowCheck/>so fast first searchesawaitclearance cleanly instead of racing into a403. - Upgraded cleared browsers from
30 req/minto300 req/min, while uncleared traffic shares fingerprinted120/minbuckets so mobile IP rotation cannot mint fresh quotas. - Protected bulk
/export_excel*downloads behind a hard/unduhinterstitial.

/unduh hard gate verifying human clearance before releasing bulk dataset exports.
6. Bounding SSR Memory Before Crawlers Hit the Semaphore
Even with D1 caching, cache misses and uncached search queries hit the Rust SSR server. During crawler bursts, unbounded concurrent Leptos renders spiked memory usage.
The fix (2026-11-07 & 2026-11-11):
velocity_gate(120/min): Sits outside the render semaphore so aggressive crawlers are rejected before they claim an SSR slot.MAX_INFLIGHTsemaphore (64 → 32): Caps peak SSR concurrency inside the 30-secondrequest_timeout, backed by companion caps (SIINAS_PAGE24→12,VERIFY128→48,BMP_EXPORT4→2,SSE_SLOTS1024). Overflow degrades to a branded503instead of an OOM crash.- 256-entry
html_cache(~96 MB ceiling): Serves anonymous SSR HTML with stale-on-error fallback, whileevents::invalidate()purges bothhtml_cacheandSITEMAP_CACHEon CMS saves.
Concurrency gating and stale-on-error html_cache protection.
7. Preventing Stale WASM Traps and Hydration Mismatches
Deploying a Leptos SSR + WASM app introduces a subtle failure mode: if a user’s browser serves a cached .wasm binary from an older deploy against newly rendered SSR HTML, hydration traps.
The fix (2026-11-03 & 2026-11-13):
- Shared
TKDN_BUILDstamp: Compiled into both the SSR server and WASM hydrate targets. /api/versionfreshness loop: Polled every 5 minutes by the client (Cache-Control: no-store); on aBUILD_IDmismatch, the client purges Cache Storage and prompts a reload.- Cold-SSR
Suspensefixes: Wrapped conditional<Editable>and<PendingSections>arms and/rekapitulasiexport dialogs in explicit<Suspense>boundaries, and guarded disposed signals on route transitions.

/kalkulator single-column Permenperin 35/2025 Pasal 4 worksheet with live F.1.4 recap dock.
8. What Broke Along the Way & Key Trade-Offs
- Render
PORTbinding & PgBouncer: Early September deploys failed health checks until Axum bound dynamically toPORTwith fail-soft lazy DB startup and disabled prepared-statement caching for Neon/PgBouncer transaction pooling. - Scoped
ILIKEsequential scans: Addingmerk,tipe,HS,LVI, andKBLIfilter chips initially bypassedsearch_blobindexes. Binding each chip to its own column alongside ablob_guideGINANDclause restored bitmap-index scans. - D1 staleness window: Accepting a
300s STALE_TTLon public read models kept Neon asleep, but required strictedge_key()exclusions so/verifyand/exportnever serve stale results. cargo-leptosCI ergonomics: Keeping SSR and WASM in sync required pinningwasm-bindgen-cliagainstCargo.lock, usingcargo-cheflayers inDockerfile.musl, and gating PRs oncargo audit,sqlxoffline checks, and Criterion hot-path benchmarks.
Continue Exploring
- Live Registry: tkdn.kemenperin.go.id
- Full Case Study & 3-Era Timeline: TKDN Website — Kemenperin Case Study
- Developer Architecture Handbook: TKDN Engineering Handbook & ADRs