DEV Community

Jaskaran Deogan
Jaskaran Deogan

Posted on

Self-Hosted Analytics with Rybbit: A Game-Changer for Privacy-Conscious Developers

Rybbit Dashboard
As AI adoption accelerates day by day, so does the number of people creating web applications. With tools like Loveable and Vercel's V0, it's never been easier to test your ideas and build MVPs that capture the essence of your vision. However, once you transition from prototype to production and start onboarding real users, understanding their behavior becomes crucial.

You need insights into user experience, system performance, and potential errors. You need analytics that tell you everything about the traffic flowing through your website. But here's the thing – can you really trust third-party services with your precious user data?

The Analytics Dilemma: Privacy vs. Convenience

Sure, Google Analytics exists. It's free, feature-rich, and widely adopted. But as more developers embrace the "vibecoding" philosophy and rapid prototyping becomes the norm, trusting third parties with sensitive user data becomes increasingly questionable.

Enter self-sovereign analytics – the idea that you should own and control your analytics data completely. This is where Rybbit absolutely shines, and honestly, I'm blown away by its open-source capabilities.

Realtime Analytics

Analytic Events

Why Rybbit Caught My Attention

Rybbit isn't just another analytics tool – it's a complete, self-hosted analytics platform that gives you:

  • 🔒 Complete data ownership - Your data stays on your infrastructure
  • 📊 Real-time insights - Live traffic monitoring and user behavior tracking
  • 🚀 Performance monitoring - Track errors, page load times, and system health
  • 🛡️ Privacy-first approach - No third-party data sharing or tracking
  • 💡 Enhanced Analytics on user testing - Additional tools are available to test the app’s functionality, including enhanced error analytics and user session replays.
  • 📈 Beautiful dashboards - Intuitive interface that rivals commercial solutions
  • 🔧 Full customization - Modify and extend as needed since it's open source

Rybbit Github

Deploying Rybbit on Coolify: The Complete Guide

If you want to simply run Rybbit on your VPS, the official documentation has you covered. But if you're like me and want to deploy it on Coolify with proper health checks and production-ready configuration, this guide is for you.

The Architecture

Rybbit is a multi-service application that requires several components working in harmony:

  • Frontend: Next.js client (port 3002)
  • Backend: Fastify API server (port 3001)
  • Database: PostgreSQL for user data and configuration
  • Analytics DB: ClickHouse for high-performance analytics storage
  • Cache: Redis for session management and caching
  • Reverse Proxy: Handled automatically by Coolify

Step 1: Setting Up the Docker Compose Configuration

The magic happens in the coolify-compose.yml file. Here's the production-ready configuration with health checks:

services:
  clickhouse:
    image: clickhouse/clickhouse-server:25.4.2
    volumes:
      - clickhouse-data:/var/lib/clickhouse
    environment:
      - CLICKHOUSE_DB=${CLICKHOUSE_DB:-analytics}
      - CLICKHOUSE_USER=${CLICKHOUSE_USER:-default}
      - CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-frog}
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    restart: unless-stopped

  postgres:
    image: postgres:17.4
    environment:
      - POSTGRES_USER=${POSTGRES_USER:-frog}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-frog}
      - POSTGRES_DB=${POSTGRES_DB:-analytics}
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    volumes:
      - redis-data:/data
    restart: unless-stopped
    command: ["redis-server", "--requirepass", "${REDIS_PASSWORD:-changeme}", "--appendonly", "yes"]
    healthcheck:
      test: ["CMD", "redis-cli", "--raw", "incr", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  backend:
    build:
      context: .
      dockerfile: ./server/Dockerfile
    environment:
      - NODE_ENV=production
      - CLICKHOUSE_HOST=http://clickhouse:8123
      - POSTGRES_HOST=postgres
      - REDIS_HOST=redis
      - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}
      - BASE_URL=${BASE_URL}
      # ... other environment variables
    depends_on:
      clickhouse:
        condition: service_healthy
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: unless-stopped

  client:
    build:
      context: .
      dockerfile: ./client/Dockerfile
      args:
        NEXT_PUBLIC_BACKEND_URL: ${NEXT_PUBLIC_BACKEND_URL}
    environment:
      - NODE_ENV=production
      - NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL}
    depends_on:
      backend:
        condition: service_healthy
    restart: unless-stopped

