Microservices: An Example With Docker, Go, and MongoDB

introduction

"cinema" is an example project which demonstrates the use of microservices for a fictional movie theater. the cinema backend is powered by for microservices, all of which happen to be written in go, using mongodb for manage the database and docker to isolate and deploy the ecosystem.

the cinema use case is based on the project written in python by umer mansoor .

the project structure is based on the knowledge learned in the book web development with go by shiju varghese , isbn 978-1-4842-1053-6

prerequisite

we must add virtual domains in order to use each api entry point . by default we are using movies.local , bookings.local , users.local, showtimes.local and monitor.local .

virtual domains have been defined in the docker-compose.yml file and configured in the /etc/hosts file. add the following line in your /etc/hosts file:

127.0.0.1   movies.local bookings.local users.local showtimes.local monitor.local

monitor.local will be used to see the dashboard created by traefik.

source code

you can download the source code using this link .

services diagram

starting services

docker-compose up -d


stopping services

docker-compose stop


including new changes

if you need to change some source code you can deploy it typing:

docker-compose build



you can start using an empty database for all microservices, but if you want you can restore a preconfigured data execute this step:

restore mongodb data typing:

docker-compose exec db /bin/bash /backup/restore.sh

documentation

user service

this service returns information about the users of cinema.

routes:

movie service

this service is used to get information about a movie. it provides the movie title, rating on a 1-10 scale, director, and other information.

routes:

showtimes service

this service is used get a list of movies playing on a certain date.

routes:

booking service

used to lookup booking information for users.

routes:

exposed ports

the port 27017 is exposed to be consulted by the robomongo system. port 80 is exposed to be consulted by devices, web browsers, or others microservices.

microservices - exposed ports

screenshots

starting services

microservices - starting services


restoring database information

microservices - restoring database information

traefik dashboard

traefik dashboard


service: get all users (postman)


service: get all movies (postman)


service: get all showtimes (postman)


service: get all bookings (postman)


database big picture (robomongo)

 

 

 

 

Top