Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
/ tiktok Public archive

Kitex + Hertz + Prometheus + Grafana + RabbitMQ + Redis + Gorm + etcd + es + Kibana. Distributed and relatively standardized backend for short video engineering.

License

Notifications You must be signed in to change notification settings

ozline/tiktok

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

tiktok

English | ็ฎ€ไฝ“ไธญๆ–‡

tiktok is a distributed simple-tiktok backend based on RPC and HTTP protocols using Kitex + Hertz + etcd + MySQL + Jaeger + Docker + Thrift + Prometheus + Grafana + Elasticsearch + Kibana

Materials (Simplified Chinese only)

This project is a part of a competition. We have attached our final materials here.

Quietly say: We have achieved a good ranking.

Documentation Replay of the defense

Feature

  • Extremely easy to use and deploy.
  • Relatively mature CI/CD.
  • Relatively high code quality
  • Safety Considerations
  • Performance Optimization for Interfaces

Architecture

architecture

Quick start

We will introduce how to quickly start this project using Docker. If you need to build and run it locally, please refer to: start-by-local

Due to the script we have written, the process has been greatly simplified. You just need to use the following command to quickly start the environment and run the program in a containerized manner.

make env-up      # launch environment, env-down for remove
make docker      # build docker-image
sh docker-run.sh # launch all services

# if you just want to launch specific service, use
sh docker-run.sh api # or others

then you can send HTTP request on localhost:10001 for test or others things

Quick deploy

We use a fully automated process to streamline the workload, so you can always use our Docker image packaged with the latest code.

You can directly copy the deploy folder of our project to the server you expect to deploy. The folder structure is roughly as follows

deploy
โ”œโ”€โ”€ config              # same as this projects
โ”‚ย ย  โ”œโ”€โ”€ config.yaml
โ”‚ย ย  โ”œโ”€โ”€ words.txt       # sensitive word list
โ”‚ย ย  โ”œโ”€โ”€ prometheus.yml
โ”‚ย ย  โ””โ”€โ”€ sql             # for mysql init
โ”‚ย ย      โ”œโ”€โ”€ init.sql
โ”‚ย ย      โ””โ”€โ”€ user.sql
โ”œโ”€โ”€ docker-compose.yml  # for environment, same
โ””โ”€โ”€ restart-service.sh  # deploy scripts

The script will automatically pull the latest image from Aliyun ACR, find and delete the running containers, and re-run them with the latest image.

If you want a specific tutorial on how to use it, please visit: deploy docs

Project structure

Overall

.
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ Makefile              # some useful commands
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ cmd                   # microservices
โ”œโ”€โ”€ config                # for run-directly config and config-example
โ”œโ”€โ”€ deploy                # for deploy
โ”œโ”€โ”€ docker-compose.ci.yml # for ci env
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ docker-run.sh         # for local docker-run
โ”œโ”€โ”€ docs
โ”œโ”€โ”€ go.mod
โ”œโ”€โ”€ go.sum
โ”œโ”€โ”€ idl                   # interface definition
โ”œโ”€โ”€ kitex_gen
โ”œโ”€โ”€ pkg
โ”‚ย ย  โ”œโ”€โ”€ constants         # store any consts
โ”‚ย ย  โ”œโ”€โ”€ errno             # custom error
โ”‚ย ย  โ”œโ”€โ”€ middleware        # common middleware
โ”‚ย ย  โ”œโ”€โ”€ tracer            # for jaeger
โ”‚ย ย  โ””โ”€โ”€ utils             # useful funcs
โ””โ”€โ”€ test

Gateway/api service

.
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ biz
โ”‚   โ”œโ”€โ”€ handler     # solve request/send response
โ”‚   โ”œโ”€โ”€ middleware
โ”‚   โ”œโ”€โ”€ model
โ”‚   โ”œโ”€โ”€ pack        # pack response
โ”‚   โ”œโ”€โ”€ router      # for route
โ”‚   โ””โ”€โ”€ rpc         # send rpc request to microservices
โ”œโ”€โ”€ build.sh
โ”œโ”€โ”€ main.go
โ”œโ”€โ”€ output          # build binary
โ”œโ”€โ”€ router.go
โ”œโ”€โ”€ router_gen.go
โ””โ”€โ”€ script

Microservices

.
โ”œโ”€โ”€ Makefile        # useful commands
โ”œโ”€โ”€ build.sh        # build binary
โ”œโ”€โ”€ dal
โ”‚   โ”œโ”€โ”€ cache       # redis
โ”‚   โ”œโ”€โ”€ db          # MySQL
โ”‚   โ””โ”€โ”€ mq          # RabbitMQ
โ”œโ”€โ”€ handler.go
โ”œโ”€โ”€ kitex_info.yaml
โ”œโ”€โ”€ main.go
โ”œโ”€โ”€ output          # build binary
โ”œโ”€โ”€ pack            # pack response
โ”œโ”€โ”€ rpc             # send request to other services
โ”œโ”€โ”€ script
โ”œโ”€โ”€ coverage        # coverage test(some service not exist)
โ””โ”€โ”€ service

Test

you can drop .postman/tiktok.openapi.json to postman then start this project and test

Visualization example

Jaeger

jaeger jaeger-dag

Kibana + Elasticsearch

kibana

Grafana + Prometheus

grafana

Contributor

Fuzhou University west2-online studio golang team