Version: v0.9.0


Kalgan is ready for production deployment. However there are some advices which must be taken into account.

Cache configuration files

Before going to production you must set environment.is_prod to true. This will prevent your app from refreshing all your configuration parameters (config, i18n, routes and templates) with every request.

We can even set this parameter to true in our local machine to see how loading speed is improved. While developing ( environment.is_prod: false ), the bigger our app is, the more config files and templates it will have and therefore and slower performance will be achieved. However this issue won't happen when this parameter is set to true.

Notice that setting environment.is_prod to true will disable parameter environment.refresh_config_timeout.

Reverse Proxy

We have already seen that Kalgan runs over a built-in multithreaded web server (see Built-in Web Server in the docs). This server does the job but it's not ready to handle some features which are a "must" when running in a production environment. That is to say (among others):

  • SSL certificates (HTTPS connections)
  • Caching and compression for static content
  • Load balancing

Here is when reverse proxy servers come to the rescue.

A reverse proxy server retrieves resources on behalf of a client from one or more servers. When going to production, our app should definitely be running behind a reverse proxy server. There are multiple choices out there, probably one of the best options is NGINX Reverse Proxy.

Find in the below flowchart a representation of the new architecture for our app:

Notice that even though the client is sending HTTPS requests, the built-in server will always handle HTTP requests.

Integrating our app with a reverse proxy server is not a very complex task, however it is out the scope of these docs.

Static Files

Kalgan built-in server can process static files but perfomance will always be much better if we leave this task to the proxy server.

We've just seen that when working with a reverse proxy server Kalgan stops processing static file requests. At this point we must remember to remove settings parameter static.folders to prevent Kalgan of checking whether a request is for an asset or not.

There's another feature we must enable when going to production: versioning our static files. This is done through the settings parameter static.version. This means that all url assets rendered with |asset, the built-in filter for Tera, will have the version value appended at the end of the route. For example:

  path: /static
  version: v001
<script src="{{ "/vendor/jquery/dist/jquery.min.js"|asset }}"></script>
This will render as follows:
<script src="/static/vendor/jquery/dist/jquery.min.js?v001"></script>

Notice that this feature wil only be enbled when paremeter environment.is_prod is set to true.

There are some other tasks we should perform before deploying our static files in a production environment such as the concatenation and minification of these files. However these tasks are out of the scope of Kalgan framework and these docs.