Building Microservices in Python and Flask (GitHub Project Included)

Umer Mansoor Umer Mansoor Follow Jul 10, 2016 · 2 mins read

After years of building applications and platforms using the Service Oriented Architecture, I became very interested in microservices last year. So much so that I chose the job offer based on the sole fact that it was providing me an opportunity to design and develop microservices on the AWS platform. I’ll share the pros and cons of microservices in a later post.

In this post, we’ll see how to build microservices in Python using a light-weight framework called Flask. Unlike other web frameworks (e.g. Rails,) Flask is very flexible and doesn’t force you to adopt a specific layout style for your projects. It’s light-weight because it doesn’t require users to use particular tools or libraries. For example, Flask doesn’t come with any database access libraries. You will use extensions to add the functionality that you want.

Cinema 3

I have created a fictional project called Cinema 3 that demonstrates the use of microservices using Python and Flask. In this hypothetical project, we have a few microservices working together to allow users to find movies and books tickets online. The microservices which make up the project are:

  • Movies: Manages information related to movies e.g. title, rating, etc.
  • Show Times: Provides show times for movies.
  • Bookings: Handles online booking.
  • Users: Manages user accounts for our project.

The microservices talk to each other using REST API. How do they know the address (host:port) of other services? In this example, each microservice runs on a separate port so we could identify them. In real-world projects, people use more advanced techniques such as service discovery (either server or client side; consul is a popular tool that people use for this purpose.)

Flask VS Other Python Web Application Frameworks

Before you decide to use Flask, see how it holds up to against other Python web application frameworks on popularity, features and more. Click on the image below to start comparing.

Compare Top Python Frameworks

Sample Code on GitHub

Here’s a link to the project on GitHub. The source code itself is pretty simple as this is just an example to give you a basic understanding of building microservices using Flask.

If you have any comments or question about the project, please let me know in the comments section below.

If you’re looking to learn Flask, here’s an excellent YouTube video series you should watch.

#microservices #python #flask

You May Also Enjoy

If you like this post, please share using the buttons above. It will help CodeAhoy grow and add new content. Thank you!

Comments (5)

krishna pal

The project is nicely structured and implemented the microservices, But I am not able to see any security on that, like authentication.


Super it’s simple and easy to understand.
Can we have a post on deployment of this project and how to make multiple instances


2017 Update: After trying out microservices on a small scale and realizing the inherent DevOps complexity they introduce, we backtracked and went back to SOA which also feels like an overkill for backend gaming services.


So what’s your opinion in microservices in 2020 with new tools in market… Did you change your perspective?

Dave O'Connor

Can you say more about the inherent DevOps complexity? What unforeseen challenges arose?

Speak Your Mind