Highly Optimized URL Shortener
Engineered with Go and Redis. Paste your long URL below to experience a robust, gracefully scaling, and highly available shortener.
Engineering Decisions & Architecture
A deep dive into system design
Trade-offs, scalability patterns, and infrastructure choices that make our Go-based engine incredibly robust.
Write-Contention Buffering
Instead of hitting Postgres on every link click, reads are buffered in a Redis Hash via a non-blocking Go channel and flushed every 60s. This ensures a viral link receiving 10,000 clicks/min results in exactly 1 database write, protecting Postgres from write-locks.
Read-Through Caching
Redis acts as the primary read layer. Cache misses gracefully fall back to Postgres and automatically populate Redis. Subsequent reads bypass the database entirely, protecting the primary data store during read spikes.
Single-Binary SPA Deployment
The Astro SPA is statically compiled and injected directly into the Go backend using //go:embed. It ships as a single, self-contained binary without needing a separate Nginx server, drastically simplifying CI/CD and infrastructure overhead.
Enterprise Observability
Fully instrumented with the OTel SDK. It provides explicit bucket histograms for exact latency percentiles (p95, p99) and custom resource collectors for connection pools, demonstrating operational maturity beyond basic HTTP logs.
Collision-Free Short Codes
Uses the sqids-go library coupled with a Postgres SEQUENCE. This mathematically guarantees 100% collision-free codes natively, completely eliminating the need for expensive database collision checks or while-loop retries.
Graceful Shutdown & Cron
Internal context-aware cron scheduler manages purging. sync.WaitGroup worker lifecycles ensure that upon receiving a SIGTERM, all in-flight channel buffers are safely flushed to Postgres before exiting, guaranteeing zero data loss.