Skip to main content

Zero-Downtime Deployments

Every deployment involves replacing the running version of your application with a new one. This guide covers how Appliku handles deployments and what you can do to minimize downtime.

How Appliku Handles Deployments

Server Mode

In server mode, Appliku deploys by stopping the old container and starting the new one. There is a brief period of downtime while the new container starts up and becomes ready to serve traffic.

Cluster Mode (Docker Swarm)

In cluster mode, Appliku uses Docker Swarm's rolling update mechanism. Swarm starts new containers before stopping old ones, routing traffic to healthy instances throughout the process. This provides true zero-downtime deployments.

tip

If zero-downtime deployments are critical for your application, consider using cluster mode with Docker Swarm. It handles rolling updates automatically.

Tips for Reducing Downtime

Even in server mode, you can significantly reduce deployment downtime:

1. Optimize Startup Time

The faster your application starts, the shorter the downtime window. Common strategies:

  • Minimize the work done at application startup
  • Use lightweight base images
  • Pre-compile assets during the build phase, not at startup
  • Avoid running database queries during startup

2. Use a Release Command

Run database migrations and other pre-deployment tasks using a release command. This runs before the new containers start serving traffic:

python manage.py migrate --noinput

Configure the release command in your application's Build Settings. This ensures migrations complete before the container swap happens.

3. Handle Graceful Shutdown

Make sure your application handles SIGTERM signals properly. When Appliku stops the old container, it sends SIGTERM first, giving your application time to finish in-flight requests before SIGKILL.

For Gunicorn, set a graceful timeout:

gunicorn myproject.wsgi --graceful-timeout 30

4. Keep Migrations Backward-Compatible

Write database migrations that work with both the old and new versions of your code. This is especially important for cluster mode where old and new containers run simultaneously:

  • Add new columns as nullable or with defaults
  • Deploy the column addition first, then the code that uses it
  • Remove old columns only after the code no longer references them
note

Backward-compatible migrations are a best practice regardless of your deployment strategy. They prevent errors if a deployment needs to be rolled back.

5. Use Health Checks

Configure health check endpoints so Appliku can verify your application is ready to serve traffic before routing requests to it.

A simple health check endpoint in Django:

# urls.py
from django.http import JsonResponse

def health_check(request):
return JsonResponse({"status": "ok"})

urlpatterns = [
# ...
path("health/", health_check),
]