Giter VIP home page Giter VIP logo

furkan-gulsen / golang-url-shortener Goto Github PK

View Code? Open in Web Editor NEW
111.0 2.0 3.0 2.57 MB

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

License: MIT License

Go 95.57% Makefile 4.43%
aws-serverless-architecture go-hexagonal-architecture go-serverless golang golang-serverless hexagonal-architecture link-shortener serverless serverless-architectures url-shortener

golang-url-shortener's Introduction

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.

golang-url-shortener's People

Contributors

furkan-gulsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

golang-url-shortener's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.