• Stars
    star
    165
  • Rank 228,906 (Top 5 %)
  • Language
    Go
  • Created almost 2 years ago
  • Updated 4 months ago

Reviews

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

Repository Details

backend clone of Twitter with golang

Twitter Backend API

This is a Twitter-Backend side project written in Golang along with database like PostgreSQL and Redis, and RabbitMQ as message Queue.

Article explaining the internals:

Docker Build

docker network create Twitter
docker-compose up -d

Only the logs of services are outputed rest are disabled in docker-compose file

Authentication

This API uses JWT (JSON Web Tokens) for authentication. When a user logs in, the API generates a JWT containing the user's id, which is used to authenticate all subsequent requests. I have usen Asymmetric JWTs so it have an private and a public key. private key will be used for creating tokens and public key will be used for verifying the tokens. The Public key is shared by other service for authentication.

Asymmetric JWT key

Endpoints

Auth

 

Routes:

 

Method Url Description
POST /auth/signup Creates a new user.
POST /auth/login Login a user
POST /auth/logout Logout a user
POST /auth/refresh-token Generate new access Token

User

 

Routes:

 

Method Url Description
GET /user/data/:username Gets User Details
DELETE / Delete User
UPDATE / Update User
POST /user/follow?username= Follows User
POST /user/unfollow?username= Unfollows User

Tweet

 

Routes:

 

Method Url Description
POST /tweet/create Create Tweet
GET /tweet/id/:id Get Tweet By ID
DELETE /tweet/id/:id/delete Del Tweet by ID
POST /tweet/id/:id/like Like a Tweet by ID
POST /tweet/id/:id/dislike DisLike a Tweet by ID
POST /tweet/id/:id/retweet Retweet a tweet
DELETE /tweet/id/:id/retweet del a Retweet

Timeline

 

Routes:

 

Method Url Description
GET /timeline/home?start= Gets User's Home timeline
GET /timeline/user?username=&start= Gets User Timeline by specifying username

Architecture

As you know this project in microservice architecture, So each service is independent. Tweet service and Timeline service is connected through Message Queue (RabbitMq). Tweet Service sends the new tweets to Timeline Service and Timleine service pushes these to respective tweet authors followers timeline If authors follower count is less than 10(I know it's very low but for testing this is fine). If it's above 10 followers would fetch tweet when they load the timeline.

Tweet-Timleine link by Mq

 

Conclusion

This was a fun project, I'm glad I could finish this project😬 learned some new things like How twitter timeline works, consul(service register), HAproxy(load balancer), RabbitMq(Message Queue) and Asymmetric JWT token. Now going back to learning👋.

Twitter Journey: "https://twitter.com/serpico_z/status/1605899167439757312"

More Repositories

1

E-commerce-Api

E-Commerce API Made With NodeJs,Typescript,PostgreSQL,Redis And Kafka
TypeScript
66
star
2

go-structure

This is a Golang project structure that I use for my projects. It is based on the hexagonal architecture, with some modifications. The structure is designed to keep the code organized and easy to understand. It includes directories for the entry point, functional code, database interactions, models, middleware and utility functions.
Go
16
star
3

go-chat2

Improved go chat application with distributed web servers,group chat
Go
15
star
4

goswift

High-performance, concurrent embedded caching library for Go applications with support for Hash data type, Disk Save and TTL
Go
10
star
5

blog_api

Blog API made with typescript, express & PostgreSQL
TypeScript
9
star
6

rplace

Backend Development of reddit r/place🐱‍💻
Go
5
star
7

weak-password-detector

Detect Weak password from 10,000 most used passwords using Redisbloom in sub-millisecond response times
TypeScript
4
star
8

Watchalong

JavaScript
2
star
9

password-generator

Generate passwords with Images 🐱‍💻, Truly random password
Python
1
star
10

health-check

python web health checker
Python
1
star
11

go-chat

Go
1
star
12

serpico

Simplify your digital life with Serpico, the ultimate app for organizing your files with precision and ease. Designed to help you manage and declutter your digital space, Serpico organizes your files by month, year, and file type.
NSIS
1
star
13

image-similarity

Image similarity detection using wavelet hashing algorithm
Python
1
star
14

graphql_structure

Go
1
star
15

go_graphql

grpahql
Go
1
star
16

ds

yes i'm doing ds
Go
1
star
17

consistent_hashing

consistent hashing implementation in go
Go
1
star