Skip to main content

On This Page

Self-Hosting InstantDB: A Real-Time Open-Source Firebase Alternative on Ubuntu 24.04

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

Deploying Instant Open-Source Firebase Alternative on Ubuntu 24.04

Instant (InstantDB) is an open-source, real-time backend platform designed as a self-hosted alternative to Firebase. It leverages a PostgreSQL store to provide relational queries, authentication, and live synchronization.

Why This Matters

Many developers rely on proprietary BaaS (Backend-as-a-Service) models that introduce vendor lock-in and unpredictable scaling costs. By moving to a self-hosted architecture using Docker and Traefik, engineers gain full control over their data residency and infrastructure while maintaining the real-time capabilities typically reserved for managed services.

Key Insights

  • Real-time sync is achieved via a PostgreSQL store utilizing logical replication (wal_level=logical).
  • Automatic SSL/TLS termination is handled by Traefik v3.6 using Let’s Encrypt ACME HTTP challenges.
  • Database performance is optimized through the pg_hint_plan library and specific random_page_cost settings (1.1).

Working Examples

Initial directory setup and repository cloning.

mkdir ~/instant
cd ~/instant
git clone https://github.com/instantdb/instant.git app
cd app/server
mv docker-compose.yml docker-compose.yml.bak

Environment configuration file.

TZ=UTC
DOMAIN=instant.example.com
EMAIL=[email protected]
POSTGRES_USER=instant
POSTGRES_PASSWORD=YOUR_DATABASE_PASSWORD
POSTGRES_DB=instant

Docker Compose manifest for deploying Traefik, PostgreSQL 16, and the Instant server.

services:
  traefik:
    image: traefik:v3.6
    container_name: traefik
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--entrypoints.web.http.redirections.entrypoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--certificatesresolvers.letsencrypt import acme"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./letsencrypt:/letsencrypt"

  postgres:
    image: ghcr.io/instantdb/postgresql:postgresql-16-pg-hint_plan
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    command: ["postgres", "//etc config flags"]">  # Note: Full command list includes wal_level=logical and shared_preload_libraries=pg_hint_plan					 
present in original context.
docker compose up -d --build

Practical Applications

  •  Live Sync Applications: Using client SDKs wired against the Instant domain for real time data updates; Pitfall ignoring volume backups for ‘postgresstata’, leading to total data loss during container migration.
  •  Secure API Access: Implementing HTTPS via Traefik labels to secure backend traffic; Pitfall failing to configure DNS before deployment, resulting in Let’s Encrypt certificate issuance failure.

References:

Continue reading

Next article

Self Hosting Immich: Deploying an Open Source Photo Management Stack on Ubuntu 24.04

Related Content