Deployment Architecture: Zero-Downtime Production System

This article explains how we deploy and run the website with automatic restarts and zero downtime.

The Problem: Manual Deployment is Risky

Traditional deployment requires:

  • Manual server restart: Causes downtime

  • Service monitoring: Someone must watch for crashes

  • Code updates: Requires SSH access and manual steps

  • Rollback: Manual process if something breaks

This doesn't scale and causes downtime during updates.

The Solution: Automated Deployment with Systemd

We use systemd to manage (see Infrastructure Overview) the application:

  • Auto-restart: Automatically restarts on crash or code change

  • Zero downtime: Graceful worker restarts

  • Logging: Centralized log management

  • Process management: Handles worker lifecycle

Server Infrastructure

Production Server

The production server hosts the public-facing website:

  • Purpose: Public website serving product catalog and e-commerce

  • Module: "web" only

  • Environment: Production (Gunicorn + systemd)

  • Access: Public (no login required)

Application Server

Gunicorn

Gunicorn is the production web server:

  • Multi-worker: Multiple worker processes

Systemd Integration

Systemd manages Gunicorn:

  • Auto-start: On server boot

  • Auto-restart: On crash or code change

  • Logging: Systemd journal integration

  • Process management: Worker lifecycle

Configuration

Environment Config

Configuration is environment-specific:

  • Config files: Environment-specific settings

  • JSON format: Key-value pairs

  • Environment variables: Secrets and API keys

  • Module enablement: Controls which features load

Static Assets

Static assets are served from S3 with CloudFront CDN:

  • S3 bucket: Object storage for static files

  • CloudFront: CDN for global asset delivery

  • Caching: Long TTL for static content

  • Versioning: Cache-busting with version numbers

Deployment Process

Code Deployment

Code is deployed via Git with systemd managing the application service:

  1. Commit and push: Changes pushed to Git repository
  2. Pull on server: Code pulled to production server
  3. Systemd restart: Service restarts automatically on crash

Configuration Deployment

Configuration is managed separately from code:

  1. Config files: JSON configuration files in Git
  2. Environment variables: Secrets loaded from environment
  3. Module enablement: Controls which features load

Monitoring

Health Checks

Health endpoints monitor server status:

  • Health endpoint: Basic health check

  • Database check: Database connectivity

  • Cache check: Cache connectivity

Logging

Logs are stored in multiple locations:

  • Gunicorn Error logs: Application errors

  • Gunicorn Access logs: HTTP requests

  • Service logs: Systemd journal

Summary

Deployment architecture provides:

  • Gunicorn: Production WSGI server

  • Systemd: Auto-restart and process management

  • Git deployment: Code and config management

  • S3 + CloudFront: Static asset delivery

  • Health monitoring: Health check endpoints

  • Logging: Error and access logs