- Stores users in a leaderboard using redis
- nginx used as a load balancer to distribute traffic
/ go / fiber / Docker / nginx / redis /
-
Clone the repo into your local
git clone https://github.com/bcaglaraydin/go-scoreboard
-
Create an
.env
file and place it in root directory
Sample.env
file:APP_PORT=":3000" REDIS_PORT=":6379" REDIS_HOST="redis"
-
Make sure you have docker-compose and docker installed on your machine
-
Run the following command (N is the number of servers)
docker-compose up --scale api=N
POST http://localhost:3000/user/create
{
"user_id": "389e4264-e88b-12d3-a456-426614174000",
"display_name": "username",
"points": 1000,
"rank": 0,
"country": "tr"
}
POST http://localhost:3000/score/submit/{user_guid}
{
"score_worth": 10,
"user_id": "399e4264-e88b-12d3-a456-426614174000",
"timestamp": 8573040751
}
GET http://localhost:3000/user/profile/{user_guid}
{
"user_id": "389e4264-e88b-12d3-a456-426614174000",
"display_name": "hey",
"points": 1000,
"rank": 1,
"country": "gr"
}
GET http://localhost:3000/leaderboard
[
{
"user_id": "389e4464-e88b-12d3-a456-426614174000",
"display_name": "user",
"points": 5000,
"rank": 1,
"country": "tr"
},
{
"user_id": "389e4264-e88b-12d3-a456-426614174000",
"display_name": "user2",
"points": 1000,
"rank": 2,
"country": "gr"
},
{
"user_id": "399e4264-e88b-12d3-a456-426614174000",
"display_name": "user3,
"points": 2,
"rank": 3,
"country": "tr"
}
]
GET http://localhost:3000/leaderboard/{country_iso_code}
[
{
"user_id": "389e4464-e88b-12d3-a456-426614174000",
"display_name": "user",
"points": 5000,
"rank": 1,
"country": "tr"
},
{
"user_id": "399e4264-e88b-12d3-a456-426614174000",
"display_name": "user3,
"points": 2,
"rank": 3,
"country": "tr"
}
]
Berdan Çağlar Aydın - https://www.linkedin.com/in/bcaglaraydin/ - [email protected]