This project is 2024 Dcard backend intern assignment.
Development details: (https://keen-rose-d7a.notion.site/Dcard-c4192a8187434789bab65a80d11d9edf?pvs=4)
Another repo that try to horizontal scale up the service: (https://github.com/Tomlord1122/Dcard-backend-extenstion)
- Create Ads: Add new advertisements with detailed targeting options.
- Create Random Ads: Add random advertisements for testing.
- List Ads: Retrieve active ads with flexible filtering, optimized for performance.
- Cache Integration: Leverages Redis for caching, significantly reducing response times for frequent queries.
- Database Optimization: Utilizes indexed queries for efficient data retrieval.
- Scalability: Designed for high throughput, supporting auto-scaling and load balancing.
- GET API
- POST API
- Test
- 10000 RPS
- Number of ads (StartAt < NOW < EndAt) < 1000
- The number of ads created per day will not exceed 3,000
- Go 1.15+
- PostgreSQL 12+
- Redis 6+
- Docker
-
Clone the repository:
git clone https://github.com/Tomlord1122/Dcard-Backend-Intern.git
-
Install dependencies:
go mod tidy
-
Set up the environment variables as per the
.env
file.
-
Start the PostgreSQL and Redis servers.
make postgres make createdb make migrate make server make redis make k6 # testing
-
Makefile:
postgres: docker run --name postgres16 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:latest stop: docker stop postgres16 start: docker start postgres16 createdb: docker exec -it postgres16 createdb --username=root --owner=root dcard dropdb: docker exec -it postgres16 dropdb dcard migrateup: migrate -path db/migration -database "postgresql://root:secret@localhost:5432/dcard?sslmode=disable" -verbose up migratedown: migrate -path db/migration -database "postgresql://root:secret@localhost:5432/dcard?sslmode=disable" -verbose down server: go run main.go test: go test -v -cover ./... sqlc: sqlc generate k6: cd k6 && k6 run loadtest.js redis: redis-server ./redis.conf .PHONY: postgres createdb dropdb migrateup migratedown sqlc k6 test server stop start
- POST /ads: Create a new ad.
- GET /ads: List ads based on query parameters.