• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created 12 months ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This URL shortener service, built with Go and Hexagonal Architecture, leverages a serverless approach for efficient scalability and performance.

Golang URL Shortener

Cover image

This URL shortener service, built with Go and Hexagonal Architecture, leverages a serverless approach for efficient scalability and performance. It uses a variety of AWS services to provide a robust, maintainable, and highly available URL shortening service.

Functional Requirements

  • Shortening URLs: Users should be able to input a URL and receive a shortened version.
  • URL Redirection: When accessing a shortened URL, users should be redirected to the original URL.
  • Analytics: Provide analytics for each shortened URL, including click counts and basic usage stats.
  • API Access: Offer API endpoints for creating, retrieving, and managing shortened URLs.
  • User Notifications: Send notifications for specific actions like URL creation or deletion (Slack).

Non-Functional Requirements

  • Scalability: The system must automatically scale to handle varying loads.
  • Performance: High performance in URL redirection and shortening operations.
  • Reliability: Ensure high availability and fault tolerance.
  • Security: Implement security measures to prevent unauthorized access and abuse.
  • Maintainability: Code should be well-organized, documented, and adhering to Hexagonal Architecture principles for easy maintenance.
  • Monitoring and Logging: Implement comprehensive monitoring and logging for troubleshooting and performance tracking.

Features

  • URL Generation: Create shortened URLs efficiently.
  • Redirection: Redirect users to original URLs via shortened links.
  • Stats: Gather and display usage stats of shortened URLs.
  • Notification: Notify users or systems of certain actions or events.
  • Deletion: Safely remove shortened URLs and their associated data.

Prerequisites

  • Go (Golang) installed on your system.
  • AWS SAM CLI for deploying serverless functions.
  • Access to AWS Lambda and related AWS services.

Technologies Used

  • Go (Golang): The primary programming language used for development.
  • AWS DynamoDB: A NoSQL database service used for storing and retrieving data efficiently.
  • ElastiCache(Redis): An in-memory data structure store, used as a cache and message broker.
  • AWS CloudFormation: A service for defining and deploying infrastructure as code, ensuring consistent and repeatable architectural deployments.
  • AWS SQS (Simple Queue Service): A message queuing service used to decouple and scale microservices, distributed systems, and serverless applications.
  • GitHub Actions: Automated CI/CD platform used for building, testing, and deploying code directly from GitHub repositories.
  • AWS Lambda: A serverless compute service that lets you run code without provisioning or managing servers, automatically scaling with usage.
  • AWS CloudFront: A fast content delivery network (CDN) service that securely delivers data, videos, applications, and APIs to customers globally with low latency and high transfer speeds.
  • AWS API Gateway: A fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale.

System Architecture

system design

Class Diagram

class diagram

Installation

  1. Clone the Repository:

    git clone https://github.com/Furkan-Gulsen/golang-url-shortener.git
    cd golang-url-shortener
  2. Build the Project: Use the Makefile to build the project:

    make build

Usage

Deploying to AWS Lambda

  • Deploy your functions to AWS Lambda using the following command:
    make deploy
    This command will use AWS SAM to deploy your serverless functions.

Running Tests

  • Unit Tests: Run unit tests for specific functions:

    make unit-test
  • Benchmark Tests: Perform benchmark tests:

    make benchmark-test

Cleaning Up

  • To clean up the build artifacts:

    make clean
  • To delete the deployed stack:

    make delete

Cost Estimate

AWS Service Estimated Cost for 1 Million Requests Notes
AWS Lambda $0.20 First 1M requests/month are free, after that, it's $0.20 per 1 million requests
API Gateway $3.50 First 1M requests/month are free, after that, it's $3.50 per 1 million request.
DynamoDB $1.25 2 writes per generate, 1 write per redirect, 2 reads per stats
CloudFront $0.75 - $2.20 Based on 1M HTTPS requests
ElastiCache (Redis) Variable Dependent on node size and time running
SQS $0.40 First 1M requests/month are free, after that, it's $0.40 per 1 million requests.

Warning: This is a calculation based entirely on guesswork.


Hexagonal Architecture

Hexagonal Architecture

Image Resource: https://aws.amazon.com/blogs/compute/developing-evolutionary-architecture-with-aws-lambda

