Microservices: An Example With Docker, Go, and MongoDB

DZone 's Guide to

Microservices: An Example With Docker, Go, and MongoDB

See how you can set up your own system using a combination of microservices, containers, Go, and MongoDB. In this scenario, see a fictional movie theater come to life.

· Integration Zone ·
Free Resource


"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.

  • Users Service: Provides users information.
  • Movie Service: Provides information like movie ratings, title, etc.
  • Show Times Service: Provides showtime 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 on the knowledge learned in the book Web Development with Go by Shiju Varghese, ISBN 978-1-4842-1053-6


  • Docker 18.06.1-ce
  • Docker Compose 1.23.1

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:   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


User Service

This service returns information about the users of Cinema.


  • GET - http://users.local/users: Get all users.
  • POST - http://users.local/users: Create user.
  • DELETE - http://users.local/users/{id}: Remove user by ID.

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.


  • GET - http://movies.local/movies: Get all movies.
  • POST - http://movies.local/movies: Create movie.
  • GET - http://movies.local/movies/{id}: Get movie by ID.
  • DELETE - http://movies.local/movies/{id}: Remove movie by ID.

Showtimes Service

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


  • GET - http://showtimes.local/showtimes: Get all showtimes.
  • POST - http://showtimes.local/showtimes: Create showtime.
  • GET - http://showtimes.local/showtimes/{id}: Get showtime by ID.
  • DELETE - http://showtimes.local/showtimes/{id}: Remove showtime by ID.

Booking Service

Used to lookup booking information for users.


  • GET - http://bookings.local/bookings: Get all bookings.
  • POST - http://bookings.local/bookings: Create booking.

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


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)

api, backend, container, database, docker, go, mongodb, service, source code

Published at DZone with permission of Manuel Morejón , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}