Skip to content

Architecture

Rishabh jain edited this page Aug 19, 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.

About cache

In yaus we are caching things both at the client side as well as server side. In client sied we are using apollo cache (part of apollo client itself) this is mostly been done in admin app. On the server side we are using redis to cache the link data to improve performance of our key endpoints.If you are a contributor interested in contributing to the yaus backend then exploring redis further would be worthwhile , this will significantly help you in understanding the yaus backend codebase.

About Messaging Queue

Messaging Queue are a popular way of offloading heavy task in backend by pushing them to a queue and performing these tasks asynchronously with the help of consumers. In yaus we are using a popular Messaging queue namely RabbitMQ. These are mostly being used to perform write operation to the yaus db which are not urgent and can be performed async for example :- increasing click count is something thats not urgent and can be done async.

About Web client

Yaus has a clean and minimal web client written in react to help users with the link creation and bunch of other features like dashboard etc. This is a cruical part of yaus since most of the users will be directly interating with this to create and manage their shorten links. If you are contributor who has even basic knowledge of frontend then this is where you should look for since it has a lot of beginner friendly issues to work upon. PS: look from a folder name frontend with the app folder , this is where the entire web client codebase resides.