# Appwrite Backend as a Service

> Self-hosted Firebase alternative with authentication, databases, storage, and functions.

- Category: Full Web Stacks
- Difficulty: intermediate
- Components: appwrite, mariadb, redis, influxdb, telegraf
- Tags: appwrite, baas, firebase-alternative, backend, serverless
- Source: https://docker.recipes/full-stacks/appwrite-backend

## Overview

Appwrite is an open-source Backend-as-a-Service platform that provides developers with a comprehensive set of APIs and tools to build web, mobile, and Flutter applications. Originally created as a self-hosted alternative to Firebase, Appwrite offers authentication, real-time databases, file storage, cloud functions, and webhooks through a unified REST API and dashboard interface. The platform emerged from the need for developers to have full control over their backend infrastructure while maintaining the convenience of managed services.

This stack combines Appwrite with a robust data layer consisting of MariaDB for primary application data storage, Redis for high-performance caching and session management, and InfluxDB for time-series analytics and monitoring data. Telegraf acts as the metrics collection agent, gathering system and application performance data and feeding it into InfluxDB for analysis. This configuration creates a production-grade backend infrastructure that can handle authentication, data persistence, real-time features, and comprehensive monitoring in a single deployment.

This configuration is ideal for startups and development teams who want the convenience of Firebase-like services but require data sovereignty, custom business logic, or cost predictability. The combination is particularly valuable for building mobile applications, SaaS platforms, or any application requiring user authentication, file uploads, real-time updates, and detailed usage analytics. Unlike managed services, this self-hosted approach eliminates vendor lock-in while providing enterprise-grade monitoring and observability through the InfluxDB and Telegraf integration.

## Features

- Multi-tenancy support with project isolation and API key management through Appwrite Console
- Real-time database subscriptions and webhooks powered by Appwrite's event system
- OAuth integration with 30+ providers including Google, GitHub, Facebook, and custom SAML
- Built-in file storage with image transformation, virus scanning, and CDN capabilities
- Cloud Functions runtime supporting Node.js, Python, PHP, Ruby, and custom Docker containers
- MariaDB Galera Cluster readiness for high-availability database deployments
- Redis-powered session management with automatic failover and clustering support
- Time-series analytics collection via Telegraf monitoring Appwrite API usage and performance metrics

## Use cases

- Mobile app backends requiring user authentication, push notifications, and offline data sync
- SaaS applications needing multi-tenant user management with role-based access control
- E-commerce platforms requiring file storage for product images and order processing workflows
- IoT applications collecting sensor data through Appwrite APIs with InfluxDB time-series storage
- Social media applications needing real-time messaging, user profiles, and content moderation
- Enterprise applications requiring custom authentication flows and detailed usage analytics
- Development agencies building multiple client applications with shared backend infrastructure

## Prerequisites

- Docker host with minimum 2GB RAM (4GB recommended) to support MariaDB, Redis, and InfluxDB simultaneously
- Available ports 80 and 443 for Appwrite web console and API access
- Valid domain name and SSL certificates for production deployments with OAuth providers
- Understanding of REST APIs, JWT tokens, and basic database concepts for Appwrite configuration
- Telegraf configuration file (telegraf.conf) with InfluxDB output and desired input plugins configured

## docker-compose.yml

```yaml
services:
  appwrite:
    image: appwrite/appwrite:latest
    ports:
      - "80:80"
      - "443:443"
    environment:
      - _APP_ENV=production
      - _APP_OPENSSL_KEY_V1=${OPENSSL_KEY}
      - _APP_DOMAIN=localhost
      - _APP_DOMAIN_TARGET=localhost
      - _APP_REDIS_HOST=redis
      - _APP_REDIS_PORT=6379
      - _APP_DB_HOST=mariadb
      - _APP_DB_PORT=3306
      - _APP_DB_SCHEMA=appwrite
      - _APP_DB_USER=${MYSQL_USER}
      - _APP_DB_PASS=${MYSQL_PASSWORD}
      - _APP_INFLUXDB_HOST=influxdb
      - _APP_INFLUXDB_PORT=8086
    volumes:
      - appwrite_uploads:/storage/uploads
      - appwrite_cache:/storage/cache
      - appwrite_config:/storage/config
      - appwrite_certificates:/storage/certificates
      - appwrite_functions:/storage/functions
    depends_on:
      - mariadb
      - redis
      - influxdb
    networks:
      - appwrite-net
    restart: unless-stopped

  mariadb:
    image: mariadb:11
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: appwrite
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
      - mariadb_data:/var/lib/mysql
    networks:
      - appwrite-net
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data
    networks:
      - appwrite-net
    restart: unless-stopped

  influxdb:
    image: influxdb:2.7-alpine
    volumes:
      - influxdb_data:/var/lib/influxdb2
    networks:
      - appwrite-net
    restart: unless-stopped

  telegraf:
    image: telegraf:alpine
    volumes:
      - ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
    depends_on:
      - influxdb
    networks:
      - appwrite-net
    restart: unless-stopped

volumes:
  appwrite_uploads:
  appwrite_cache:
  appwrite_config:
  appwrite_certificates:
  appwrite_functions:
  mariadb_data:
  redis_data:
  influxdb_data:

networks:
  appwrite-net:
    driver: bridge
```

## .env

```bash
# Appwrite Configuration
OPENSSL_KEY=$(openssl rand -hex 32)

# MariaDB
MYSQL_ROOT_PASSWORD=secure_root_password
MYSQL_USER=appwrite
MYSQL_PASSWORD=secure_mysql_password
```

## Usage notes

- Appwrite Console at http://localhost
- Create account on first visit
- SDKs available for all platforms
- Built-in OAuth, database, storage, and functions

## Troubleshooting

- Appwrite Console shows 'Service Unavailable': Check MariaDB container health and ensure database schema initialization completed successfully
- OAuth authentication fails with redirect URI mismatch: Update _APP_DOMAIN and _APP_DOMAIN_TARGET environment variables to match your actual domain
- File uploads return 500 errors: Verify appwrite_uploads volume permissions and available disk space for large file storage
- InfluxDB connection timeouts in Appwrite logs: Ensure InfluxDB container is fully initialized and create required buckets and tokens
- Redis connection refused errors: Check Redis container status and verify network connectivity between Appwrite and Redis containers
- Telegraf not collecting metrics: Validate telegraf.conf file syntax and ensure proper InfluxDB authentication credentials are configured