volumes:
  clickhouse-data:
  postgres-data:
  redis-data:
Enter fullscreen mode Exit fullscreen mode

Step 2: Environment Variables Configuration

Set these in your Coolify application:

# Required
DOMAIN_NAME=analytics.yourdomain.com
BASE_URL=https://analytics.yourdomain.com
BETTER_AUTH_SECRET=your-super-secure-secret-here
NEXT_PUBLIC_BACKEND_URL=https://api.analytics.yourdomain.com

# Database credentials
POSTGRES_USER=frog
POSTGRES_PASSWORD=your-secure-postgres-password
POSTGRES_DB=analytics
CLICKHOUSE_DB=analytics
CLICKHOUSE_PASSWORD=your-secure-clickhouse-password
REDIS_PASSWORD=your-secure-redis-password

# Optional
DISABLE_SIGNUP=false
DISABLE_TELEMETRY=true
Enter fullscreen mode Exit fullscreen mode

Step 3: Deploy in Coolify

  1. Create a new Application in Coolify
  2. Choose Docker Compose as the deployment method
  3. Connect your Git repository
  4. Set the compose file to coolify-compose.yml
  5. Configure all environment variables
  6. Deploy!

Common Issues and Solutions

1. API Proxy Configuration

The most common issue: Frontend can't communicate with the backend.

Solution: Ensure your Next.js configuration properly handles API proxying. The frontend should proxy /api/* calls to the backend service. Make sure NEXT_PUBLIC_BACKEND_URL points to your domain, not the internal backend service.

// client/next.config.ts
const nextConfig = {
  async rewrites() {
    if (process.env.NODE_ENV === 'development') {
      return [
        {
          source: '/api/:path*',
          destination: 'http://backend:3001/api/:path*'
        }
      ]
    }
    return []
  }
}
Enter fullscreen mode Exit fullscreen mode

2. Health Check Failures

Issue: Services failing health checks and restarting continuously.

Solution: Verify that:

  • Database credentials match across all services
  • Network connectivity between containers is working
  • Health check endpoints are responding correctly
# Test backend health
curl -f http://localhost:3001/api/health

# Test database connectivity
docker exec -it postgres-container pg_isready -U frog -d analytics
Enter fullscreen mode Exit fullscreen mode

3. Build Context Issues

Issue: Docker builds failing due to incorrect context or Dockerfile paths.

Solution: Ensure your build context is set to the repository root, and Dockerfile paths are relative to that context:

backend:
  build:
    context: .  # Repository root
    dockerfile: ./server/Dockerfile  # Relative to context
Enter fullscreen mode Exit fullscreen mode

The Benefits of This Setup

🔄 Graceful Service Dependencies

Services start in the correct order with health condition checks:

  1. Databases (PostgreSQL, ClickHouse, Redis) initialize first
  2. Backend waits for all databases to be healthy
  3. Frontend waits for backend to be healthy

🏥 Comprehensive Health Monitoring

Every service includes health checks that Coolify can monitor and act upon automatically.

🚀 Production-Ready Optimizations

  • Standalone Next.js builds for containerized deployment
  • Conditional compression loading (zstd with gzip fallback)
  • Proper restart policies and resource management

Why This Matters

In an era where data privacy is paramount and vendor lock-in is a real concern, self-hosted analytics solutions like Rybbit represent the future. You get:

  • Complete control over your analytics data
  • No monthly fees or usage limits
  • Customization freedom to add features you need
  • Compliance confidence knowing where your data lives
  • Performance benefits from local data processing

Final Thoughts

Rybbit on Coolify is a winning combination for developers who value privacy, performance, and control. The setup might seem complex initially, but the payoff is enormous – you get enterprise-grade analytics without the enterprise price tag or privacy concerns.

The open-source nature means you can contribute back to the community, customize it for your specific needs, and never worry about a service shutting down or changing their pricing model.

Have you tried self-hosted analytics? What's been your experience with tools like Rybbit? I'd love to hear your thoughts in the comments!


Resources:

Happy analytics tracking! 📊

Top comments (0)