gRPC + SQLC + Mongo + Redis + Kafka and ID pool
- Postgres: SQL database
- MongoDB: Document database
- Redis: Cache
- Kafka: Message queue
- API: Go App serves gRPC
- Requirement:
- SQLC: https://github.com/kyleconroy/sqlc
- Migrate: https://github.com/golang-migrate/migrate
- Docker
- Clone
git clone https://github.com/golang-migrate/migrate
-
Create config.yml file
- build/gitToken: token for getting private go package (grpc)
-
Start API
run cmd/client/main.go dev
- Running command inside a container
docker exec -it explorer-api-1 ash
-
/api
Document for api. OpenAPI or Swagger specifications, JSON Schema files, protocol definition files. -
/build
Script for build. Docker file for local, dev, production -
/cmd
The entry point for our application -
/config
Initialization of the general app configurations -
/internal
Internal logic of application. Internal contain module which has:/handler
Handle request to module. For each module, it was named with user domain, such as: public_handler for end-user, ops_handler for operator,…/pkg
Logic of module:service
model
const
validation
-
/pkg
logic can be imported into a different proj -
/script
Scripts for building, installing, analyzing, and conducting other operations on the project
-
pkg/db/postgres
-
Migration SQL script
YYYYMMDDHHMMSS_name.up.sql
For migrate upYYYYMMDDHHMMSS_name.down.sql
For migrate down -
Generate SQLC code
go run cmd/client/main.go sqlc
-
Migrate SQL Database
go run cmd/client/main.go migrateup
-
-
pkg/db/mongo
- Create new collection/repo
- Define model of Collection in
db/mongo/model/
- Define logic of repo in
db/mongo/repo/
- Define repo in Driver struct
db/mongo/driver/
- Define model of Collection in
- Create new collection/repo
-
pkg/uuid
- UUID format
- Len: 20 numeric digit ~ 64 bit
- 41 bit for timestamp
- 6 bit for sharding id
- 6 bit for type
- 11 bit for counter
- Load capacity: 2048 per nano second ~ 2M per second
- UUID format