Game Service is designed to serve game app(s) on multiple devices via REST
calls.
All Internal APIs
& the Database
are designed to support multiple games in future, with multiple supporting modes.
The Service is bootstrapped to work with a game named FAMOUS SHOOTER
and supports following 3 modes
:
- Battle Royal
- Team Deathmatch
- Capture the flag
- gameid=1 is default game id for all endpoints
- A player can play only one game at a time
- Area is always 3 letter code
- Game names are Unique & can support multiple modes
- Multiple games can have same modes
- A Game can support any number of players
- JSON is the supported format for now
- GET
/top-modes?area=blr
- returns a json array of all active modes in the given
area
indescending
order of popularility i.e. themode
with highest number of active players will be first followed by sencond highest and so on
- POST
/player?modeid=1&area=blr
- returns the
playerid
assigned to the new player, thisplayerid
can be used to remove the player from the game
- DELETE
/player?playerid=1
Game Service
at bare minimim needs docker
installed/running and a .env
at the project's root with following details
LILA_DB_HOST=postgres
LILA_DB_PORT=5432
LILA_DB_USER=postgres
LILA_DB_PASSWORD=postgres
LILA_DB_DATABASE=postgres
LILA_DB_DRIVER=postgres
LILA_DB_EXPLORER_EMAIL=someone@postgres.com
LILA_DB_EXPLORER_PASSWORD=postgres
LILA_DB_RUN_MIGRATION=true
LILA_SERVER_PORT=:1234
LILA_TIME_TO_WAIT_FOR_SUPPORTING_SERVICES_TO_COME_UP=s30s
make up
will bring up all services.
After all services have successfully come up visit
localhost.
To explore the postgres data visit postgres and login with LILA_DB_EXPLORER_EMAIL
and LILA_DB_EXPLORER_PASSWORD
and configure the database in there with the said configuration from .env
file.
make down
will teardown all services
$ bombardier -c 125 -n 100000 http://localhost:1234/top-modes\?area\=blr
Bombarding http://localhost:1234/top-modes?area=blr with 100000 request(s) using 125 connection(s)
100000 / 100000 [========================================================================================================================] 100.00% 7453/s 13s
Done!
Statistics Avg Stdev Max
Reqs/sec 7543.95 1912.33 12149.01
Latency 16.57ms 23.13ms 529.39ms
HTTP codes:
1xx - 0, 2xx - 100000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 1.54MB/s
The Service is designed following the go
conventions, executables
are kept inside cmd
directory, re-usable packages are kept under pkg
directory & critical business logic is kept under internal
directory.
All database tables have been properly indexed to suit the service's need.
Server
has dependency on Service
Service
has denepdency on storage layer
or the Database
which can be swapped with in-memory
or elastic
should there be a need pertaining to performance (in future).
We can also opt gRPC
based communications using protobuf
for performance & to cap bandwidth - keeping in view mobile devices.
Based on load-testing
above the service
is able to serve an average of 7.5K requets/second
.
server -> service -> database
Game Service is composed up of three microservices
- postgres
- is the database used
- game_app
- actual game service serving the
REST
calls- postgres_explorer
- handy UI for exploring the postgres database
It took ~6 hours in total to build the service.
Following are the bifurcation
- Architecting the service, code structure and database structure took approximately 2 hours.
- Coding & Dockerizing took 3 hours.
- Testing took an 1 hour.