Hexagonal Architecture in a serverless context, specifically using Go language, is a fascinating topic that combines modern architectural patterns with the agility and scalability of serverless computing. Let's break down the key concepts and how your project structure fits into this model.

  1. Core Concept: Hexagonal Architecture, also known as Ports and Adapters Architecture, is designed to create a loosely coupled application that isolates the core logic from external concerns. The idea is to allow an application to be equally driven by users, programs, automated tests, or batch scripts, and to be developed and tested in isolation from its eventual runtime devices and databases.

  2. Ports and Adapters: In this architecture, the 'ports' are the interfaces that define how data can enter and leave the application or system. The 'adapters' are implementations that interact with the outside world, such as a database, a web server, or other systems.

Internal Directory

Adapters:

  • cache (e.g., redis.go): This likely represents the caching mechanism, an adapter to an external caching service like Redis.
  • functions: These are serverless functions for different operations (delete, generate, notification, redirect, stats), each with its own bootstrap and main.go. They serve as entry points for various operations, acting as adapters to external triggers or requests.
  • handlers (e.g., delete.go, generate.go): These are likely the controllers or use-case handlers that interact with the core domain logic.
  • repository (e.g., link.go, stats.go): Represents the data access layer, an adapter for database interaction.

Core Directory:

  • Domain (e.g., link.go, stats.go): Contains the business logic and entities of your application.
  • Ports (e.g., cache.go, link.go): Interfaces that define the expected operations (like CRUD) for various entities.
  • Services (e.g., link.go, stats.go): Implements business logic or domain services.

Tests Directory:

  • Contains various tests (benchmark, unit) to ensure that both the core logic and adapters work as expected.

Other Files:

  • go.mod, go.sum: Go module files for managing dependencies.
  • Makefile, README.md: For building the project and documentation.
  • samconfig.toml, template.yaml: AWS SAM configuration files for deploying serverless functions.

Serverless and Hexagonal Architecture:

In a serverless context, Hexagonal Architecture brings several benefits:

  • Decoupling: Your core logic is separated from external services like databases, message queues, or web frameworks.
  • Flexibility: Easy to replace or modify external services without affecting the core logic.
  • Scalability: Serverless functions (like AWS Lambda) can scale automatically, handling varying loads efficiently.
  • Cost-Effective: Pay for the compute time you use, which can be more cost-effective for certain workloads.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

More Repositories

1

turkce-go-egitimi

Bu repo, Go dilini hızlı bir şekilde öğrenmek isteyenler için hazırlanmış bir eğitim serisidir. Toplamda 40 konuyu, örnekler üzerinden anlatarak dilin temel yapılarını kapsar.
848
star
2

AWS-Certified-Cloud-Practitioner-Certification-My-Notes

In the process of obtaining the AWS Certified Cloud Practitioner certificate, I took notes of the topics I encountered from more than 10 sources and more than 2000+ questions and I share them in this repo.
410
star
3

HTML-CSS-JAVASCRIPT

HTML-CSS-JAVASCRIPT
HTML
126
star
4

Sport-With-AI

The human body is detected with the help of the Mediapipe library. Then, using the mathematical methods applied, it is determined how much the exercise count is done.
Jupyter Notebook
113
star
5

kubernetes-docs

Bu GitHub Reposunda amacım Kubernetes'e dair öğrendiğim bilgileri (makalelerden, kurslardan, notlarımdan) paylaşarak bu alana daha hızlı ve bilgilini girmeni sağlamaktır.
81
star
6

face-classification

Computer Vision project that detects emotion, age and gender after detecting faces.
Python
77
star
7

TensorFlow-ile-Yapay-Zeka-Gelistirme

Bu sayfada Türkçe olarak TensorFlow kullanarak derin öğrenme (deep learning) ve makine öğrenmesi (machine learning) ile ilgili detaylı anlatımlar ve projeler yer almaktadır.
Jupyter Notebook
50
star
8

Blur-Detection-Web-App

Blur Detection Web App with OpenCV and Flask
Python
48
star
9

Traefik-Auth-API-Gateway

Traefik Auth API Gateway
Go
25
star
10

Furkan-Gulsen

23
star
11

