Two years of data freshness20242025202696.8%91.8%94.3%92.6%93.6%98.3%98.8%98.2%99%99.3%99.1%94.9%99.8%99.8%96.8%99.8%97.7%99%99.3%94.2%98.4%97.7%99.8%99.4%
Illustration: daily values are synthetic, the marked events are real and come from the project history. Each dot is a day: the share of 15-minute file updates that met the freshness rule (data at most two cycles old).

← Work

CASE 03 · PRODUCTION · ONGOING

Nationwide availability pipeline

Prices and availability for 99.5% of Ukraine's pharmacies, kept fresh every 15 minutes on home hardware: about 200 million rows a day, in production since 2024.

  • 200Mrows a day
  • 99.5%of Ukraine's pharmacies covered
  • 15 minoutput refresh, data at most two cycles old
Role
Co-founder; designed and built it alone
Team
Solo
Stack
Python · PostgreSQL · curl_cffi · Selenium · NumPy · pandas · multiprocessing

Problem

A price-monitoring product needs current prices and availability for medicines in almost every pharmacy in Ukraine. The only nationwide source is a price-comparison site whose JSON API answers one product around one location at a time, with strict limits per session. The output file has to be refreshed every 15 minutes, a full pass over the catalogue takes about six hours, and the file may only hold data from the last two passes.

Data

About 4,600 products, queried around 28 points across the country, three full cycles a day between 5:00 and midnight: around 200 million rows a day. Every response is a list of pharmacies with price and location, so the same pharmacy comes back for thousands of products.

Approach

Each part of the problem got its own fix, measured before and after.

Sessions and proxies. Five worker processes, each with its own proxy line. Rate limits are expected, so a worker that hits one retries only the failed products and changes its IP inside the same browser session instead of restarting the browser. That raised useful work per browser launch from about 0.6 to 10–14 batches. I moved the proxy lines physically to Ukraine and run them myself on USB modems, one SIM card per line; since then the site no longer blocks us and only answers “too many requests” when we go too fast. Failover works per line, and a guard samples every line every four hours: once a line kept answering but recycled the same 4 IPs for more than 100 launches, which no connectivity check could see.

Database. Workers write to a staging table and a validator moves the rows into the main table. In July the staging table grew to 97.8% dead rows, the validator slowed down, and the stale-data cleanup started deleting fresh rows. I replaced in-place deletes with an atomic swap: the live staging table is renamed in one step, drained newest-first in chunks and truncated, and the upsert never lets older data overwrite newer. In November I split the main table into a narrow price table (product, pharmacy, price, time) and a pharmacy directory with coordinates. Measured on a copy of production: the table shrank from 5.6 GB to 2.37 GB, upserts became 3.3 times faster, and the validator went from about 8,000 to 23,000 rows per second. The database stopped being the bottleneck. A golden-file test shows the export is identical before and after the migration.

Coverage. After the site changed how its API returns data, the pipeline started losing about 8% of product–pharmacy pairs without a single error. The cause: each response holds only the pharmacies nearest to the query point, so popular products fill up inside regional centres and distant towns drop out (one regional city showed 33 of its 300 pharmacies). I ran a coverage pass of 170 candidate points × 460 sampled products, chose the query points with integer programming under the rule that no community may end up worse covered than before, and checked the choice on a held-out half of the products. The missing 8% came back, and a daily coverage report now raises an alert when the totals drop.

Running unattended. A supervisor starts the workers, the validator and the export, and restarts anything that crashes; a watchdog restarts the supervisor. Every night the database is checked for bloat and vacuumed when it needs it, and a log analyser reports throughput, rate limits and each worker’s progress.

Architecture

  • Supervisor → five workers, each with its own proxy line, browser session and HTTP client.
  • Workers → staging (two tables swapped atomically) → validator → main tables (prices and a pharmacy directory).
  • Export every 15 minutes into the delivered file.
  • Around it: proxy guard, daily coverage report, nightly database maintenance, log analysis.
  • All of it runs on home hardware: one laptop and five USB modems.

Results

About 200 million rows a day from 99.5% of the country’s pharmacies, with the file updated every 15 minutes and never older than two cycles. In production since August 2024. Each incident above was found, explained and fixed, and each fix came with tests.

What I’d do differently

Split the database from day one into a hot price table and a pharmacy directory. That single decision moved the bottleneck off the database, and it would have saved months of tuning around it.

Measure coverage from the start, not just errors. Losing 8% of the data silently is worse than crashing, because nothing tells you.