Code Monkey home page Code Monkey logo

microservices's Introduction

Cinema 3 - (Extremely Simplified) Example of Microservices in Python

Overview

Cinema 3 is an example project which demonstrates the use of microservices for a fictional movie theater. The Cinema 3 backend is powered by 4 microservices, all of which happen to be written in Python using Flask. For more information, you can refer to the blog post here: https://codeahoy.com/2016/07/10/writing-microservices-in-python-using-flask/

  • Movie Service: Provides information like movie ratings, title, etc.
  • Show Times Service: Provides show times information.
  • Booking Service: Provides booking information.
  • Users Service: Provides movie suggestions for users by communicating with other services.

Requirements

  • Python 2.7
  • Works on Linux, Windows, Mac OSX and (quite possibly) BSD.

Install

The quick way is use the provided make file.

$ make install

Starting and Stopping Services

To launch the services:

$ make launch

To stop the services:

$ make shutdown

APIs and Documentation

Movie Service (port 5001)

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.

To lookup all movies in the database, hit: http://127.0.0.1:5001/movies

GET /movies
Returns a list of all movies.

{
    "267eedb8-0f5d-42d5-8f43-72426b9fb3e6": {
        "director": "Ryan Coogler", 
        "id": "267eedb8-0f5d-42d5-8f43-72426b9fb3e6", 
        "rating": 8.8, 
        "title": "Creed"
}, 
...... output truncated ...... 

To lookup a movie by its id:

GET /movies/7daf7208-be4d-4944-a3ae-c1c2f516f3e6
Returns the specified movie.

{
    "director": "Paul McGuigan", 
    "id": "7daf7208-be4d-4944-a3ae-c1c2f516f3e6", 
    "rating": 6.4, 
    "title": "Victor Frankenstein", 
    "uri": "/movies/7daf7208-be4d-4944-a3ae-c1c2f516f3e6"
}

Showtimes Service (port 5002)

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

To lookup all showtimes, hit: http://127.0.0.1:5002/showtimes

GET /showtimes
Returns a list of all showtimes by date.

{
"20151130": [
    "720d006c-3a57-4b6a-b18f-9b713b073f3c", 
    "a8034f44-aee4-44cf-b32c-74cf452aaaae", 
    "39ab85e5-5e8e-4dc5-afea-65dc368bd7ab"
], 
...... output truncated ...... 

To get movies playing on a certain date:

GET /showtimes/20151201
Returns all movies playing on the date.

[
    "267eedb8-0f5d-42d5-8f43-72426b9fb3e6", 
    "7daf7208-be4d-4944-a3ae-c1c2f516f3e6", 
    "39ab85e5-5e8e-4dc5-afea-65dc368bd7ab", 
    "a8034f44-aee4-44cf-b32c-74cf452aaaae"
]

Booking Service (port 5003)

Used to lookup booking information for users.

To get all bookings by all users in the system, hit: http://127.0.0.1:5003/bookings

GET /bookings
Returns a list of booking information for all bookings in the database.

{
    "chris_rivers": {
        "20151201": [
            "267eedb8-0f5d-42d5-8f43-72426b9fb3e6"
        ]
    }, 
    ...... output truncated ...... 

To lookup booking information for a user:

GET /bookings/dwight_schrute

    {
        "20151201": [
            "7daf7208-be4d-4944-a3ae-c1c2f516f3e6", 
            "267eedb8-0f5d-42d5-8f43-72426b9fb3e6"
        ], 
        "20151205": [
            "a8034f44-aee4-44cf-b32c-74cf452aaaae", 
            "276c79ec-a26a-40a6-b3d3-fb242a5947b6"
        ]
    }

User Service (port 5000)

This service returns information about the users of Cinema 3 and also provides movie suggestions to the users. It communicates with other services to retrieve booking or movie information.

To get a list of all the users in the system, hit: http://127.0.0.1:5000/users

GET /users
Returns a list of all users in the database.

{
    "chris_rivers": {
        "id": "chris_rivers", 
        "last_active": 1360031010, 
        "name": "Chris Rivers"
    }, 
    ...... output truncated ...... 

To lookup information about a user:

GET /users/michael_scott
{
    "id": "michael_scott", 
    "last_active": 1360031625, 
    "name": "Michael Scott"
}

To get suggested movies for a user:

GET /users/michael_scott/suggested

microservices's People

Contributors

dependabot[bot] avatar griffinb avatar umermansoor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microservices's Issues

Run test

Good work done. I am fairly new to Flask. How do i run your test case?

how to consolidate retrieved data ?

I was thinking of a real production example, should the data be consolidated and show just ids or really shows just ids, and handle consolidation from the frontend.

for example:

should the showtime service return a list of movies ids or return list of movies including titles and other related information.

if it's just returning ids of movies, should the frontend do another request to fetch those movies?

Error running make install for the first time

Under Ubuntu, this is the error I got.

ps -ef | grep "services/movies.py" | grep -v grep | awk '{print $2}' | xargs kill  

Usage:
 kill [options] <pid> [...]

Options:
 <pid> [...]            send signal to every <pid> listed
 -<signal>, -s, --signal <signal>
                        specify the <signal> to be sent
 -l, --list=[<signal>]  list all signal names, or convert one to a name
 -L, --table            list all signal names in a nice table

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see kill(1).
make: *** [shutdown] Error 123

The problem is related to the kill part, as this is my first time, there is no PID and therefore, kill complains.

Fixed by adding -r to the xargs. According to the man page: Do not run the command if there are no arguments. Normally the command is executed at least once even if there are no arguments.

More info about rest

Hi, can you perhaps put in the docs why you didn't use Flask_restful? I'm interested to learn more about microservices.

More Detailed Information

Can you provide more information about the architecture? Like if every microservice has its own database? How the microservices talks to each other?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.