Computer-based language and civic exams are deterministic, read-heavy workloads. In the Dutch civic integration (Inburgering) system administered by DUO, core modules such as Kennis van de Nederlandse Maatschappij (KNM, 40 questions in 45 minutes) and Lezen (Reading A2, 25 questions in 65 minutes) consist of fixed Dutch prompts, short source texts, and four-option multiple-choice items.
Querying a relational database on every question transition introduces unnecessary tail latency and connection state on mobile networks. When engineering InburgeringMock as a reference practice platform, we eliminated origin database reads during active exam sessions by combining build-time JSON compilation, a deterministic client-side state machine, edge entitlement gating, and structured machine-readable metadata.
1. Static-First Question Bank JSON Schema
Civic integration prep presents a dual-language data modeling problem: questions and reading passages must remain in authentic CEFR A2/B1 Dutch, while international test-takers need option-by-option explanations in plain English alongside optional vocabulary scaffolding. Additionally, the UI must render both single-pane situational items—such as those in the KNM practice exam—and split-screen reading comprehension passages (municipal letters or workplace notices) from one normalized schema.
export interface ExamItem {
id: string;
module: 'knm' | 'reading_a2';
theme: string;
cefr: 'A2' | 'B1';
passage?: {
genre: 'official_letter' | 'workplace_notice';
bodyNl: string;
};
stemNl: string;
keywordHints: Array<{ termNl: string; glossEn: string }>;
options: Array<{ id: 'A' | 'B' | 'C' | 'D'; textNl: string }>;
correctId: 'A' | 'B' | 'C' | 'D';
rationalesEn?: Record<'A' | 'B' | 'C' | 'D', string>;
officialSource?: { label: string; url: string };
}
When passage is present, the test runner deterministically switches into a dual-pane desktop layout (and collapses cleanly into a zero-overflow vertical stack on 375px viewports) without layout shift. Freemium rationale gating is enforced at build serialization rather than via CSS hiding: in a 10-question diagnostic where Q1–Q3 explanations are free and Q4–Q10 are locked, the public diagnostic JSON bundle strips rationalesEn and officialSource from Q4–Q10 so gated content is never leaked in DevTools network payloads.
2. Deterministic Client-Side State Machine and Scoring
Interactive exam runners commonly fail on subtle lifecycle bugs: timers ticking before mode selection, setInterval drift when mobile browsers background a tab, or accidental early submissions. Modeling the session as a finite state reducer prevents invalid state combinations:
type ExamState =
| { phase: 'SETUP'; mode: 'timed' | 'practice' }
| { phase: 'ACTIVE'; mode: 'timed' | 'practice'; deadlineMs: number | null }
| { phase: 'CONFIRM_SUBMIT'; unanswered: number; deadlineMs: number | null }
| { phase: 'RESULTS'; breakdown: Record<string, { hit: number; total: number }> };
Three invariants govern state transitions:
-
Explicit clock initialization: Rendering the landing preview or toggling between Timed and Practice modes in
SETUPnever starts a background countdown;deadlineMsinitializes strictly when the user dispatchesSTART_EXAM. -
Monotonic wall-clock deltas: Remaining time is derived from
Math.max(0, deadlineMs - Date.now()), ensuring mobile tab switches (visibilitychange) neither drift the timer nor trigger false auto-submissions. -
Early-submission guard: Dispatching
REQUEST_SUBMITwith unanswered items transitions toCONFIRM_SUBMITrather than finalizing the score immediately, prompting explicit confirmation before grading.
Client-side scoring executes as a pure reduction over user responses in under 1ms, computing overall accuracy alongside KNM and Reading A2 sub-scores while surfacing an explicit notice that 70% is a study benchmark rather than an equated DUO pass cutoff.
3. Edge Consent and Entitlement Gating
Static HTML shells and public diagnostic JSON bundles are served from edge nodes (Cloudflare Workers) with Cache-Control: public, max-age=0, s-maxage=86400, keeping global Time to First Byte below 30ms. Anonymous visitors can run the 10-question diagnostic (6 KNM + 4 Reading) immediately without login walls, and edge consent gating ensures zero non-essential cookies or analytics scripts execute prior to explicit opt-in.
When a user unlocks full mock exams or gated diagnostic explanations, an edge Worker verifies an HMAC-signed HttpOnly entitlement cookie before streaming the protected rationale JSON from edge storage. On preview and staging domains, the Worker inspects the request host header to short-circuit live payment initialization cleanly during automated Playwright tests.
4. Machine Readability: schema.org/Quiz and llms.txt
Statutory exam requirements differ across immigration cohorts, such as the A2 versus B1 pathways documented in our DUO 2026 rules engineering reference. Making assessment items and regulatory specs parseable by search crawlers and LLM retrieval pipelines requires two static build artifacts:
-
JSON-LD Quiz structured data: Public sample items rendered visibly in HTML are paired with
schema.org/QuizJSON-LD declarations mapping questions, accepted answers, and CEFR alignment. -
/llms.txtmanifest: A static Markdown manifest at/llms.txtindexes canonical practice routes, official exam durations, and primary Dutch government references (UWV, Rijksoverheid, DUO) so retrieval agents ingest structured facts rather than scraping UI controls.
Pairing edge-cached JSON bundles with deterministic client reducers and explicit structured metadata keeps infrastructure costs predictable even under spiky exam-season traffic.
Top comments (0)