Over a million developers have joined DZone.

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

Build APIs from SQL and NoSQL or Salesforce data sources in seconds. Read the Creating REST APIs white paper, brought to you in partnership with CA Technologies.


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

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 configured data using the following steps:

Access to MongoDB Container:

docker exec -it cinema-db /bin/bash

Restore Data:


Leave the Container



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.


Starting services

Restoring Database Information

Service: Get All Users (Postman)

Service: Get All Movies (Postman)

Service: Get All Showtimes (Postman)

Service: Get All Bookings (Postman)

Database Big Picture (Robomongo)

The Integration Zone is brought to you in partnership with CA Technologies.  Use CA Live API Creator to quickly create complete application backends, with secure APIs and robust application logic, in an easy to use interface.

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

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}