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

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.



Umer Mansoor
Written by Umer Mansoor Follow
Hi, I am Umer. I live in the San Francisco Bay Area and it is where I work. Since 2011, I have worked at startups, mobile gaming and internet companies. If you have any questions, feel free to message me.

Comments (4)


kirankotari

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


Dave O'Connor

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


Umer

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.


krishna pal

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


Speak Your Mind

Join Newsletter
Enter your email address to receive a very occasional newsletter. I'll never spam or sell your email.