# Saleor + PostgreSQL + Redis + Celery

> GraphQL-first e-commerce platform with async task processing.

- Category: E-Commerce & Business
- Difficulty: advanced
- Components: saleor-api, saleor-dashboard, postgresql, redis, celery
- Tags: saleor, graphql, ecommerce, celery, async
- Source: https://docker.recipes/ecommerce/saleor-complete

## Overview

Saleor is a modern GraphQL-first e-commerce platform built with Django and designed for headless commerce implementations. Originally developed by Mirumee Software, Saleor provides a robust API-driven foundation for building custom storefronts while handling complex e-commerce operations like inventory management, payment processing, and multi-channel sales. The platform emphasizes developer experience with comprehensive GraphQL APIs and webhook support for real-time integrations. This stack combines Saleor's API backend with PostgreSQL for transactional data storage, Redis for caching and session management, and Celery for asynchronous task processing. PostgreSQL handles complex e-commerce queries involving products, orders, and customer data with ACID compliance, while Redis provides fast access to frequently accessed data like product catalogs and shopping cart sessions. Celery workers process time-intensive operations like image resizing, email notifications, and inventory synchronization without blocking the main application. Enterprise development teams, growing e-commerce businesses, and agencies building custom commerce solutions will find this stack particularly valuable. The GraphQL-first approach enables frontend teams to work independently while the async processing capabilities ensure the platform can handle high-volume operations. The separation of concerns between the API, dashboard, and background workers creates a scalable architecture suitable for both rapid prototyping and production deployments.

## Features

- GraphQL-first API with comprehensive schema for products, orders, customers, and inventory management
- Headless architecture enabling custom frontend implementations across web, mobile, and IoT platforms
- Multi-tenant capabilities supporting multiple storefronts and sales channels from single backend
- Celery-powered async processing for image optimization, email campaigns, and third-party integrations
- Advanced product catalog with variants, attributes, categories, and digital product support
- Built-in payment gateway integrations with webhook-driven order fulfillment workflows
- PostgreSQL-backed inventory tracking with real-time stock level management across warehouses
- Redis-cached product searches and recommendations for sub-second response times

## Use cases

- Building custom B2B e-commerce portals with role-based pricing and bulk ordering capabilities
- Creating headless storefronts for fashion brands with complex product variants and seasonal catalogs
- Developing marketplace platforms connecting multiple vendors with centralized order management
- Implementing omnichannel retail systems integrating online stores with POS and inventory systems
- Building subscription commerce platforms with recurring billing and automated fulfillment
- Creating international e-commerce sites with multi-currency support and localized product catalogs
- Developing mobile-first commerce apps using GraphQL APIs for optimal data fetching

## Prerequisites

- Docker Engine 20.10+ and Docker Compose V2 for container orchestration
- Minimum 4GB RAM (8GB recommended) due to Saleor API, Celery workers, and PostgreSQL memory requirements
- Available ports 8000 (API), 9000 (Dashboard), and 5432/6379 for database connections
- Basic understanding of GraphQL schema and query structure for API interactions
- Familiarity with Django admin interface for initial store configuration and user management
- SSL certificate and domain configuration for production deployments with payment processing

## docker-compose.yml

```yaml
services:
  api:
    image: ghcr.io/saleor/saleor:latest
    environment:
      - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/saleor
      - REDIS_URL=redis://redis:6379/0
      - CELERY_BROKER_URL=redis://redis:6379/1
      - SECRET_KEY=${SECRET_KEY}
      - ALLOWED_HOSTS=localhost,api
      - DEBUG=False
      - DEFAULT_COUNTRY=US
      - DEFAULT_CURRENCY=USD
    ports:
      - "8000:8000"
    depends_on:
      - postgres
      - redis
    networks:
      - saleor-network
    restart: unless-stopped

  dashboard:
    image: ghcr.io/saleor/saleor-dashboard:latest
    environment:
      - API_URI=http://localhost:8000/graphql/
    ports:
      - "9000:80"
    depends_on:
      - api
    networks:
      - saleor-network
    restart: unless-stopped

  postgres:
    image: postgres:15
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=saleor
    volumes:
      - postgres-data:/var/lib/postgresql/data
    networks:
      - saleor-network
    restart: unless-stopped

  redis:
    image: redis:alpine
    volumes:
      - redis-data:/data
    networks:
      - saleor-network
    restart: unless-stopped

  celery:
    image: ghcr.io/saleor/saleor:latest
    command: celery -A saleor worker --loglevel=info
    environment:
      - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/saleor
      - REDIS_URL=redis://redis:6379/0
      - CELERY_BROKER_URL=redis://redis:6379/1
      - SECRET_KEY=${SECRET_KEY}
    depends_on:
      - postgres
      - redis
    networks:
      - saleor-network
    restart: unless-stopped

  celery-beat:
    image: ghcr.io/saleor/saleor:latest
    command: celery -A saleor beat --loglevel=info
    environment:
      - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/saleor
      - REDIS_URL=redis://redis:6379/0
      - CELERY_BROKER_URL=redis://redis:6379/1
      - SECRET_KEY=${SECRET_KEY}
    depends_on:
      - postgres
      - redis
    networks:
      - saleor-network
    restart: unless-stopped

volumes:
  postgres-data:
  redis-data:

networks:
  saleor-network:
    driver: bridge
```

## .env

```bash
# Saleor
POSTGRES_USER=saleor
POSTGRES_PASSWORD=secure_postgres_password
SECRET_KEY=your-very-long-secret-key-here

# Generate secret: python -c "import secrets; print(secrets.token_urlsafe(50))"
```

## Usage notes

- API at http://localhost:8000/graphql/
- Dashboard at http://localhost:9000
- Create superuser: docker exec -it api python manage.py createsuperuser
- Celery for async tasks
- GraphQL Playground available

## Troubleshooting

- Celery workers not processing tasks: Check Redis connectivity and ensure CELERY_BROKER_URL uses different database than main Redis cache
- GraphQL mutations failing with authentication errors: Verify SECRET_KEY environment variable matches across all Saleor containers
- Dashboard showing API connection errors: Confirm API_URI points to accessible GraphQL endpoint and API container is running
- PostgreSQL connection timeouts during high load: Increase PostgreSQL max_connections and configure connection pooling in Saleor settings
- Product images not displaying: Check Celery worker logs for image processing errors and verify file upload permissions
- Slow product catalog queries: Enable PostgreSQL query logging and add database indexes for frequently searched product attributes

