Skip to content

Architecture

Rishabh jain edited this page Aug 14, 2023 · 11 revisions

High level overview of Yaus Architecture

Yaus HLD

This diagram depicts a high level overview of yaus architecture. Don't worry if everything seems unfamiliar to you we will be diving into all of these things one by one in this guide.

Before diving into the details of each technology used lets break the whole architecture into small parts. Yaus is comprised of mainly these parts

  • Database : To persistenlt store the links
  • Cache : To cache the links for faster response time
  • Router : Route incoming requests
  • Messaging Queue: To perform side affects asynchronously
  • Web client : To interact with the yaus backend

About Database

Yaus uses a SQL database to store link data persistently. We use PostgreSql for this purpose since it is already battle tested and known for its extensibility, reliability, and adherence to SQL standards.

  • Database Schema

Here is a simplified representation of the Yaus database schema:

Table Name Columns
ShortLinks id (primary key)
userID
tags
clicks
url
hashid
project
customHashId
createdAt
params

link table is the main table where we store all the info related to link as well as some required metadata like createdAt(Time of creation of link).
hashId and customHashId are the two filed which as a user you will be mostly working since these are the suffix appended to yaus base url makes your shorten URL. hashId is automatically assigned to each link on successful creation where a user can choose customHashId as per their wish until and unless its already been in use by someone else.

About Router

A router is a crucial component that handles the routing of incoming requests to specific handlers or functions based on the requested URL. Yaus uses Fastify as router. Fastify is a modern, high-performance web framework for Node.js. It is specifically designed to be fast and efficient, making it well-suited for building APIs and web applications that demand high-speed performance.
Whenever a request is made to yaus backend its first received by Fastify which then routes it to appropriate handler if such exists. Currently yaus supports only these endpoints.

  • GET /id : redirect to orignal link by resolving a request made to shortened link
  • POST /register : To create a new shorten link
  • PATCH /update/id : To update information in already existing link

All in fastify router within yaus nestJs backend is where all the business logic resides and will be the area where you will be mostly speding time if you are a contributor or someone interested in modifying yaus as per your needs.