DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Write a Smart Contract With ChatGPT, MetaMask, Infura, and Truffle
  • Java String Templates Today
  • What Is TTS and How Is It Implemented in Apps?
  • [DZone Survey] Share Your Expertise for Our Database Research, 2023 Edition
  1. DZone
  2. Data Engineering
  3. Databases
  4. Microservices: An Example With Docker, Go, and MongoDB

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.

Manuel Morejón user avatar by
Manuel Morejón
·
Aug. 29, 16 · Tutorial
Like (18)
Save
Tweet
Share
33.36K Views

Join the DZone community and get the full member experience.

Join For Free

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.

  • 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

prerequisite

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

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:

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

routes:

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

routes:

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

routes:

  • 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

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)


microservice Web Service Docker (software) MongoDB

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

Opinions expressed by DZone contributors are their own.

Trending

  • Write a Smart Contract With ChatGPT, MetaMask, Infura, and Truffle
  • Java String Templates Today
  • What Is TTS and How Is It Implemented in Apps?
  • [DZone Survey] Share Your Expertise for Our Database Research, 2023 Edition

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: