Background: In the quest for a straightforward link shortening solution tailored to personal needs, I encountered the frustration of encountering extraneous ads and unwanted tracking features in nearly every application I tried. Determined to find a no-nonsense solution, I embarked on creating my very own link shortener in 2021 initially intended solely for personal use.
Utilizing Next.js for both link creation and redirection, complemented by a Flutter app for convenient link generation, my initial setup seemed to meet the requirements. However, a hurdle surfaced as the use of Prisma with Next.js resulted in slightly delayed redirects. While contemplating the integration of a Redis server for caching, financial constraints made it impractical to pursue this enhancement, leaving the system without a caching mechanism.
The Journey Continues: Fast forward to the present year, a decision was made to overhaul the application, prioritizing speed and user-friendliness. The entire system underwent a comprehensive rewrite with a newfound commitment to providing a free and accessible link shortening solution for everyone. The primary objective was clearβto create a scalable link shortener devoid of unnecessary tracking and advertising.
The evolution led to the birth of Songkhep, a revolutionary link shortener designed to simplify and enhance the user experience. Stripping away the complexities of tracking and advertising, Songkhep aims to deliver a seamless, efficient, and entirely free link shortening service.
Key Features in mind:
- Speed and Efficiency: The reimagined architecture ensures swift redirects, eliminating the delays experienced in the previous version.
- User-Friendly Interface: an intuitive and easy-to-use interface, catering to both tech enthusiasts and casual users alike.
- Scalability: effortlessly scale with growing user demands.
Backend Infrastructure
The backbone of the system lies in the serverless backend, powered by Golang with the Fiber web framework, running on Azure Functions. This serverless runtime ensures optimal resource utilization and effortless scalability, allowing the system to handle varying workloads seamlessly.
For robust data management, I chose Azure Cosmos DB as the database solution. Its flexibility and scalability perfectly complement the serverless architecture, enabling the system to efficiently handle the storage and retrieval of URL data.
URL Redirection with Cloudflare Workers: To handle URL redirection, Cloudflare Workers take center stage. When a user attempts to access a short URL (e.g., songkhep.monzim.com/:slug), the Cloudflare Worker checks the KV cache for relevant data. If the data is not found, it seamlessly communicates with the backend server to retrieve the necessary information.
Efficient Caching Strategy: To optimize performance, the Cloudflare Worker caches the retrieved data in the KV store, ensuring quick access for subsequent requests. This caching mechanism is set to expire after 7 days, striking a balance between speed and data freshness.
API Integration for URL Shortening: The main website interfaces with the backend server through an API, allowing users to create new short URLs effortlessly. The API is secured with an API key and supports Cross-Origin Resource Sharing (CORS), ensuring a secure and accessible experience for users.
Conclusion: The Songkhep architecture represents a harmonious blend of cutting-edge technologies, offering a scalable, fast, and user-friendly URL shortening solution. Whether you're a developer looking for inspiration or a user in need of a reliable URL shortener, Songkhep stands out as a testament to the power of thoughtful architecture and innovative technology integration.

