Skip to content

Commit ebd1786

Browse files
committed
Update README.md
1 parent a2e0f7b commit ebd1786

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

GameBackendSocketIO/README.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Game Backend
22

3-
A Node.js application built with socket.io, Express.js and MongoDB.
3+
A Node.js application built with socket.io, Express.js, MongoDB, and Redis.
44

5-
## Events
5+
`server.js` facilitates the gameplay and real-time communication between players while `worker.js` runs as a background process (on a separate Heroku dyno) and populates a Redis cache of questions to speed up question retrieval.
6+
7+
## Server
8+
9+
The server handles the following events:
610

711
### `join game`
812

@@ -15,7 +19,7 @@ Errors: `fatal error`, `duplicate userId`
1519
### `get question`
1620

1721
Parameters: `level` (string)<br>
18-
After receiving this event, the backend will make a GET request to the `/random` endpoint of [QbQuestionsAPI](https://github.com/sherryhli/Extriviaganza/tree/master/QbQuestionsAPI), with the optional query parameter `level`, which can have values `MiddleSchool`, `HighSchool`, `Collegiate` or `Trash` (**not case-sensitive**). If successful, the server will emit `receive question` and all players in the game associated the socket that invoked this event will receive the question.
22+
After receiving this event, the server will attempt to retrieve a question from the cache. The set name is either supplied in the `level` parameter (`MiddleSchool`, `HighSchool`, `Collegiate` or `Trash`), or randomly chosen if `level` is null. (Note: level names are **not case-sensitive**). If the server fails to retrieve a question from the cache, then a GET request to the `/random` endpoint of [QbQuestionsAPI](https://github.com/sherryhli/Extriviaganza/tree/master/QbQuestionsAPI) is made with the appropriate query parameter. If there is a successful retrieval from either the cache or the API, the server will emit `receive question` and all players in the game associated the socket that invoked this event will receive the question.
1923

2024
Errors: `retryable error`, `fatal error`
2125
***
@@ -62,6 +66,13 @@ Parameters: none<br>
6266
This event is emitted by the server if a player tries to use a `userId` that's already being used by another player in their game.
6367

6468

69+
## Worker
70+
71+
The worker continuously makes GET requests to the `/random` endpoint of [QbQuestionsAPI](https://github.com/sherryhli/Extriviaganza/tree/master/QbQuestionsAPI) in order to populate the Redis cache upfront with questions of all levels. The cache is implemented as a collection of sets, with questions of each level being in a separate set, e.g. `questions:MiddleSchool`, `questions:HighSchool`, etc. Sets were chosen over lists as they decrease the likelihood of requests made close in time returning the same question, and also limits memory usage as only unique questions are stored in each set.
72+
73+
The worker should be scaled down as we approach the 25 MB memory limit of free Heroku Redis (not likely anytime soon since there aren't enough questions in [QbQuestionsAPI](https://github.com/sherryhli/Extriviaganza/tree/master/QbQuestionsAPI)'s database). Although there is an LRU eviction policy, it will result in loss of an entire set of questions, which is not ideal.
74+
75+
6576
## Deployment
6677

6778
The backend is deployed to Heroku at https://extriviaganza.herokuapp.com. There are currently two test endpoints: `/test1` and `/test2` that serve as very simple clients.
@@ -93,11 +104,16 @@ To check status of dynos:
93104
heroku ps
94105
```
95106

96-
To run 1 dyno:
107+
To run 1 web dyno:
97108
```
98109
heroku ps:scale web=1
99110
```
100111

112+
Scale down worker dyno:
113+
```
114+
heroku ps:scale worker=0
115+
```
116+
101117
To restart dyno:
102118
```
103119
heroku ps:restart

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Extriviaganza is a project inspired by Protobowl, an online quizbowl game that I
1010

1111
There are 5 different components to this project, with 4 already being worked on. More detailed documentation can be found in each component's README. The components are kept in a single repo for organization purposes but most are actually deployable units on their own.
1212

13-
Architecture diagram, updated April 1, 2020:
13+
Architecture diagram, updated April 18, 2020:
1414

1515
![Architecture-Diagram](architecture_diagram.png)
1616

@@ -40,7 +40,7 @@ This is a .NET Core REST API supporting CRUD operations that interacts with a SQ
4040

4141
### [Game Backend](https://github.com/sherryhli/Extriviaganza/tree/master/GameBackendSocketIO)
4242

43-
The game backend is an Express.js server that makes use of socket.io, which allows players to interact in real-time when playing the game. socket.io supports the concept of rooms, which is great because it makes it easy to enable isolation between games. MongoDB is used to store game states.
43+
The game backend is an Express.js server that makes use of socket.io, which allows players to interact in real-time when playing the game. socket.io supports the concept of rooms, which is great because it makes it easy to enable isolation between games. MongoDB is used to store game states and Redis is used to cache questions.
4444

4545
### Game Frontend
4646

architecture_diagram.png

1.85 KB
Loading

0 commit comments

Comments
 (0)