How to make Python code production-ready?


What is production-ready Python code?

My favourite quote from "Release It! Design and Deploy Production-ready Software" book by Michael T. Nygard:

You’ve worked hard on your project. It looks like all the features are actually complete, and most even have tests. You can breathe a sigh of relief. You’re done.

Or are you?

How do we actually find out that our feature is ready for production. How do we check if our code is ready to be deployed into production environment.

Ideally the only difference between production and non-production environment would be some existing data in database and a log level would not be debug.

In reality, the only difference between production and non-production is that there is always a customer using our app in production. Customer usually does not know all developed features, all working workflows.

We can create as many tests as possible, cover all possible cases, read all possible books and watch all usefull talks.

But we have to accept that at some point something will go wrong in production, and we need to make sure that customer will not get upset, and the issue/issues will be fixed. In order to do that, as developers, we need to make sure that we will be able to find the issue and we will have enough information what went wrong.

How to write production-ready code

Couple of suggestions what to check before going live:

  • make sure that you handle axceptions and return a propper error to customer (500 is not a propper error)
  • make sure that you have enough logs
  • make sure that you have enough monitoring for logs and metrics
  • make sure that you are making backups of all databased frequently and you can actually restore information from them
  • secure your docker images, make sure that you are downloading from official sources

Used sources and books to read

  1. "Release It! Design and Deploy Production-ready Software" book by Michael T. Nygard:
  2. Photo by Sticker Mule on Unsplash