"Flask At Scale" tutorial at PyCon 2016 in Portland

Posted by
on under

Pycon 2016 Logo

The tutorial line up for PyCon 2016 in Portland, Oregon has been announced, and I'm excited to be part of it with yet another Flask tutorial. For some odd reason, not all the class information I provided with my proposal was published on the PyCon website, so I want to give you a good overview of the material I plan to cover here, to help you decide if this tutorial is for you.

My Flask tutorial is scheduled for Saturday, May 28th from 9am to 12:20pm. PyCon tutorials have a registration fee of $150 each if purchased ahead of time, or $200 if purchased the same day at the door. Note that tutorial fees are separate and not included in the conference registration. Your tutorial registration also gives you access to lunch on the tutorial day.

If you want to have an idea of what you get from one of my Flask tutorials, here are the two that I gave in past years:


Flask Workshop: A beginner's Flask tutorial I gave at PyCon 2015


Flask By Example: An intermediate Flask tutorial I gave at PyCon 2014

This class that I'm preparing for this year's PyCon is for intermediate and advanced Flask developers looking to learn the patterns and best practices that can help scale a Flask application, both in terms of application size and load. In terms of complexity, this class would go after the two above and will be the most advanced Flask class I have ever given. The topics are divided into two main areas:

  • Large applications: How to organize code, templates and static files in a way that allows the application to grow without becoming a mess.
  • Flask under load: Different ways to deploy a Flask application so that it can handle large numbers of clients.

Below you can see the description and abstract as published on the PyCon website, plus the tentative class outline, which was not published:

Description

Do you think that because Flask is a micro-framework, it must only be good for small, toy-like web applications? Well, not at all! In this tutorial I am going to show you a few patterns and best practices that can take your Flask application to the next level.

Abstract

Can Flask scale? For many, that is the million dollar question. Unfortunately even the Flask official documentation is ambiguous about this topic. Flask is a small, unobtrusive framework that simplifies the interface between your application and the web server. Outside of that, it mostly stays out of your way, so if you need to write an application that can scale, Flask is not going to prevent it, and in fact, it will allow you to freely choose the components of your stack and not impose choices on you like big frameworks tend to do.

In this tutorial session, I will walk you through a list of typical patterns for medium and large applications written in Flask, specifically chosen to highlight scalability patterns and best practices that you will be able to transfer to your own projects. The class will be divided in two main sections, dedicated to scalability of the code (i.e. how to write large applications with Flask) and scalability of the deployed application (i.e. how to handle large numbers of clients).

Outline

  • Introduction (10 min)
  • Large applications (1 hour)
    • How to structure a large application
    • Using Blueprints to organize an application
    • Decorators as a way to simplify application code
    • Combining a web application with a REST API
    • API versioning
  • Flask under load (1 hour)
    • Asynchronous requests
    • Using a Celery job queue
    • Using multiple processes and hosts with a load balancer
    • Using coroutine frameworks such as eventlet or gevent
    • Using WebSocket for server-push and reduced latency
  • Free-form Discussion and Q&A (50 min)

I hope this additional information helps you decide if you want to attend. And by the way, I'm only starting to prepare the material for this class, so I'm happy to accept suggestions for topics I may have not included that fit the theme of the class.

I hope to see you in Portland, either at my tutorial or around the conference!

Miguel

Become a Patron!

Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!

27 comments
  • #26 fred engel said

    Your Flask at Scale seminar was exteremly helpful,
    as I am trying to scale a Flask application. I have
    implemented a bunch of what you articualted. As
    you might have guessed, I'm stuck on one point.

    My confusion has to do with the sharing of object
    variables across multiple processes. When you
    showed being able to just add servers, are they
    each a separate process?

    More precisely, you have db created at the flack
    init.py level and then passed onto the lower
    modules as an object variable through import. I
    have played around with this and it works.

    What I am confused about is how does this work
    across multiple processes that don't share memory.
    Does NGINX creates separate processes each in their
    own memory space. How does the db object work in
    that environment? Can I share other Class instances
    in this way?

    I am sure I am missing something here.

    Thanks!

  • #27 Miguel Grinberg said

    @fred: Yes, you are missing the most obvious and straightforward answer. Each process has its own independent database object. The same goes for the app object that represents the Flask application instance and everything else. There is no sharing between server processes, each is completely independent from the others.

Leave a Comment