Back to all posts
2026-11-255 min read

From Kubernetes HPA to $0/Month Serverless: Engineering LocalPulse

How I built a distributed cultural discovery crawler with Redis Streams, PostGIS, and Kubernetes — and then re-architected it for $0/month serverless hosting without losing production readiness.

#Kubernetes#Redis Streams#Next.js#PostgreSQL#System Design
From Kubernetes HPA to $0/Month Serverless: Engineering LocalPulse

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:

text
[ 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.
python
# 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)
LocalPulse cultural discovery results
Real-time cultural discovery results aggregated from OpenStreetMap, Reddit, Wikipedia, and Zyte

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.
sql
-- 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;
LocalPulse credit ledger and authorization flow
Double-entry credit ledger with 1-click AWS SES explorer credit grants
LocalPulse pricing and credit tiers
Explorer credit tiers backed by atomic database deductions

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.

DimensionOriginal K8s ClusterServerless Production Demo
ComputeMulti-pod K8s (FastAPI + Workers + HPA)Vercel Next.js 16 Route Handlers (/api/v1/*)
Database & AuthSelf-hosted PostGIS + RedisManaged Supabase PostgreSQL + OAuth PKCE
ObservabilityPrometheus + Grafana podsServerless 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

  1. 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.
  2. 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.
  3. Automate Seed & Fixture Snapshots: Keeping lightweight geo-fixtures makes local development and CI tests instant without spinning up PostGIS + Redis containers every time.

dispatch.preferences
Zero spam · Unsubscribe anytime

Want pings when I publish new deep-dives?

Pick your signal preference below — only real engineering breakdowns, never filler.