SimpleNS LogoDocs

Self-Hosting Guide

Deploy SimpleNS to production with flexible infrastructure hosting options.


Initial installation and setup

Refer the Getting Started Guide guide for initial installation and setup.


Overview

SimpleNS uses a split architecture that separates application services from infrastructure services, allowing flexible deployment across single or distributed systems.

Compose FilePurposeWhen to Use
docker-compose.yamlApplication services (API, processors, dashboard)Always required
docker-compose.infra.yamlInfrastructure (MongoDB, Kafka, Redis, Loki, Grafana)Only if self-hosting infrastructure

SimpleNS can also be hosted easily on cloud providers using prebuilt Terraform templates: SimpleNS Terraform Templates.


Customizing Infrastructure

The @simplens/onboard cli tool lets you to choose which infrastructure services to deploy with Docker. This gives you flexibility to use managed cloud services for some components while self-hosting others.

Selective Infrastructure Services

During onboarding, you can select which services to deploy:

ServiceDescriptionDefault
MongoDBPrimary databaseYes
KafkaMessage queue for notificationsYes
Kafka UIWeb dashboard for Kafka monitoringNo
RedisCaching and delay queueYes
LokiLog aggregationNo
GrafanaObservability dashboardNo
NginxReverse proxy server needed when BASE_PATH is configuredNo

Using Managed/External Services

For any service you choose not to deploy via Docker, you'll be prompted to provide connection URLs:

Environment VariableDescriptionExample
MONGO_URIMongoDB connection stringmongodb+srv://user:pass@cluster.mongodb.net/simplens
BROKERSKafka broker addresseskafka-broker.cloud-provider.com:9092
REDIS_URLRedis connection URLredis://user:pass@redis.cloud-provider.com:6379
LOKI_URLLoki endpoint (optional)http://loki.cloud-provider.com:3100

Use managed services like MongoDB Atlas, Confluent Cloud, or Redis Cloud for production deployments to reduce operational overhead.


Plugin & Provider Management

