• Stars
    star
    107
  • Rank 313,444 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created 5 months ago
  • Updated 5 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.
813
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.
314
star
3

HTML-CSS-JAVASCRIPT

HTML-CSS-JAVASCRIPT
HTML
120
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
108
star
5

face-classification

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

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.
71
star
7

Blur-Detection-Web-App

Blur Detection Web App with OpenCV and Flask
Python
44
star
8

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
41
star
9

Furkan-Gulsen

22
star
10

Recognize-Handwritten-Digits

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

Face-Mask-Detection

Face Mask Detection With Deep Learning
Python
20
star
12

social-distance-detection

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

phpEmailSystem

Simple PHP Email System
PHP
19
star
14

Document-Scanner-Web-App

Document Scanner Web App with Python
Python
13
star
15

ReactJS-Projects

Here you can find small projects with ReactJS.
JavaScript
12
star
16

python-face-stabilization

Apply face stabilization with Python
Python
11
star
17

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
18

nodejs-auth-system

A comprehensive user sign-up/sign-in system
JavaScript
10
star
19

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
9
star
20

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
8
star
21

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
22

Python-Algorithms

Introduction to basic algorithms and their codes with Python.
Python
7
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
7
star
24

e_commerce_microservice

E Commerce Microservices with NodeJS
TypeScript
6
star
25

pandas-dokumantasyonu

Ayrıntılı Python Pandas Öğreticisi
Jupyter Notebook
6
star
26

Library-System

HTML
5
star
27

codeblogger-social-website

CSS
5
star
28

Lane-Detection-With-Image-Processing

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

Realtime-Chat-With-User-And-Rooms

Realtime Chat With User And Rooms
JavaScript
5
star
30

Node.js-Passport-Login-System

JavaScript
4
star
31

iris_predictor_web_app

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

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

A Movie App With React And Graphql
JavaScript
4
star
33

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

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

chatbot-with-pytorch

Python
3
star
35

Object-Detection-with-YOLO

Object detection with YOLO
Python
3
star
36

Bootstrap-webpage

Website
JavaScript
2
star
37

CRUD-with-AWS-Lambda-and-NodeJS

CRUD-with-AWS-Lambda-and-NodeJS
JavaScript
2
star
38

PHP-Projects

Simple php projects I made
PHP
2
star
39

gocircuit

Circuit Breaker for Golang
Go
2
star
40

javascript-snake-game

JavaScript Snake Game
JavaScript
1
star
41

E-Commerce-with-Spring-Boot

E-Commerce with Spring Boot
Java
1
star