Microservices - Example with Docker, Go and MongoDB

24 August 2016 · 3 min read

Introduction

Cinema is an example project which demonstrates the use of microservices for a fictional movie theater. The Cinema backend is powered by 4 microservices, all of witch happen to be written in Go, using MongoDB for manage the database and Docker to isolate and deploy the ecosystem.

  • Users Service: Provides users information.
  • Movie Service: Provides information like movie ratings, title, etc.
  • Show Times Service: Provides show times information.
  • Booking Service: Provides booking information.

The Cinema use case is based on the project written in Python by Umer Mansoor.

The project structure is based in the knowledge learned in the book: Web Development with Go by Shiju Varghese, ISBN 978-1-4842-1053-6

Prerequisite

  • Docker 1.12
  • Docker Compose 1.8

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

Virtual domains has been defined in docker-compose.yml file and configured in /etc/hosts file. Add the following line in your /etc/hosts file:

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

Source Code

You can download the source code using this link.

Services diagram

Microservices - Cinema

Starting services

docker-compose up -d

Stopping services

docker-compose stop

Including new changes

If you need change some source code you can deploy it typing:

docker-compose build

Restore database information

You can start using an empty database for all microservices, but if you want you can restore a configured data following this steps:

Access to mongodb container typing:

docker exec -it cinema-db /bin/bash

Restore data typing:

/backup/restore.sh

Leave the container:

exit

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 Robomongo system. The 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

Service - Get all users (Postman)

Microservices - Get all users

Service - Get all movies (Postman)

Microservices - Get all movies

Service - Get all showtimes (Postman)

Microservices - Get all showtimes

Service - Get all bookings (Postman)

Microservices - Get all bookings

Database big picture (Robomongo)

Microservices - Database big picture

Significant Revisions

comments powered by Disqus