Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URSwag Shortener

A distributed URL shortener made using Golang, Kubernetes and Docker. This project was developed to be self-hosted using Minikube but can be modified for use with other container orchestration tools.

🚧 Still a work in progress 🚧

Rationale

Initially, this project was created as a means of learning how to use Golang by developing the tried and true backend project, a URL shortener.

However, not wanting to create another boring generic project, I decided to use this opportunity to learn about Docker and Kubernetes by containerizing and automating scaling and deployment of the application (in practice at least...).

Although I wouldn't take this entire setup into a production environment, it serves as a nifty little POC as to how someone might go about scaling a web service.

Architectural Overview

Diagram

URSwag Architectural Diagram

Details

The URL shortener is a Golang HTTP Server that communicates with a PostgreSQL database to read and write URLs which are encoded using Base62.

This server is packaged into a Docker image and containerized so it can be run through Docker, with database migrations being handled with Flyway.

Using Kubernetes, we can host and deploy our containerized server along with our database, which can be scaled up and down based on traffic and resource load. These pods communicate with each other using their associated services (primarily the server and database services).

We are using NGINX Fabric Gateway as a load balancer for our application which handles inbound requests from clients and routes them to the server pods.

Basic Flow

  1. A user will make a request to the URL shortener service

  2. It will first handled by the gateway where the request will be load balanced across the available pods

  3. The request will be processed by the server service and route to the corresponding pod where the server will handle the request

  4. Any database operations are handled via the database service and response is send back to the user

Setup & Installation

Prerequisites

Running Locally

All you need to do is compose up and down in the root directory. Images will be pulled and built automatically.

docker compose up

Kubernetes

Assuming you are using Minikube, use kubectl to apply all config files to your cluster

kubectl apply -f route/to/directoryOrFile

Note: Ensure that nginx-ingress is installed and ingress is enabled in Minikube. You can do this using Helm.

What's Next?

  • Add Redis cache for frequently accessed URLs (another learning experience)
  • e2e tests
  • Incorporate migrations into k8 deploynment
  • Probably swap to Gateway API

License

MIT

About

URL Shortener made with Go, Docker and K8's

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages