Giter Club home page Giter Club logo

gamesample's Introduction

gamesample

Introduction

The application contained in this repository consists of an nginx loadbalancer container, one or more web application containers, a redis container and a mysql container.

Request sequence

  1. Client makes an HTTP request to 127.0.0.1:8083
  2. Docker directs tcp/8083 to nginxlb tcp/4000
  3. nginxlb resolves DNS hostname 'webapp' to internal network IP
  4. nginxlb directs tcp/4000 to webapp tcp/5000
  5. webapp flask application receives traffic on tcp/5000 and performs function based on url
  6. /player/create creates a row in mysql and a record in redis
  7. /player/get reads from redis and mysql
  8. Redis request is returned to webapp
  9. MySQL request is returned to webapp
  10. webapp request is returned to nginxlb
  11. nginxlb request is returned to client

Container descriptions

Nginx loadbalancer container (NGINXLB)

Purpose: This container provides a frontend interface for webtraffic. The nginx proxy will forward the request on tcp port 8083 to the internal inteface of the web application container on port 5000. The nginx loadbalancer will query DNS records in a round-robin mechanism to resolve the alias of 'webapp' set by docker-compose to an internal IP of one of the webapp containers. nginx listens internally on tcp port 4000 and is directed to port 8083 externally by docker which then presents the port to the host operating system on localhost:8083.

Web Application container (WEBAPP)

Purpose: This container hosts the python flask application on port 5000. It will retrieve environment variables passed from the start.sh script to docker-compose relating to MySQL and Redis authentication details. After creating a connection to these services it will listen on port 5000 to incoming traffic and respond depending on the endpoint url. This is currently /player/create or /player/get. In the event of there being a mismatch between redis and mysql in relation to gold, the app will update mysql with a syncronisation update which could be done asyncronously.

Redis container (REDIS)

Purpose: Redis is an in-memory cache and can be used to store and update frequently used data. The reason to use redis over mysql is to optimise latency when looking up specific records rather than request the lookup via a relational database. The redis container allows for TTL of records and so infreqently used data can be purged from memory increasing accuracy.

MySQL container (MYSQL)

Purpose: MySQL is a relational database which stores information relating to the player such as player name and player gold. When a player is created a row is created in the gamesample database and player table to store for future lookups. The gold is initially set to 0 but can be updated via the webapp.

Installation/Usage

To install this sample application please follow the instructions below:

Ensure that docker is running and docker-compose 2.0 are installed

git clone https://github.com/dmccue/gamesample.git && cd gamesample

Starting

To run the stack please run:

./start.sh <number of webapp containers>

Wait for the stack to create and display output from the nginxlb and webapp containers

Testing

In an alternative window type:

./test.sh

You should see the responses to curl commands displayed in the terminal

Stopping

In an alternative window type:

./stop.sh

Future improvements

AWS Architecture - Using API only

AWS Architecture - Using static webpages

### AWS Architecture - FARGATE

AWS Architecture - Lambda

AWS Architecture - CodePipeline

gamesample's People

Contributors

dmccue avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.