This is my first blog post — something I have been wanting to start for many months. Between building backend systems, experimenting with DevOps pipelines, and college coursework, writing down the why behind architectural decisions kept getting pushed to "next week." With LocalPulse, the lessons learned along the way were too valuable not to document.
Building a full-stack app is easy. Engineering a production-grade distributed crawler, running Kubernetes with autoscaling workers, and then re-architecting it for $0/month serverless hosting is where the real lessons happen.
Here is the complete engineering breakdown of LocalPulse — an intelligent cultural travel and discovery platform (GitHub & K8s Manifests).
1. The Original Architecture: Kubernetes & Event-Driven Workers
I originally designed LocalPulse as a microservices architecture deployed with Docker Compose and Kubernetes (K8s) so heavy crawling would never block user-facing HTTP requests:
[ CLIENT ] ---> [ K8s INGRESS ]
|
+-------------+-------------+
| |
[ Next.js Pod ] [ FastAPI Pod ]
|
[ Redis Streams (Queue) ]
|
[ Crawler Workers (HPA) ]
|
[ Processor Worker (Deduplication) ]
|
[ PostgreSQL + PostGIS ]- Distributed Crawler Pipeline: API requests publish scrape jobs into Redis Streams instead of running synchronous scraping inside the request cycle.
- Consumer Groups & Background Workers: Dedicated Python workers consume jobs asynchronously across OpenStreetMap, Reddit, Wikipedia, Zyte, and travel portals.
- Entity Resolution & Deduplication: A secondary processor worker handles geo-clustering, text normalization, and deduplication before persisting canonical places into PostgreSQL (PostGIS).
- Kubernetes HPA: Configured Horizontal Pod Autoscalers (HPA) to scale crawler pods up or down dynamically based on queue backpressure and CPU thresholds.
- Monitoring & Observability: Built-in Prometheus metrics and Grafana dashboards for scraper latency, queue throughput, and worker health.
# Simplified Redis Streams consumer group pattern used by crawler workers
while True:
entries = redis_client.xreadgroup(
groupname="crawler-workers",
consumername=worker_id,
streams={"localpulse:crawl_jobs": ">"},
count=5,
block=5000,
)
for stream, messages in entries:
for msg_id, payload in messages:
process_crawl_job(payload)
redis_client.xack("localpulse:crawl_jobs", "crawler-workers", msg_id)
2. Transactional Ledger & Credit Economy
To keep external crawler APIs and LLM enrichment costs under control, I built a double-entry style credit and ledger system:
- Atomic Deductions: Search and crawler operations deduct credits atomically inside database transactions to prevent race conditions under concurrent requests.
- Immutable Audit Trail: Every credit grant, deduction, and refund is recorded as an append-only ledger entry.
- 1-Click Email Authorization: Powered by AWS SES, allowing instant explorer credit grants via signed email links.
-- Atomic credit deduction preventing negative-balance race conditions
UPDATE user_wallets
SET balance = balance - $1, updated_at = NOW()
WHERE user_id = $2 AND balance >= $1
RETURNING balance;

3. The Cost Dilemma & Serverless Pivot
Running a multi-pod Kubernetes cluster 24/7 (API, PostGIS, Redis, Worker pool, Prometheus) on AWS or GCP quickly adds up to $80–$150+/month in compute and managed storage costs — unsustainable for an open portfolio demo.
Treating Cost as a System Design Constraint
Instead of shutting the project down, I treated the $0/month budget as a hard architectural constraint — keeping the Kubernetes manifests intact for self-hosted production while building a zero-cost edge deployment path.
| Dimension | Original K8s Cluster | Serverless Production Demo |
|---|---|---|
| Compute | Multi-pod K8s (FastAPI + Workers + HPA) | Vercel Next.js 16 Route Handlers (/api/v1/*) |
| Database & Auth | Self-hosted PostGIS + Redis | Managed Supabase PostgreSQL + OAuth PKCE |
| Observability | Prometheus + Grafana pods | Serverless logs & structured edge telemetry |
| Monthly Cost | $80 – $150+/month | $0/month |
By unifying the stack into Next.js 16 App Router route handlers backed by Supabase PostgreSQL (with RLS) and keeping all K8s + Docker Compose manifests in the repo, the live demo achieves sub-second edge responses at $0/month.
4. What I'd Do Differently Next Time
- Start with a Modular Monolith Before Splitting Pods: Having separate FastAPI, crawler, and processor services taught me a lot about distributed queues, but a clean modular boundary inside one service would have shipped v1 twice as fast.
- Design for Scale-to-Zero Early: Using serverless-friendly queues (like Upstash Redis or QStash) from day one avoids rewriting worker loops when moving to edge hosting.
- Automate Seed & Fixture Snapshots: Keeping lightweight geo-fixtures makes local development and CI tests instant without spinning up PostGIS + Redis containers every time.