Recognize-Handwritten-Digits

Recognize Handwritten Digits - A Simple Web App
Jupyter Notebook
21
star
12

social-distance-detection

The project that detects the interpersonal social distance from videos using YOLOv3
Python
20
star
13

Face-Mask-Detection

Face Mask Detection With Deep Learning
Python
20
star
14

phpEmailSystem

Simple PHP Email System
PHP
19
star
15

redis-sentinel-pubsub-demo

The project demonstrates the implementation and functionality of Redis, Redis Sentinel, and Pub/Sub systems.
Go
18
star
16

Document-Scanner-Web-App

Document Scanner Web App with Python
Python
14
star
17

ReactJS-Projects

Here you can find small projects with ReactJS.
JavaScript
13
star
18

microservices-with-go

The project utilizes Go, Kubernetes, RabbitMQ, MongoDB, Postgres, and a microservices architecture. It focuses on efficient data handling and processing, with RabbitMQ for message queuing, MongoDB and Postgres for database management, orchestrated via Kubernetes.
Go
13
star
19

python-face-stabilization

Apply face stabilization with Python
Python
11
star
20

nodejs-auth-system

A comprehensive user sign-up/sign-in system
JavaScript
11
star
21

sport-with-ai-monorepo

Purpose of the Project The most general aim of the project is to make our user feel himself in the gym thanks to artificial intelligence technology while doing sports.
TypeScript
10
star
22

T-Rex-Game-with-CNN

Get great scores without touching the keyboard with the dinosaur that you trained with the convolutional neural network.
Python
10
star
23

python-selenium-test-islemleri

Python dilinin Selenium kütüphanesini kullanarak; Amazon, LinkedIn ve ÇiçekSepeti üzerinde test işlemleri yaptığımız bir case study reposudur.
Python
8
star
24

veri_bilimi_ve_makine_ogrenmesi

Veri bilimi, verileri anlamaya, geçmiş verilerden yola çıkarak belli istatistiksel modeller kurup geleceğe dönük tahmin yapmamızı sağlayan uygulamaların bütünüdür.
Jupyter Notebook
7
star
25

Python-Algorithms

Introduction to basic algorithms and their codes with Python.
Python
7
star
26

e_commerce_microservice

E Commerce Microservices with NodeJS
TypeScript
7
star
27

Checkout-System

The project is a mini e-commerce checkout developed with Go, incorporating features such as cart management, various product types, and promotions. It utilizes technologies like Go, Docker, Grafana, and Prometheus.
Go
7
star
28

Library-System

HTML
5
star
29

codeblogger-social-website

CSS
5
star
30

pandas-dokumantasyonu

Ayrıntılı Python Pandas Öğreticisi
Jupyter Notebook
5
star
31

Lane-Detection-With-Image-Processing

Lane Detection with Image Processing Method and using OpenCV
Python
5
star
32

Realtime-Chat-With-User-And-Rooms

Realtime Chat With User And Rooms
JavaScript
5
star
33

Node.js-Passport-Login-System

JavaScript
4
star
34

iris_predictor_web_app

Iris Predictor with Deep Learning | Web App
Jupyter Notebook
4
star
35

gocircuit

Circuit Breaker for Golang
Go
4
star
36

Simple-Messaging-App-With-Node-And-Socket.io-

Simple Messaging App With Node And Socket.io
HTML
4
star
37

chatbot-with-pytorch

Python
3
star
38

Object-Detection-with-YOLO

Object detection with YOLO
Python
3
star
39

CRUD-with-AWS-Lambda-and-NodeJS

CRUD-with-AWS-Lambda-and-NodeJS
JavaScript
3
star
40

A-Movie-App-With-React-And-Graphql

A Movie App With React And Graphql
JavaScript
3
star
41

Bootstrap-webpage

Website
JavaScript
2
star
42

PHP-Projects

Simple php projects I made
PHP
2
star
43

E-Commerce-with-Spring-Boot

E-Commerce with Spring Boot
Java
1
star
44

NBA-Simulator-with-Golang

The NBA Simulator is a Go-based application designed to simulate various aspects of NBA games.
Go
1
star
45

javascript-snake-game

JavaScript Snake Game
JavaScript
1
star