
Summary
Key points of this document
- Prerequisites and Design Constraints
- Overview of Overall Architecture
- Four Design Decisions to Minimize Costs
Overview
Administrative information (ordinances/regulations, public notices/bidding information, subsidies/policy announcements, meeting minutes, etc.) published by public institutions such as local governments and government agencies serves as a crucial information base for local residents and businesses. However, these documents vary in publication format (HTML, PDF, attached documents) and update timing depending on the source, making it challenging to quickly access necessary information.
When designing an application that automatically aggregates and structures such public information, allowing for cross-sectional search and browsing, the biggest engineering challenge is balancing "establishing a sustainable cost structure" and "considering the load on target servers."
If periodic crawling, full-text analysis, and AI-driven structural processing are performed without a plan, infrastructure costs for always-on containers and API call costs for external AI models will escalate, threatening service continuity. This paper explains an architectural design that achieves stable operation while minimizing operational costs by combining multi-differential detection, a two-stage pipeline, and serverless execution in a periodic synchronization pipeline for public documents.
Prerequisites and Design Constraints
Systems handling public information have unique technical constraints that differ from general web services.
- Thorough Politeness towards Target Infrastructure
Excessive request loads must not be placed on public portals or administrative servers. Strict adherence to per-second request rate limiting (Rate Limiting), exponential backoff (Exponential Backoff), rigorous control of concurrent executions, and preventing unnecessary re-access by respecting the target's cache headers are absolute requirements.
- Autonomous Operation with Minimal Operational Budget
Information provision platforms with high public utility generally find direct monetization difficult. They require robustness to operate autonomously without dedicated operators, keeping infrastructure and external API maintenance costs to a minimal scale of several thousand to tens of thousands of yen per month.
- Preventing Missed Updates and Ensuring Freshness
For bidding announcements and subsidy information, initial response immediately after publication is crucial. It is necessary to quickly and reliably detect newly added or revised documents within daily or hourly synchronization cycles.
Overview of Overall Architecture
This system adopts a pipeline configuration that loosely couples and separates three layers with different scopes of responsibility.
[Public Information Source] (Municipal Portal / Public Notice Information / Public PDF)
│
▼ (1. Change Detection: ETag / Last-Modified / Selector Hash)
[Difference Collection & Detection Worker] (Cloud Run Jobs / Scheduled Activation)
│
▼ (Only differential documents transferred)
[Extraction & Structuring Engine] (Rule-based Preprocessing ➔ Small LLM Analysis for Differences Only)
│
▼ (Normalized JSON / Metadata Storage)
[Data Storage & Search Layer] (PostgreSQL / SQLite / Object Storage)
│
▼ (Edge Cache / SSR Delivery)
[Web UI / API Client] (Cloudflare Workers / React)By eliminating always-on heavy-duty virtual machines and container clusters, and combining a job environment that starts only when needed with an edge delivery network, idle infrastructure costs are brought close to zero.
Four Design Decisions to Minimize Costs
1. "Multi-Differential Detection" using HTTP Headers and Content Hashes
The most significant cost-saving point at the very beginning of the pipeline is "not using any resources for unchanged documents."
This system thoroughly eliminates unnecessary data transfers and subsequent processing through the following multi-stage filtering:
- Stage 1: Cache Determination via Lightweight HEAD Requests
For the target URL, a HEAD request is first sent to retrieve HTTP response headers (ETag and Last-Modified) are retrieved. If the values match the previous synchronization time, processing is immediately completed without downloading the body (HTML or PDF content).
- Stage 2: SHA-256 Hash Matching Limited to Body Extraction Area
Many target sites include dynamic elements such as sidebar access rankings and current date/time in the footer. Hashing the entire page's HTML would lead to false positives, incorrectly indicating "updated" even if the document body has not changed.
Therefore, only the main content area containing the body (main body container or specific document nodes) is extracted using a selector, and a SHA-256 hash is calculated for the normalized string and compared with the previous hash value.
- Stage 3: Binary Metadata Comparison for PDFs, etc.
For attached PDFs, before downloading, HTTP Content-Length and Last-Modified are matched, and only if changes are suspected, the file is streamed and a binary hash is calculated.
This multi-stage detection allows us to narrow down the number of documents that actually proceed to body analysis and subsequent pipelines to less than a few percent of the total, even in environments monitoring thousands of pages daily.
2. Two-Stage Pipeline: Rule-Based Preprocessing and Pinpoint AI Analysis
When extracting metadata such as title, publication date, responsible department, target region, category, and importance from collected documents, indiscriminately feeding everything into a Large Language Model (LLM) would cause token-based charges to skyrocket.
Therefore, the structural processing has been separated into two stages: "deterministic rule-based processing" and "semantic interpretation by AI models."
- First Stage (Rule-Based, High-Speed Preprocessing):
Using regular expressions, HTML meta tags, Microdata/JSON-LD, and morphological analysis, fixed patterns such as dates (Japanese calendar/Western calendar conversion), notification numbers, and contact information are extracted at high speed. Approximately 70% of all standardized public notices can satisfy the necessary metadata requirements with just this first stage.
- Second Stage (Differential-Limited Small LLM Structuring):
This stage targets only the generation of non-standardized body summaries, long documents with ambiguous classification categories, and differential documents containing complex tables. It invokes a lightweight model with a small number of parameters (or a small model with excellent cost performance) by applying strict JSON Schema constraints.
By passing the metadata extracted in the preceding step as context to the prompt, we minimize the number of generation tokens required from the model, suppressing LLM-related API costs to less than 5% of the total.
3. Compute Optimization with Serverless Batch and Lightweight Runtimes
If batch collection processes are run on always-on containers (e.g., container instances running 24/7), infrastructure base charges continue to accrue even during idle times when no processing is occurring.
In this system, we adopt Cloud Run Jobs as the execution platform for synchronous processing, configured to be triggered periodically by Cloud Scheduler.
- Billed only during execution: CPU and memory are allocated only for tens of seconds to several minutes, from batch startup until processing completion, after which resources are immediately deallocated.
- Adoption of Lightweight Binaries: For the pipeline's core processing engine, we adopt a lightweight language (Go language) with a small memory footprint and extremely fast startup times. By suppressing startup overhead to milliseconds and setting container memory allocation to a minimum (512MB-1GB), we keep the compute cost per job to a few cents.
4. Compression of Serving Costs through Static Caching and Edge Delivery
In the frontend and API layers for search and browsing, we leverage an edge network (Cloudflare Workers + Edge Storage/CDN) to minimize the frequency of direct queries to the database.
Pre-generation of Aggregated Indexes:
Highly frequently updated public summary and category-specific list data are pre-generated as static JSON upon completion of synchronous batches and placed in object storage (R2/GCS).
Instant Response via Edge Cache:
Since most user requests are returned directly from the edge cache, the number of connections and read load on the backend relational database (e.g., PostgreSQL) dramatically decreases. This makes it possible to maintain the DB specifications at their minimum configuration.
Verification Points and Operational Pitfalls
In operating this architecture, key verification points and countermeasures to be particularly mindful of are as follows:
Resilience to structural changes in target websites (DOM breakage)
There is a risk that text extraction by selectors may fail due to website redesigns or minor markup changes on public sites.
This system incorporates a safeguard that flags "extraction anomalies" when the character count or structure of a text node changes drastically, issuing alerts while retaining the previous cached data. Preventing silent data loss or empty updates is crucial.
Temporary Network Failures and Error Classification
For temporary 503 errors or timeouts from the target server, it should not be immediately determined as "document deletion." We adopt a state transition design that clearly classifies HTTP status codes into "retryable (5xx, 429, timeout)" and "permanently unreachable (404, 410)," setting a logical deletion flag only when 404 is confirmed multiple times consecutively.
Summary: Design Decisions for Building a Sustainable Data Foundation
| Design Area | Traditional Approach | This System's Design Approach | Cost/Operational Benefits |
|---|---|---|---|
| Change Detection | Crawl all pages and fetch full text every time | HEAD request + hash limited to body area | Reduces communication traffic and documents to be analyzed by over 90% |
| Data Delivery | DB query and dynamic generation for every request | Pre-generation of aggregated data + edge cache | Achieves both minimal DB load and ultra-fast responses |