Plugins, encrypted provider credentials, and channel routings are stored in MongoDB and hot-reloaded across all services via Redis Pub/Sub.

  • Install, upgrade, or uninstall plugins in Dashboard → Plugins (/plugins) (or via /api/plugins/*).
  • Configure provider instances with encrypted credentials, priority, and token-bucket rate limits (maxTokens, refillRate, refillInterval).
  • Set default and fallback providers per channel in Channel Routing.
  • If upgrading from a legacy simplens.config.yaml setup, YamlMigrator automatically imports it on startup when MongoDB is empty.

Scaling with Kafka Partitions

SimpleNS uses Kafka topic partitions to enable horizontal scaling of consumers:

  • Per-Channel Partitions (Dynamic): Configured in Dashboard → Channel Routing (default: 6 partitions). SimpleNS creates and expands channel topic partitions dynamically (expandTopicPartitions).
  • System Topic Partitions (.env): DELAYED_PARTITION (default 1) and NOTIFICATION_STATUS_PARTITION (default 1) are set in .env.

The recovery service does not depend on Kafka partitions and is stateless—it scales horizontally using atomic MongoDB claiming (recovery_claimed_by).

Scaling Workers & Processors

# Deploy multiple instances (compose files live in docker-compose/)
docker compose -f docker-compose/docker-compose.master.yaml up -d --scale notification_processor=6
docker compose -f docker-compose/docker-compose.master.yaml up -d --scale worker=3
docker compose -f docker-compose/docker-compose.master.yaml up -d --scale delayed_processor=2

Kafka partition counts can be increased dynamically, but cannot be decreased after topics are created.

For detailed configuration of all environment variables, see the Configuration Reference.


Deployment Configurations

SimpleNS is designed to scale from a single Raspberry Pi to a multi-node Kubernetes cluster. How you deploy depends on your expected volume and whether you want to manage stateful databases yourself.

Hardware Requirements

EnvironmentMinimum ResourcesRecommended Resources
Development (Devcontainer)4 CPU Cores, 6GB RAM8 CPU Cores, 8GB RAM
Production (All-in-one)2 CPU Cores, 2GB RAM4 CPU Cores, 4GB RAM
Production (App Only)1 CPU Core, 1GB RAM2 CPU Cores, 2GB RAM + Managed DBs

Kafka and MongoDB are the most resource-intensive components when self-hosting the full stack.

Choose Your Setup

Best for: Side-projects, staging environments, and low-volume production (<100k events/day).

This setup runs both the Application and Infrastructure locally on a single machine.

.env
# Ensure MONGO, KAFKA, and REDIS point to your local docker networks
MONGO_URI=mongodb://host.docker.internal:27017/simplens?replicaSet=rs0
BROKERS=host.docker.internal:9092
REDIS_URL=redis://host.docker.internal:6379
LOKI_URL=http://host.docker.internal:3100
# Step 1: Start Infrastructure (DBs, Queues)
docker compose -f docker-compose/docker-compose.infra.yaml up -d

# Step 2: Start Application Services
docker compose -f docker-compose/docker-compose.master.yaml up -d

Best for: Most production workloads. You run the stateless Node.js services, while handing off database maintenance to cloud providers.

.env
# MongoDB Atlas
MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/simplens?retryWrites=true

# Confluent Cloud Kafka / AWS MSK
BROKERS=kafka-broker.cloud-provider.com:9092

# Redis Cloud / AWS ElastiCache
REDIS_URL=redis://user:pass@redis.cloud-provider.com:6379
# Only start application services
docker-compose up -d

With this setup, you completely ignore docker-compose.infra.yaml.

Best for: High availability and massive throughput.

You deploy infrastructure on dedicated nodes (or managed services), and spread Application workers across multiple machines behind a load balancer.

  1. API Nodes: Scale api container horizontally behind NGINX/ALB.
  2. Processor Nodes: Deploy notification_processor on separate servers tailored to target specific channels using PROCESSOR_CHANNEL=email.
  3. Background Nodes: Run worker and delayed_processor on background compute.

Ensure you adjust your *_PARTITION environment variables before creation to support the number of parallel processor instances you plan to run.


Application Services

The docker-compose.yaml uses pre-built images from GitHub Container Registry:

ServiceImageDescription
apighcr.io/simplenotificationsystem/simplens-core:latestREST API for notification ingestion
workerghcr.io/simplenotificationsystem/simplens-core:latestBackground worker for outbox processing
notification_processorghcr.io/simplenotificationsystem/simplens-core:latestPlugin-based notification delivery
delayed_processorghcr.io/simplenotificationsystem/simplens-core:latestScheduled notification handling
recoveryghcr.io/simplenotificationsystem/simplens-core:latestDetects and rescues stuck notifications
dashboardghcr.io/simplenotificationsystem/simplens-dashboard:latestAdmin dashboard (Next.js)

All application services have thier own .plugins directory in their container (not a shared volume) for installed npm packages, while plugin state, encrypted provider credentials, and routing live in MongoDB and synced via Redis Pub/Sub.


Infrastructure Services

The docker-compose.infra.yaml provides self-hosted infrastructure:

ServiceImageDescription
mongomongo:7.0MongoDB with replica set
kafkaapache/kafka-nativeKafka with KRaft mode (no Zookeeper)
kafka-uikafbat/kafka-ui:mainKafka monitoring UI (optional)
redisredis:7-alpineRedis for caching and queues
lokigrafana/loki:2.9.0Log aggregation
grafanagrafana/grafana:10.2.0Log visualization

Port Reference

ServicePortDescription
API3000REST API for notification ingestion
Dashboard3002Admin web interface
MongoDB27017Database
Kafka9092Message broker
Kafka UI8080Kafka monitoring (optional)
Redis6379Cache and queues
Loki3100Log aggregation
Grafana3001Log visualization

Plugin & Operational Configuration

SimpleNS stores plugins, encrypted provider credentials, channel routings, storage providers, and operational settings in MongoDB, hot-reloaded across all replicas via Redis Pub/Sub.

  • Manage plugins, providers, and routing in Dashboard → Plugins (/plugins).
  • Tune worker, retry, attachment, and IP rate-limit settings live in Dashboard → Settings (/settings).
  • If upgrading from a legacy simplens.config.yaml setup, YamlMigrator automatically imports it on startup when MongoDB is empty.

Security Considerations

Before Deploying to Production

Complete these security checks before going live.

  1. ✅ Set a strong JWT_SECRET (minimum 32 characters) and ADMIN_ALERT_ENCRYPTION_KEY in .env
  2. ✅ Complete /setup in the Dashboard immediately on first launch to create your admin account
  3. ✅ Configure CORS_ALLOWED_ORIGINS explicitly (SimpleNS is default-deny for CORS)
  4. ✅ If behind a reverse proxy (Nginx/Traefik), set TRUST_PROXY to a hop count (e.g., 1) or trusted IP/CIDR—never true
  5. ✅ Enable NODE_ENV=production so SSRF protection (safe-outbound-url / safe-http-client) blocks private/internal webhook_url and alert targets
  6. ✅ Set up SSL/TLS for the API and Dashboard, and configure MongoDB authentication + backups
  7. ✅ Use Kubernetes probeServer liveness/readiness probes (and /api/health*) in orchestrated deployments

Troubleshooting

Services can't connect to infrastructure

  • INFRA_HOST / URLs: Ensure MONGO_URI, REDIS_URL, and BROKERS point to reachable addresses
  • Firewall: Check ports 27017, 9092, 6379, 3100 are open
  • Network: Verify containers/machines can reach each other

MongoDB replica set issues

# Reset and reinitialize
docker compose -f docker-compose.infra.yaml down -v
docker compose -f docker-compose.infra.yaml up -d
# Wait 60 seconds for auto-initialization

Plugin or settings changes not syncing across replicas

# Verify Redis connectivity and check processor logs
docker compose logs notification_processor api

On this page