Case study · United Nations (UN)
Rescuing a large private data-collection programme
This was a separate engagement, on a different programme and at a different time from the WFP work. I took over a large, restricted data-collection project running on fragile infrastructure. I rebuilt it so 140M records could be collected without outages and reach analysts within minutes.
- 140Mrecords collected
- < 5 minfrom submission to analyst view, down from 36 hours
- 3 sfor key analytical queries, down from 40 minutes
- 99.95%uptime, up from 94%
Challenge
- Volume had far outgrown the original setup: a few hand-configured servers, manual deployments, untested backups and outages most weeks.
- Analysts needed fresh data quickly, but queries across the full dataset took tens of minutes or timed out.
- The data was restricted, so encryption, network isolation, access logging and data residency were requirements from day one.
What I built
- An audit of the existing estate, then a phased migration that kept collection live the whole time, with no lost submissions.
- The whole environment as code: private VPCs, no public database endpoints, KMS encryption, secrets in Vault, and nightly backups restored automatically to prove they work.
- A Kafka-based ingestion path that absorbs collection bursts, retries safely and scales Go workers horizontally.
- Separate write and read paths: operational records in PostgreSQL, streamed continuously into ClickHouse for analysis and S3 for long-term storage.
- Partitioning, materialised views and pre-aggregations, so common analytical queries return in seconds.
- CI/CD, health checks, central logs and metrics, and on-call alerting, replacing manual fixes over SSH.
Stack
Go, Python, PostgreSQL, ClickHouse, Apache Kafka (Amazon MSK), Redis, AWS (EKS, S3, KMS, VPC, IAM), Terraform, HashiCorp Vault, Argo CD, Prometheus, Grafana, Loki.
System design
The rebuild split one overloaded server into a stream with three consumers: an operational database, an analytics store and an archive. Each can scale or fail without stopping collection.
- Collection API: a Go service on EKS receives submissions over TLS, checks authentication and the schema, writes each one to Kafka with acknowledgement from all replicas, and returns 202. Redis holds recent request IDs for a short window, so a client retrying the same submission is recognised at once.
- Kafka backbone: Amazon MSK topics are partitioned by programme and site, replicated three times, and kept for 7 days, so any consumer can replay after a fault or a bug fix.
- Operational writes: Go consumers write to PostgreSQL (Amazon RDS) in batches, as upserts keyed on record ID. Kafka offsets are committed only after the database commit, so a crash replays a batch rather than losing it, and the upsert makes the replay harmless.
- Analytics: ClickHouse reads the same topics through its Kafka engine and materialised views, into MergeTree tables partitioned by month and sorted by programme, site and time. Aggregating views keep running totals up to date, so common questions read a few thousand pre-summed rows instead of 140M raw ones. Data reaches analysts within minutes of submission.
- Archive: an hourly Python job writes records to S3 as Parquet files for long-term storage and reprocessing, with lifecycle rules moving old data to Glacier.
- Security boundary: everything runs in private subnets with no public database endpoints, and admins reach it through AWS Systems Manager instead of open SSH. KMS encrypts MSK, RDS, EBS and S3. Vault issues short-lived database credentials, services use IAM roles, and every analyst query is logged.
- Migration: the new collection API ran beside the old servers. Historical data was copied across, then traffic moved site by site through weighted DNS. Daily record counts were compared between old and new before each site was cut over, so no submissions were lost.
- Delivery and operations: Terraform defines the infrastructure and Argo CD deploys the applications from Git. Prometheus and Grafana track request rates, errors and Kafka consumer lag, and Loki holds the logs. Backups are restored every night into a scratch environment and checked by row count.
Results
- Scale: 140M records collected, at peaks of 25,000 submissions a minute
- Freshness: submission to analyst view from 36 hours down to under 5 minutes
- Query speed: key analytical queries from 40 minutes down to 3 seconds
- Reliability: uptime from 94% to 99.95%, with zero data loss during migration
- Delivery: from monthly manual releases to about 30 automated releases a week